Botan 3.14.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
20
21/**
22 * Classic McEliece is a Code-Based KEM. It was a round 4 candidate in NIST's PQC competition and was
23 * standardized by ISO in June 2026 (ISO/IEC 18033-2:2006/Amd 2). It is endorsed by the German Federal
24 * Office for Information Security (BSI) for its conservative security assumptions. Both NIST and ISO
25 * parameter sets are implemented here. As the ISO document is not freely available, see
26 * https://classic.mceliece.org/ for the specification this implementation follows; the ISO standard
27 * is stated by the Classic McEliece team to be compatible with it.
28 *
29 * Advantages of Classic McEliece:
30 * - Conservative post-quantum security assumptions
31 * - Very fast encapsulation
32 * - Fast decapsulation
33 *
34 * Disadvantages of Classic McEliece:
35 * - Very large public keys (0.26 MB - 1.36 MB)
36 * - Relatively slow key generation
37 * - Algorithm is complex and hard to implement side-channel resistant
38 *
39 * Note that recent research suggests that the security of Classic McEliece may
40 * be significantly lower than what was previously thought. As of Sep 2026, BSI
41 * recommends that Classic McEliece "should currently no longer be used in new
42 * developments or when planning new cryptographic applications" and that any
43 * usage of it be done as a hybrid KEM, paired with some other algorithm, such
44 * as an EC or lattice-based scheme.
45 */
47 public:
48 /**
49 * @brief Load a Classic McEliece public key from bytes.
50 *
51 * @param alg_id The algorithm identifier
52 * @param key_bits The public key bytes
53 */
54 Classic_McEliece_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
55
56 /**
57 * @brief Load a Classic McEliece public key from bytes.
58 *
59 * @param key_bits The public key bytes
60 * @param param_set The parameter set
61 */
62 Classic_McEliece_PublicKey(std::span<const uint8_t> key_bits, Classic_McEliece_Parameter_Set param_set);
63
68
69 ~Classic_McEliece_PublicKey() override = default;
70
71 std::string algo_name() const override { return "ClassicMcEliece"; }
72
73 AlgorithmIdentifier algorithm_identifier() const override;
74
75 OID object_identifier() const override;
76
77 size_t key_length() const override;
78
79 size_t estimated_strength() const override;
80
81 std::vector<uint8_t> public_key_bits() const override;
82
83 std::vector<uint8_t> raw_public_key_bits() const override;
84
85 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
86
87 bool supports_operation(PublicKeyOperation op) const override {
89 }
90
91 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
92
93 std::unique_ptr<PK_Ops::KEM_Encryption> _create_kem_encryption_op(
94 const PK_KEM_Options_Reader& options) const override;
95
96 protected:
98
99 protected:
100 std::shared_ptr<const Classic_McEliece_PublicKeyInternal> m_public; // NOLINT(*-non-private-member-variable*)
101};
102
105
107 public virtual Private_Key {
108 public:
109 /**
110 * @brief Create a new Classic McEliece private key for a specified parameter set.
111 *
112 * @param rng A random number generator
113 * @param param_set The parameter set to use
114 */
116
117 /**
118 * @brief Load a Classic McEliece private key from bytes.
119 *
120 * @param sk The private key bytes
121 * @param param_set The parameter set to use
122 */
123 Classic_McEliece_PrivateKey(std::span<const uint8_t> sk, Classic_McEliece_Parameter_Set param_set);
124
125 /**
126 * @brief Load a Classic McEliece private key from bytes.
127 *
128 * @param alg_id The algorithm identifier
129 * @param key_bits The private key bytes
130 */
131 Classic_McEliece_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
132
133 std::unique_ptr<Public_Key> public_key() const override;
134
136
138
139 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
140
141 std::unique_ptr<PK_Ops::KEM_Decryption> _create_kem_decryption_op(
142 RandomNumberGenerator& rng, const PK_KEM_Options_Reader& options) const override;
143
144 private:
145 std::shared_ptr<const Classic_McEliece_PrivateKeyInternal> m_private;
146};
147
149
150} // namespace Botan
151
152#endif // BOTAN_CMCE_H_
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:128
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:125
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:127
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
Representation of a Classic McEliece private key.
std::unique_ptr< PK_Ops::KEM_Decryption > _create_kem_decryption_op(RandomNumberGenerator &rng, const PK_KEM_Options_Reader &options) const override
Definition cmce.cpp:143
Classic_McEliece_PrivateKey(RandomNumberGenerator &rng, Classic_McEliece_Parameter_Set param_set)
Create a new Classic McEliece private key for a specified parameter set.
Definition cmce.cpp:91
bool check_key(RandomNumberGenerator &rng, bool strong) const override
Definition cmce.cpp:137
secure_vector< uint8_t > private_key_bits() const override
Definition cmce.cpp:129
std::unique_ptr< Public_Key > public_key() const override
Definition cmce.cpp:125
secure_vector< uint8_t > raw_private_key_bits() const override
Definition cmce.cpp:133
Representation of a Classic McEliece public key.
bool supports_operation(PublicKeyOperation op) const override
Definition cmce.h:87
Classic_McEliece_PublicKey & operator=(Classic_McEliece_PublicKey &&)=default
Classic_McEliece_PublicKey(Classic_McEliece_PublicKey &&)=default
~Classic_McEliece_PublicKey() override=default
Classic_McEliece_PublicKey & operator=(const Classic_McEliece_PublicKey &other)
Definition cmce.cpp:44
Classic_McEliece_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
Load a Classic McEliece public key from bytes.
Definition cmce.cpp:21
std::shared_ptr< const Classic_McEliece_PublicKeyInternal > m_public
Definition cmce.h:100
std::string algo_name() const override
Definition cmce.h:71
PublicKeyOperation
Definition pk_keys.h:50
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128