Botan 3.9.0
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 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& rng, bool strong) const override;
77
78 bool supports_operation(PublicKeyOperation op) const override {
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> m_public; // NOLINT(*-non-private-member-variable*)
92};
93
96
98 public virtual Private_Key {
99 public:
100 /**
101 * @brief Create a new Classic McEliece private key for a specified parameter set.
102 *
103 * @param rng A random number generator
104 * @param param_set The parameter set to use
105 */
107
108 /**
109 * @brief Load a Classic McEliece private key from bytes.
110 *
111 * @param sk The private key bytes
112 * @param param_set The parameter set to use
113 */
114 Classic_McEliece_PrivateKey(std::span<const uint8_t> sk, Classic_McEliece_Parameter_Set param_set);
115
116 /**
117 * @brief Load a Classic McEliece private key from bytes.
118 *
119 * @param alg_id The algorithm identifier
120 * @param key_bits The private key bytes
121 */
122 Classic_McEliece_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
123
124 std::unique_ptr<Public_Key> public_key() const override;
125
127
129
130 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
131
132 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
133 std::string_view params,
134 std::string_view provider) const override;
135
136 private:
137 std::shared_ptr<Classic_McEliece_PrivateKeyInternal> m_private;
138};
139
141
142} // namespace Botan
143
144#endif // BOTAN_CMCE_H_
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:122
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:119
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:121
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
Representation of a Classic McEliece private key.
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:88
std::unique_ptr< PK_Ops::KEM_Decryption > create_kem_decryption_op(RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const override
Definition cmce.cpp:133
bool check_key(RandomNumberGenerator &rng, bool strong) const override
Definition cmce.cpp:129
secure_vector< uint8_t > private_key_bits() const override
Definition cmce.cpp:121
std::unique_ptr< Public_Key > public_key() const override
Definition cmce.cpp:117
secure_vector< uint8_t > raw_private_key_bits() const override
Definition cmce.cpp:125
Representation of a Classic McEliece public key.
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:91
Classic_McEliece_PublicKey(Classic_McEliece_PublicKey &&)=default
~Classic_McEliece_PublicKey() override=default
Classic_McEliece_PublicKey & operator=(const Classic_McEliece_PublicKey &other)
Definition cmce.cpp:40
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:24
std::string algo_name() const override
Definition cmce.h:62
PublicKeyOperation
Definition pk_keys.h:46
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69