Botan 3.6.1
Crypto and TLS for C&
pcurves.cpp
Go to the documentation of this file.
1/*
2* (C) 2024 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/pcurves.h>
8
9#include <botan/internal/pcurves_instance.h>
10
11#if defined(BOTAN_HAS_ASN1)
12 #include <botan/asn1_obj.h>
13#endif
14
15namespace Botan::PCurve {
16
17#if !defined(BOTAN_HAS_PCURVES_SECP192R1)
18//static
19std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp192r1() {
20 return nullptr;
21}
22#endif
23
24#if !defined(BOTAN_HAS_PCURVES_SECP224R1)
25//static
26std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp224r1() {
27 return nullptr;
28}
29#endif
30
31#if !defined(BOTAN_HAS_PCURVES_SECP256R1)
32//static
33std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp256r1() {
34 return nullptr;
35}
36#endif
37
38#if !defined(BOTAN_HAS_PCURVES_SECP384R1)
39//static
40std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp384r1() {
41 return nullptr;
42}
43#endif
44
45#if !defined(BOTAN_HAS_PCURVES_SECP521R1)
46//static
47std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp521r1() {
48 return nullptr;
49}
50#endif
51
52#if !defined(BOTAN_HAS_PCURVES_SECP256K1)
53//static
54std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp256k1() {
55 return nullptr;
56}
57#endif
58
59#if !defined(BOTAN_HAS_PCURVES_BRAINPOOL256R1)
60//static
61std::shared_ptr<const PrimeOrderCurve> PCurveInstance::brainpool256r1() {
62 return nullptr;
63}
64#endif
65
66#if !defined(BOTAN_HAS_PCURVES_BRAINPOOL384R1)
67//static
68std::shared_ptr<const PrimeOrderCurve> PCurveInstance::brainpool384r1() {
69 return nullptr;
70}
71#endif
72
73#if !defined(BOTAN_HAS_PCURVES_BRAINPOOL512R1)
74//static
75std::shared_ptr<const PrimeOrderCurve> PCurveInstance::brainpool512r1() {
76 return nullptr;
77}
78#endif
79
80#if !defined(BOTAN_HAS_PCURVES_FRP256V1)
81//static
82std::shared_ptr<const PrimeOrderCurve> PCurveInstance::frp256v1() {
83 return nullptr;
84}
85#endif
86
87#if !defined(BOTAN_HAS_PCURVES_SM2P256V1)
88//static
89std::shared_ptr<const PrimeOrderCurve> PCurveInstance::sm2p256v1() {
90 return nullptr;
91}
92#endif
93
94#if !defined(BOTAN_HAS_PCURVES_NUMSP512D1)
95//static
96std::shared_ptr<const PrimeOrderCurve> PCurveInstance::numsp512d1() {
97 return nullptr;
98}
99#endif
100
130
147
148std::string PrimeOrderCurveId::to_string() const {
149 switch(this->code()) {
151 return "secp192r1";
153 return "secp224r1";
155 return "secp256r1";
157 return "secp384r1";
159 return "secp521r1";
161 return "secp256k1";
163 return "brainpool256r1";
165 return "brainpool384r1";
167 return "brainpool512r1";
169 return "frp256v1";
171 return "sm2p256v1";
173 return "numsp512d1";
174 }
175
176 return "unknown";
177}
178
179//static
180std::optional<PrimeOrderCurveId> PrimeOrderCurveId::from_string(std::string_view name) {
181 if(name == "secp192r1") {
183 } else if(name == "secp224r1") {
185 } else if(name == "secp256r1") {
187 } else if(name == "secp384r1") {
189 } else if(name == "secp521r1") {
191 } else if(name == "secp256k1") {
193 } else if(name == "brainpool256r1") {
195 } else if(name == "brainpool384r1") {
197 } else if(name == "brainpool512r1") {
199 } else if(name == "frp256v1") {
201 } else if(name == "sm2p256v1") {
203 } else if(name == "numsp512d1") {
205 } else {
206 return {};
207 }
208}
209
210#if defined(BOTAN_HAS_ASN1)
211
212//static
213std::optional<PrimeOrderCurveId> PrimeOrderCurveId::from_oid(const OID& oid) {
214 const std::string name = oid.human_name_or_empty();
215 if(name.empty()) {
216 return {};
217 } else {
219 }
220}
221
222#endif
223
224} // namespace Botan::PCurve
std::string human_name_or_empty() const
Definition asn1_oid.cpp:147
static std::shared_ptr< const PrimeOrderCurve > secp521r1()
Definition pcurves.cpp:47
static std::shared_ptr< const PrimeOrderCurve > numsp512d1()
Definition pcurves.cpp:96
static std::shared_ptr< const PrimeOrderCurve > secp256k1()
Definition pcurves.cpp:54
static std::shared_ptr< const PrimeOrderCurve > secp192r1()
Definition pcurves.cpp:19
static std::shared_ptr< const PrimeOrderCurve > secp384r1()
Definition pcurves.cpp:40
static std::shared_ptr< const PrimeOrderCurve > brainpool384r1()
Definition pcurves.cpp:68
static std::shared_ptr< const PrimeOrderCurve > brainpool512r1()
Definition pcurves.cpp:75
static std::shared_ptr< const PrimeOrderCurve > secp224r1()
Definition pcurves.cpp:26
static std::shared_ptr< const PrimeOrderCurve > frp256v1()
Definition pcurves.cpp:82
static std::shared_ptr< const PrimeOrderCurve > brainpool256r1()
Definition pcurves.cpp:61
static std::shared_ptr< const PrimeOrderCurve > sm2p256v1()
Definition pcurves.cpp:89
static std::shared_ptr< const PrimeOrderCurve > secp256r1()
Definition pcurves.cpp:33
Identifier for a named prime order curve.
Definition pcurves_id.h:28
static std::vector< PrimeOrderCurveId > all()
Definition pcurves.cpp:131
static std::optional< PrimeOrderCurveId > from_string(std::string_view name)
Map a string to a curve identifier.
Definition pcurves.cpp:180
std::string to_string() const
Convert the ID to it's commonly used name (inverse of from_string)
Definition pcurves.cpp:148
static std::shared_ptr< const PrimeOrderCurve > from_id(PrimeOrderCurveId id)
Definition pcurves.cpp:101
std::string name