Botan 3.7.1
Crypto and TLS for C&
cmce.h
Go to the documentation of this file.
1/*
2 * Classic McEliece Key Generation
3 * (C) 2023 Jack Lloyd
4 * 2023,2024 Fabian Albert, Amos Treiber - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 **/
8
9#ifndef BOTAN_CMCE_H_
10#define BOTAN_CMCE_H_
11
12#include <botan/pk_keys.h>
13
14#include <botan/cmce_parameter_set.h>
15
16namespace Botan {
17
18class Classic_McEliece_PublicKeyInternal;
19class Classic_McEliece_PrivateKeyInternal;
20
21/**
22 * Classic McEliece is a Code-Based KEM. It is a round 4 candidate in NIST's PQC competition.
23 * It is endorsed by the German Federal Office for Information Security (BSI) for its conservative security
24 * assumptions and a corresponding draft for an ISO standard has been prepared. Both NIST and ISO parameter
25 * sets are implemented here. See https://classic.mceliece.org/ for the specifications and other details.
26 *
27 * Advantages of Classic McEliece:
28 * - Conservative post-quantum security assumptions
29 * - Very fast encapsulation
30 * - Fast decapsulation
31 *
32 * Disadvantages of Classic McEliece:
33 * - Very large public keys (0.26 MB - 1.36 MB)
34 * - Relatively slow key generation
35 * - Algorithm is complex and hard to implement side-channel resistant
36 */
38 public:
39 /**
40 * @brief Load a Classic McEliece public key from bytes.
41 *
42 * @param alg_id The algorithm identifier
43 * @param key_bits The public key bytes
44 */
45 Classic_McEliece_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
46
47 /**
48 * @brief Load a Classic McEliece public key from bytes.
49 *
50 * @param key_bits The public key bytes
51 * @param param_set The parameter set
52 */
53 Classic_McEliece_PublicKey(std::span<const uint8_t> key_bits, Classic_McEliece_Parameter_Set param_set);
54
59
60 ~Classic_McEliece_PublicKey() override = default;
61
62 std::string algo_name() const override { return "ClassicMcEliece"; }
63
64 AlgorithmIdentifier algorithm_identifier() const override;
65
66 OID object_identifier() const override;
67
68 size_t key_length() const override;
69
70 size_t estimated_strength() const override;
71
72 std::vector<uint8_t> public_key_bits() const override;
73
74 std::vector<uint8_t> raw_public_key_bits() const override;
75
76 bool check_key(RandomNumberGenerator&, bool) const override;
77
78 bool supports_operation(PublicKeyOperation op) const override {
79 return (op == PublicKeyOperation::KeyEncapsulation);
80 }
81
82 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
83
84 std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(std::string_view params,
85 std::string_view provider) const override;
86
87 protected:
89
90 protected:
91 std::shared_ptr<Classic_McEliece_PublicKeyInternal>
92 m_public; // NOLINT(misc-non-private-member-variables-in-classes)
93};
94
97
99 public virtual Private_Key {
100 public:
101 /**
102 * @brief Create a new Classic McEliece private key for a specified parameter set.
103 *
104 * @param rng A random number generator
105 * @param param_set The parameter set to use
106 */
108
109 /**
110 * @brief Load a Classic McEliece private key from bytes.
111 *
112 * @param sk The private key bytes
113 * @param param_set The parameter set to use
114 */
115 Classic_McEliece_PrivateKey(std::span<const uint8_t> sk, Classic_McEliece_Parameter_Set param_set);
116
117 /**
118 * @brief Load a Classic McEliece private key from bytes.
119 *
120 * @param alg_id The algorithm identifier
121 * @param key_bits The private key bytes
122 */
123 Classic_McEliece_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
124
125 std::unique_ptr<Public_Key> public_key() const override;
126
127 secure_vector<uint8_t> private_key_bits() const override;
128
129 secure_vector<uint8_t> raw_private_key_bits() const override;
130
131 bool check_key(RandomNumberGenerator&, bool) const override;
132
133 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
134 std::string_view params,
135 std::string_view provider) const override;
136
137 private:
138 std::shared_ptr<Classic_McEliece_PrivateKeyInternal> m_private;
139};
140
142
143} // namespace Botan
144
145#endif // BOTAN_CMCE_H_
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:108
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:105
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:107
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
bool supports_operation(PublicKeyOperation op) const override
Definition cmce.h:78
Classic_McEliece_PublicKey & operator=(Classic_McEliece_PublicKey &&)=default
std::shared_ptr< Classic_McEliece_PublicKeyInternal > m_public
Definition cmce.h:92
Classic_McEliece_PublicKey(Classic_McEliece_PublicKey &&)=default
~Classic_McEliece_PublicKey() override=default
std::string algo_name() const override
Definition cmce.h:62
int(* final)(unsigned char *, CTX *)
PublicKeyOperation
Definition pk_keys.h:45
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61