CCF
Loading...
Searching...
No Matches
include
ccf
crypto
curve.h
Go to the documentation of this file.
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
// Licensed under the Apache 2.0 License.
3
#pragma once
4
5
#include "
ccf/crypto/md_type.h
"
6
#include "
ccf/ds/enum_formatter.h
"
7
#include "
ccf/ds/json.h
"
8
9
#define FMT_HEADER_ONLY
10
#include <fmt/format.h>
11
#include <stdexcept>
12
#include <string>
13
14
namespace
ccf::crypto
15
{
16
// SNIPPET_START: supported_curves
17
enum class
CurveID
18
{
20
NONE
= 0,
22
SECP384R1
,
24
SECP256R1
,
26
SECP256K1
,
28
CURVE25519
,
29
X25519
30
};
31
32
DECLARE_JSON_ENUM
(
33
CurveID
,
34
{{
CurveID::NONE
,
"None"
},
35
{
CurveID::SECP384R1
,
"Secp384R1"
},
36
{
CurveID::SECP256R1
,
"Secp256R1"
},
37
{
CurveID::SECP256K1
,
"Secp256K1"
},
38
{
CurveID::CURVE25519
,
"Curve25519"
},
39
{
CurveID::X25519
,
"X25519"
}});
40
41
static
constexpr
CurveID
service_identity_curve_choice =
CurveID::SECP384R1
;
42
// SNIPPET_END: supported_curves
43
44
// Get message digest algorithm to use for given elliptic curve
45
inline
MDType
get_md_for_ec
(
CurveID
ec)
46
{
47
switch
(ec)
48
{
49
case
CurveID::SECP384R1
:
50
return
MDType::SHA384
;
51
case
CurveID::SECP256R1
:
52
return
MDType::SHA256
;
53
case
CurveID::SECP256K1
:
54
return
MDType::SHA256
;
55
default
:
56
{
57
throw
std::logic_error(fmt::format(
"Unhandled CurveID: {}"
, ec));
58
}
59
}
60
}
61
}
enum_formatter.h
json.h
DECLARE_JSON_ENUM
#define DECLARE_JSON_ENUM(TYPE,...)
Definition
json.h:835
md_type.h
ccf::crypto
Definition
base64.h:9
ccf::crypto::get_md_for_ec
MDType get_md_for_ec(CurveID ec)
Definition
curve.h:45
ccf::crypto::MDType
MDType
Definition
md_type.h:10
ccf::crypto::MDType::SHA256
@ SHA256
ccf::crypto::MDType::SHA384
@ SHA384
ccf::crypto::CurveID
CurveID
Definition
curve.h:18
ccf::crypto::CurveID::SECP384R1
@ SECP384R1
The SECP384R1 curve.
ccf::crypto::CurveID::SECP256K1
@ SECP256K1
The SECP256K1 curve.
ccf::crypto::CurveID::CURVE25519
@ CURVE25519
The CURVE25519 curve.
ccf::crypto::CurveID::NONE
@ NONE
No curve.
ccf::crypto::CurveID::SECP256R1
@ SECP256R1
The SECP256R1 curve.
ccf::crypto::CurveID::X25519
@ X25519
Generated by
1.9.8