/src/botan/build/include/internal/botan/internal/pcurves_id.h
Line | Count | Source |
1 | | /* |
2 | | * (C) 2024 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #ifndef BOTAN_PCURVES_ID_H_ |
8 | | #define BOTAN_PCURVES_ID_H_ |
9 | | |
10 | | #include <botan/secmem.h> |
11 | | #include <botan/types.h> |
12 | | #include <optional> |
13 | | #include <string> |
14 | | #include <string_view> |
15 | | #include <vector> |
16 | | |
17 | | namespace Botan { |
18 | | |
19 | | #if defined(BOTAN_HAS_ASN1) |
20 | | class OID; |
21 | | #endif |
22 | | |
23 | | } // namespace Botan |
24 | | |
25 | | namespace Botan::PCurve { |
26 | | |
27 | | /// Identifier for a named prime order curve |
28 | | class BOTAN_TEST_API PrimeOrderCurveId final { |
29 | | public: |
30 | | enum class Code : uint8_t { |
31 | | /// secp192r1 aka P-192 |
32 | | secp192r1, |
33 | | /// secp224r1 aka P-224 |
34 | | secp224r1, |
35 | | /// secp256r1 aka P-256 |
36 | | secp256r1, |
37 | | /// secp384r1 aka P-384 |
38 | | secp384r1, |
39 | | /// secp521r1 aka P-521 |
40 | | secp521r1, |
41 | | /// secp256k1 |
42 | | secp256k1, |
43 | | /// brainpool256r1 |
44 | | brainpool256r1, |
45 | | brainpool384r1, |
46 | | brainpool512r1, |
47 | | frp256v1, |
48 | | sm2p256v1, |
49 | | numsp512d1, |
50 | | }; |
51 | | |
52 | | using enum Code; |
53 | | |
54 | 387 | Code code() const { return m_code; } |
55 | | |
56 | | /// Return a list of all of the defined PrimeOrderCurveId |
57 | | /// |
58 | | /// Note this list always includes all curves, even if some were |
59 | | /// disabled at build time. |
60 | | static std::vector<PrimeOrderCurveId> all(); |
61 | | |
62 | | /// Convert the ID to it's commonly used name (inverse of from_string) |
63 | | std::string to_string() const; |
64 | | |
65 | 387 | PrimeOrderCurveId(Code id) : m_code(id) {} |
66 | | |
67 | | /// Map a string to a curve identifier |
68 | | static std::optional<PrimeOrderCurveId> from_string(std::string_view name); |
69 | | |
70 | | #if defined(BOTAN_HAS_ASN1) |
71 | | /// Map an OID to a curve identifier |
72 | | /// |
73 | | /// Uses the internal OID table |
74 | | static std::optional<PrimeOrderCurveId> from_oid(const OID& oid); |
75 | | #endif |
76 | | |
77 | | private: |
78 | | const Code m_code; |
79 | | }; |
80 | | |
81 | | } // namespace Botan::PCurve |
82 | | |
83 | | #endif |