Botan 3.12.0
Crypto and TLS for C&
Botan::McEliece_PrivateKey Class Referencefinal

#include <mceliece.h>

Inheritance diagram for Botan::McEliece_PrivateKey:
Botan::McEliece_PublicKey Botan::Private_Key Botan::Public_Key Botan::Public_Key Botan::Asymmetric_Key Botan::Asymmetric_Key

Public Member Functions

virtual Signature_Format _default_x509_signature_format () const
virtual std::optional< size_t > _signature_element_size_for_DER_encoding () const
std::string algo_name () const override
AlgorithmIdentifier algorithm_identifier () const override
bool check_key (RandomNumberGenerator &rng, bool strong) const override
virtual std::unique_ptr< PK_Ops::Decryptioncreate_decryption_op (RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const
virtual std::unique_ptr< PK_Ops::Encryptioncreate_encryption_op (RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const
std::unique_ptr< PK_Ops::KEM_Decryptioncreate_kem_decryption_op (RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const override
std::unique_ptr< PK_Ops::KEM_Encryptioncreate_kem_encryption_op (std::string_view params, std::string_view provider) const override
virtual std::unique_ptr< PK_Ops::Key_Agreementcreate_key_agreement_op (RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const
virtual std::unique_ptr< PK_Ops::Signaturecreate_signature_op (RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const
virtual std::unique_ptr< PK_Ops::Verificationcreate_verification_op (std::string_view params, std::string_view provider) const
virtual std::unique_ptr< PK_Ops::Verificationcreate_x509_verification_op (const AlgorithmIdentifier &signature_algorithm, std::string_view provider) const
Signature_Format default_x509_signature_format () const
size_t estimated_strength () const override
std::string fingerprint_private (std::string_view alg) const
std::string fingerprint_public (std::string_view alg="SHA-256") const
std::unique_ptr< Private_Keygenerate_another (RandomNumberGenerator &rng) const final
size_t get_code_length () const
size_t get_codimension () const
size_t get_dimension () const
const polyn_gf2mget_goppa_polyn () const
const std::vector< uint32_t > & get_H_coeffs () const
virtual const BigIntget_int_field (std::string_view field) const
const std::vector< gf2m > & get_Linv () const
size_t get_message_word_bit_length () const
OID get_oid () const
const std::vector< uint8_t > & get_public_matrix () const
const std::vector< polyn_gf2m > & get_sqrtmod () const
size_t get_t () const
size_t key_length () const override
 McEliece_PrivateKey (const McEliece_PrivateKey &)
 McEliece_PrivateKey (const polyn_gf2m &goppa_polyn, const std::vector< uint32_t > &parity_check_matrix_coeffs, const std::vector< polyn_gf2m > &square_root_matrix, const std::vector< gf2m > &inverse_support, const std::vector< uint8_t > &public_matrix)
 McEliece_PrivateKey (McEliece_PrivateKey &&) noexcept
 McEliece_PrivateKey (RandomNumberGenerator &rng, size_t code_length, size_t t)
 McEliece_PrivateKey (std::span< const uint8_t > key_bits)
size_t message_part_size () const
size_t message_parts () const
virtual OID object_identifier () const
bool operator!= (const McEliece_PrivateKey &other) const
bool operator!= (const McEliece_PublicKey &other) const
McEliece_PrivateKeyoperator= (const McEliece_PrivateKey &)
McEliece_PrivateKeyoperator= (McEliece_PrivateKey &&) noexcept
bool operator== (const McEliece_PrivateKey &other) const
bool operator== (const McEliece_PublicKey &other) const
virtual AlgorithmIdentifier pkcs8_algorithm_identifier () const
secure_vector< uint8_t > private_key_bits () const override
secure_vector< uint8_t > private_key_info () const
std::unique_ptr< Public_Keypublic_key () const override
std::vector< uint8_t > public_key_bits () const override
secure_vector< uint8_t > random_plaintext_element (RandomNumberGenerator &rng) const
virtual secure_vector< uint8_t > raw_private_key_bits () const
std::vector< uint8_t > raw_public_key_bits () const override
virtual std::optional< uint64_t > remaining_operations () const
 Retrieves the number of remaining operations if this is a stateful private key.
virtual bool stateful_operation () const
std::vector< uint8_t > subject_public_key () const
bool supports_operation (PublicKeyOperation op) const override
 ~McEliece_PrivateKey () override

Protected Attributes

size_t m_code_length
std::vector< uint8_t > m_public_matrix
size_t m_t

Detailed Description

Definition at line 82 of file mceliece.h.

Constructor & Destructor Documentation

◆ McEliece_PrivateKey() [1/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( RandomNumberGenerator & rng,
size_t code_length,
size_t t )

Generate a McEliece key pair

Suggested parameters for a given security level (SL)

SL=80 n=1632 t=33 - 59 KB pubkey 140 KB privkey SL=107 n=2480 t=45 - 128 KB pubkey 300 KB privkey SL=128 n=2960 t=57 - 195 KB pubkey 459 KB privkey SL=147 n=3408 t=67 - 265 KB pubkey 622 KB privkey SL=191 n=4624 t=95 - 516 KB pubkey 1234 KB privkey SL=256 n=6624 t=115 - 942 KB pubkey 2184 KB privkey

Definition at line 48 of file mceliece_key.cpp.

48 {
49 const uint32_t ext_deg = ceil_log2(code_length);
50 *this = generate_mceliece_key(rng, ext_deg, code_length, t);
51}
constexpr uint8_t ceil_log2(T x)
Definition bit_ops.h:140
McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator &rng, size_t ext_deg, size_t code_length, size_t t)

References Botan::ceil_log2(), and Botan::generate_mceliece_key().

Referenced by McEliece_PrivateKey(), McEliece_PrivateKey(), McEliece_PrivateKey(), operator!=(), operator=(), operator=(), and operator==().

◆ McEliece_PrivateKey() [2/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( std::span< const uint8_t > key_bits)
explicit

Definition at line 204 of file mceliece_key.cpp.

204 {
205 size_t n = 0;
206 size_t t = 0;
208 BER_Decoder dec_base(key_bits, BER_Decoder::Limits::DER());
209 BER_Decoder dec = dec_base.start_sequence();
210 dec.start_sequence().decode(n).decode(t).end_cons();
212
213 if(t == 0 || n == 0) {
214 throw Decoding_Error("invalid McEliece parameters");
215 }
216
217 const uint32_t ext_deg = ceil_log2(n);
218
219 if(ext_deg < 2 || ext_deg > 16) {
220 throw Decoding_Error("McEliece code length out of supported range");
221 }
222
223 // Since ext_deg >= 2, t >= n already implies ext_deg * t > n
224 if(t >= n) {
225 throw Decoding_Error("McEliece parameters are inconsistent");
226 }
227
228 const size_t codimension = ext_deg * t;
229
230 if(codimension >= n) {
231 throw Decoding_Error("McEliece parameters are inconsistent");
232 }
233
234 const size_t dimension = n - codimension;
235 const size_t expected_pubmat_size = dimension * bit_size_to_32bit_size(codimension) * sizeof(uint32_t);
236 if(m_public_matrix.size() != expected_pubmat_size) {
237 throw Decoding_Error("McEliece public matrix size does not match parameters");
238 }
239
240 m_code_length = n;
241 m_t = t;
242 m_codimension = codimension;
243 m_dimension = dimension;
244
245 auto sp_field = std::make_shared<GF2m_Field>(ext_deg);
246 m_g = {polyn_gf2m(enc_g, sp_field)};
247 if(m_g[0].get_degree() != static_cast<int>(t)) {
248 throw Decoding_Error("degree of decoded Goppa polynomial is incorrect");
249 }
250 BER_Decoder dec2 = dec.start_sequence();
251 for(uint32_t i = 0; i < t / 2; i++) {
252 secure_vector<uint8_t> sqrt_enc;
253 dec2.decode(sqrt_enc, ASN1_Type::OctetString);
254 while(sqrt_enc.size() < (t * 2)) {
255 // ensure that the length is always t
256 sqrt_enc.push_back(0);
257 sqrt_enc.push_back(0);
258 }
259 if(sqrt_enc.size() != t * 2) {
260 throw Decoding_Error("length of square root polynomial entry is too large");
261 }
262 m_sqrtmod.push_back(polyn_gf2m(sqrt_enc, sp_field));
263 }
264 secure_vector<uint8_t> enc_support;
265 dec2.end_cons();
266 dec.decode(enc_support, ASN1_Type::OctetString);
267 if(enc_support.size() % 2 != 0) {
268 throw Decoding_Error("encoded support has odd length");
269 }
270 if(enc_support.size() / 2 != n) {
271 throw Decoding_Error("encoded support has length different from code length");
272 }
273 for(uint32_t i = 0; i < n * 2; i += 2) {
274 const gf2m el = (enc_support[i] << 8) | enc_support[i + 1];
275 m_Linv.push_back(el);
276 }
278 dec.decode(enc_H, ASN1_Type::OctetString).end_cons().verify_end();
279 if(enc_H.size() % 4 != 0) {
280 throw Decoding_Error("encoded parity check matrix has length which is not a multiple of four");
281 }
282 if(enc_H.size() / 4 != bit_size_to_32bit_size(m_codimension) * m_code_length) {
283 throw Decoding_Error("encoded parity check matrix has wrong length");
284 }
285
286 for(uint32_t i = 0; i < enc_H.size(); i += 4) {
287 const uint32_t coeff = (enc_H[i] << 24) | (enc_H[i + 1] << 16) | (enc_H[i + 2] << 8) | enc_H[i + 3];
288 m_coeffs.push_back(coeff);
289 }
290}
static Limits DER()
Definition ber_dec.h:35
std::vector< uint8_t > m_public_matrix
Definition mceliece.h:74
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68
size_t bit_size_to_32bit_size(size_t bit_size)
uint16_t gf2m

References Botan::bit_size_to_32bit_size(), Botan::ceil_log2(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::Limits::DER(), Botan::BER_Decoder::end_cons(), Botan::McEliece_PublicKey::m_code_length, Botan::McEliece_PublicKey::m_public_matrix, Botan::McEliece_PublicKey::m_t, Botan::OctetString, Botan::BER_Decoder::push_back(), Botan::BER_Decoder::start_sequence(), and Botan::BER_Decoder::verify_end().

◆ McEliece_PrivateKey() [3/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( const polyn_gf2m & goppa_polyn,
const std::vector< uint32_t > & parity_check_matrix_coeffs,
const std::vector< polyn_gf2m > & square_root_matrix,
const std::vector< gf2m > & inverse_support,
const std::vector< uint8_t > & public_matrix )

Definition at line 34 of file mceliece_key.cpp.

38 :
39 McEliece_PublicKey(public_matrix, goppa_polyn.get_degree(), inverse_support.size()),
40 m_g{goppa_polyn},
41 m_sqrtmod(square_root_matrix),
42 m_Linv(inverse_support),
43 m_coeffs(parity_check_matrix_coeffs),
44 m_codimension(static_cast<size_t>(ceil_log2(inverse_support.size())) * goppa_polyn.get_degree()),
45 m_dimension(inverse_support.size() - m_codimension) {}

References McEliece_PrivateKey(), and Botan::McEliece_PublicKey::McEliece_PublicKey().

◆ ~McEliece_PrivateKey()

Botan::McEliece_PrivateKey::~McEliece_PrivateKey ( )
overridedefault

◆ McEliece_PrivateKey() [4/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( const McEliece_PrivateKey & )
default

References McEliece_PrivateKey().

◆ McEliece_PrivateKey() [5/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( McEliece_PrivateKey && )
defaultnoexcept

References McEliece_PrivateKey().

Member Function Documentation

◆ _default_x509_signature_format()

Signature_Format Botan::Asymmetric_Key::_default_x509_signature_format ( ) const
virtualinherited

◆ _signature_element_size_for_DER_encoding()

virtual std::optional< size_t > Botan::Asymmetric_Key::_signature_element_size_for_DER_encoding ( ) const
inlinevirtualinherited

Certain signatures schemes such as ECDSA have more than one element, and certain unfortunate protocols decided the thing to do was not concatenate them as normally done, but instead DER encode each of the elements as independent values.

If this returns a value x then the signature is checked to be exactly 2*x bytes and split in half for DER encoding.

Reimplemented in Botan::DSA_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::GOST_3410_PublicKey, and Botan::SM2_PublicKey.

Definition at line 144 of file pk_keys.h.

144{ return {}; }

Referenced by _default_x509_signature_format(), Botan::Public_Key::message_part_size(), Botan::Public_Key::message_parts(), Botan::PK_Verifier::PK_Verifier(), and Botan::PK_Verifier::PK_Verifier().

◆ algo_name()

std::string Botan::McEliece_PublicKey::algo_name ( ) const
inlineoverridevirtualinherited

Get the name of the underlying public key scheme.

Returns
name of the public key scheme

Implements Botan::Asymmetric_Key.

Definition at line 38 of file mceliece.h.

38{ return "McEliece"; }

Referenced by Botan::McEliece_PrivateKey::create_kem_decryption_op(), and create_kem_encryption_op().

◆ algorithm_identifier()

AlgorithmIdentifier Botan::McEliece_PublicKey::algorithm_identifier ( ) const
overridevirtualinherited
Returns
X.509 AlgorithmIdentifier for this key

Implements Botan::Public_Key.

Definition at line 77 of file mceliece_key.cpp.

77 {
78 return AlgorithmIdentifier(object_identifier(), AlgorithmIdentifier::USE_EMPTY_PARAM);
79}
virtual OID object_identifier() const
Definition pk_keys.cpp:22

References Botan::Asymmetric_Key::object_identifier(), and Botan::AlgorithmIdentifier::USE_EMPTY_PARAM.

◆ check_key()

bool Botan::McEliece_PrivateKey::check_key ( RandomNumberGenerator & rng,
bool strong ) const
overridevirtual

Implements Botan::Asymmetric_Key.

Definition at line 186 of file mceliece_key.cpp.

186 {
187 const secure_vector<uint8_t> plaintext = this->random_plaintext_element(rng);
188
189 secure_vector<uint8_t> ciphertext;
191 mceliece_encrypt(ciphertext, errors, plaintext, *this, rng);
192
193 secure_vector<uint8_t> plaintext_out;
194 secure_vector<uint8_t> errors_out;
195 mceliece_decrypt(plaintext_out, errors_out, ciphertext, *this);
196
197 if(errors != errors_out || plaintext != plaintext_out) {
198 return false;
199 }
200
201 return true;
202}
secure_vector< uint8_t > random_plaintext_element(RandomNumberGenerator &rng) const
void mceliece_decrypt(secure_vector< uint8_t > &plaintext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &ciphertext, const McEliece_PrivateKey &key)
void mceliece_encrypt(secure_vector< uint8_t > &ciphertext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &plaintext, const McEliece_PublicKey &key, RandomNumberGenerator &rng)
Definition mceliece.cpp:109

References Botan::mceliece_decrypt(), Botan::mceliece_encrypt(), and Botan::McEliece_PublicKey::random_plaintext_element().

Referenced by operator=().

◆ create_decryption_op()

std::unique_ptr< PK_Ops::Decryption > Botan::Private_Key::create_decryption_op ( RandomNumberGenerator & rng,
std::string_view params,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return an decryption operation for this key/params or throw

Parameters
Random Number Generatorsa random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::ElGamal_PrivateKey, Botan::RSA_PrivateKey, Botan::SM2_PrivateKey, and Botan::TPM2::RSA_PrivateKey.

Definition at line 126 of file pk_keys.cpp.

128 {
129 throw Lookup_Error(fmt("{} does not support decryption", algo_name()));
130}
virtual std::string algo_name() const =0
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Decryptor_EME::PK_Decryptor_EME().

◆ create_encryption_op()

std::unique_ptr< PK_Ops::Encryption > Botan::Public_Key::create_encryption_op ( RandomNumberGenerator & rng,
std::string_view params,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return an encryption operation for this key/params or throw

Parameters
Random Number Generatorsa random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::ElGamal_PublicKey, Botan::RSA_PublicKey, Botan::SM2_PublicKey, and Botan::TPM2::RSA_PublicKey.

Definition at line 105 of file pk_keys.cpp.

107 {
108 throw Lookup_Error(fmt("{} does not support encryption", algo_name()));
109}

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Encryptor_EME::PK_Encryptor_EME().

◆ create_kem_decryption_op()

std::unique_ptr< PK_Ops::KEM_Decryption > Botan::McEliece_PrivateKey::create_kem_decryption_op ( RandomNumberGenerator & rng,
std::string_view params,
std::string_view provider ) const
overridevirtual

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return a KEM decryption operation for this key/params or throw

Parameters
Random Number Generatorsa random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
paramsadditional parameters
providerthe provider to use

Reimplemented from Botan::Private_Key.

Definition at line 415 of file mceliece_key.cpp.

417 {
418 if(provider == "base" || provider.empty()) {
419 return std::make_unique<MCE_KEM_Decryptor>(*this, params);
420 }
421 throw Provider_Not_Found(algo_name(), provider);
422}
std::string algo_name() const override
Definition mceliece.h:38

References Botan::McEliece_PublicKey::algo_name().

◆ create_kem_encryption_op()

std::unique_ptr< PK_Ops::KEM_Encryption > Botan::McEliece_PublicKey::create_kem_encryption_op ( std::string_view params,
std::string_view provider ) const
overridevirtualinherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a KEM encryption operation for this key/params or throw

Parameters
paramsadditional parameters
providerthe provider to use

Reimplemented from Botan::Public_Key.

Definition at line 407 of file mceliece_key.cpp.

408 {
409 if(provider == "base" || provider.empty()) {
410 return std::make_unique<MCE_KEM_Encryptor>(*this, params);
411 }
412 throw Provider_Not_Found(algo_name(), provider);
413}

References algo_name().

◆ create_key_agreement_op()

std::unique_ptr< PK_Ops::Key_Agreement > Botan::Private_Key::create_key_agreement_op ( RandomNumberGenerator & rng,
std::string_view params,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return a key agreement operation for this key/params or throw

Parameters
Random Number Generatorsa random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::DH_PrivateKey, Botan::ECDH_PrivateKey, Botan::X25519_PrivateKey, and Botan::X448_PrivateKey.

Definition at line 144 of file pk_keys.cpp.

146 {
147 throw Lookup_Error(fmt("{} does not support key agreement", algo_name()));
148}

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Key_Agreement::PK_Key_Agreement().

◆ create_signature_op()

std::unique_ptr< PK_Ops::Signature > Botan::Private_Key::create_signature_op ( RandomNumberGenerator & rng,
std::string_view params,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return a signature operation for this key/params or throw

Parameters
Random Number Generatorsa random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::Dilithium_PrivateKey, Botan::DSA_PrivateKey, Botan::ECDSA_PrivateKey, Botan::ECGDSA_PrivateKey, Botan::ECKCDSA_PrivateKey, Botan::Ed25519_PrivateKey, Botan::Ed448_PrivateKey, Botan::GOST_3410_PrivateKey, Botan::HSS_LMS_PrivateKey, Botan::RSA_PrivateKey, Botan::SM2_PrivateKey, Botan::SphincsPlus_PrivateKey, Botan::TPM2::EC_PrivateKey, Botan::TPM2::RSA_PrivateKey, Botan::TPM_PrivateKey, and Botan::XMSS_PrivateKey.

Definition at line 138 of file pk_keys.cpp.

140 {
141 throw Lookup_Error(fmt("{} does not support signatures", algo_name()));
142}

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Signer::PK_Signer().

◆ create_verification_op()

std::unique_ptr< PK_Ops::Verification > Botan::Public_Key::create_verification_op ( std::string_view params,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return a verification operation for this key/params or throw

Parameters
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::Dilithium_PublicKey, Botan::DSA_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::Ed25519_PublicKey, Botan::Ed448_PublicKey, Botan::GOST_3410_PublicKey, Botan::HSS_LMS_PublicKey, Botan::RSA_PublicKey, Botan::SM2_PublicKey, Botan::SphincsPlus_PublicKey, Botan::TPM2::EC_PublicKey, Botan::TPM2::RSA_PublicKey, and Botan::XMSS_PublicKey.

Definition at line 116 of file pk_keys.cpp.

117 {
118 throw Lookup_Error(fmt("{} does not support verification", algo_name()));
119}

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Verifier::PK_Verifier().

◆ create_x509_verification_op()

std::unique_ptr< PK_Ops::Verification > Botan::Public_Key::create_x509_verification_op ( const AlgorithmIdentifier & signature_algorithm,
std::string_view provider ) const
virtualinherited

This is an internal library function exposed on key types. In all cases applications should use wrappers in pubkey.h

Return a verification operation for this combination of key and signature algorithm or throw.

Parameters
signature_algorithmis the X.509 algorithm identifier encoding the padding scheme and hash hash function used in the signature if applicable.
providerthe provider to use

Reimplemented in Botan::Dilithium_PublicKey, Botan::DSA_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::Ed25519_PublicKey, Botan::Ed448_PublicKey, Botan::GOST_3410_PublicKey, Botan::HSS_LMS_PublicKey, Botan::RSA_PublicKey, Botan::SphincsPlus_PublicKey, and Botan::XMSS_PublicKey.

Definition at line 121 of file pk_keys.cpp.

122 {
123 throw Lookup_Error(fmt("{} does not support X.509 verification", algo_name()));
124}

References Botan::Asymmetric_Key::algo_name(), and Botan::fmt().

Referenced by Botan::PK_Verifier::PK_Verifier().

◆ default_x509_signature_format()

Signature_Format Botan::Public_Key::default_x509_signature_format ( ) const
inlineinherited

Definition at line 237 of file pk_keys.h.

237 {
239 }
virtual Signature_Format _default_x509_signature_format() const
Definition pk_keys.cpp:30

References Botan::Asymmetric_Key::_default_x509_signature_format(), and default_x509_signature_format().

Referenced by default_x509_signature_format().

◆ estimated_strength()

size_t Botan::McEliece_PublicKey::estimated_strength ( ) const
overridevirtualinherited

Return the estimated strength of the underlying key against the best currently known attack. Note that this ignores anything but pure attacks against the key itself and do not take into account padding schemes, usage mistakes, etc which might reduce the strength. However it does suffice to provide an upper bound.

Returns
estimated strength in bits

Implements Botan::Asymmetric_Key.

Definition at line 102 of file mceliece_key.cpp.

102 {
104}
size_t mceliece_work_factor(size_t n, size_t t)

References m_code_length, m_t, and Botan::mceliece_work_factor().

◆ fingerprint_private()

std::string Botan::Private_Key::fingerprint_private ( std::string_view alg) const
inherited
Returns
Hash of the PKCS #8 encoding for this key object

Definition at line 101 of file pk_keys.cpp.

101 {
102 return create_hex_fingerprint(private_key_bits(), hash_algo);
103}
virtual secure_vector< uint8_t > private_key_bits() const =0
std::string create_hex_fingerprint(std::span< const uint8_t > bits, std::string_view hash_name)
Definition pk_keys.cpp:38

References Botan::create_hex_fingerprint(), and private_key_bits().

Referenced by Botan::Certificate_Store_In_SQL::find_certs_for_key(), Botan::Certificate_Store_In_SQL::insert_key(), and Botan::Certificate_Store_In_SQL::remove_key().

◆ fingerprint_public()

std::string Botan::Public_Key::fingerprint_public ( std::string_view alg = "SHA-256") const
inherited
Returns
Hash of the subject public key

Definition at line 94 of file pk_keys.cpp.

94 {
95 return create_hex_fingerprint(subject_public_key(), hash_algo);
96}
std::vector< uint8_t > subject_public_key() const
Definition pk_keys.cpp:63

References Botan::create_hex_fingerprint(), and subject_public_key().

Referenced by public_key_bits().

◆ generate_another()

std::unique_ptr< Private_Key > Botan::McEliece_PublicKey::generate_another ( RandomNumberGenerator & rng) const
finalvirtualinherited

Generate another (cryptographically independent) key pair using the same algorithm parameters as this key. This is most useful for algorithms that support PublicKeyOperation::KeyAgreement to generate a fitting ephemeral key pair. For other key types it might throw Not_Implemented.

Implements Botan::Asymmetric_Key.

Definition at line 403 of file mceliece_key.cpp.

403 {
404 return std::make_unique<McEliece_PrivateKey>(rng, get_code_length(), get_t());
405}
size_t get_t() const
Definition mceliece.h:50
size_t get_code_length() const
Definition mceliece.h:52

References get_code_length(), and get_t().

◆ get_code_length()

size_t Botan::McEliece_PublicKey::get_code_length ( ) const
inlineinherited

◆ get_codimension()

size_t Botan::McEliece_PrivateKey::get_codimension ( ) const
inline

Definition at line 127 of file mceliece.h.

127{ return m_codimension; }

Referenced by Botan::mceliece_decrypt().

◆ get_dimension()

size_t Botan::McEliece_PrivateKey::get_dimension ( ) const
inline

Definition at line 125 of file mceliece.h.

125{ return m_dimension; }

Referenced by Botan::mceliece_decrypt().

◆ get_goppa_polyn()

const polyn_gf2m & Botan::McEliece_PrivateKey::get_goppa_polyn ( ) const

Definition at line 53 of file mceliece_key.cpp.

53 {
54 return m_g[0];
55}

Referenced by Botan::mceliece_decrypt(), and operator=().

◆ get_H_coeffs()

const std::vector< uint32_t > & Botan::McEliece_PrivateKey::get_H_coeffs ( ) const
inline

Definition at line 119 of file mceliece.h.

119{ return m_coeffs; }

References get_H_coeffs().

Referenced by get_H_coeffs(), and Botan::mceliece_decrypt().

◆ get_int_field()

const BigInt & Botan::Asymmetric_Key::get_int_field ( std::string_view field) const
virtualinherited

Access an algorithm specific field

If the field is not known for this algorithm, an Invalid_Argument is thrown. The interpretation of the result requires knowledge of which algorithm is involved. For instance for RSA "p" represents one of the secret primes, while for DSA "p" is the public prime.

Some algorithms may not implement this method at all.

This is primarily used to implement the FFI botan_pubkey_get_field and botan_privkey_get_field functions.

TODO(Botan4) Change this to return by value

Reimplemented in Botan::DH_PrivateKey, Botan::DH_PublicKey, Botan::DSA_PrivateKey, Botan::DSA_PublicKey, Botan::EC_PrivateKey, Botan::EC_PublicKey, Botan::ElGamal_PrivateKey, Botan::ElGamal_PublicKey, Botan::RSA_PrivateKey, and Botan::RSA_PublicKey.

Definition at line 18 of file pk_keys.cpp.

18 {
19 throw Unknown_PK_Field_Name(algo_name(), field);
20}

References algo_name().

Referenced by estimated_strength(), Botan::EC_PublicKey::get_int_field(), and Botan::RSA_PublicKey::get_int_field().

◆ get_Linv()

const std::vector< gf2m > & Botan::McEliece_PrivateKey::get_Linv ( ) const
inline

Definition at line 121 of file mceliece.h.

121{ return m_Linv; }

Referenced by Botan::mceliece_decrypt().

◆ get_message_word_bit_length()

size_t Botan::McEliece_PublicKey::get_message_word_bit_length ( ) const
inherited

Definition at line 57 of file mceliece_key.cpp.

57 {
58 const size_t codimension = ceil_log2(m_code_length) * m_t;
59 return m_code_length - codimension;
60}

References Botan::ceil_log2(), m_code_length, and m_t.

Referenced by Botan::mceliece_decrypt(), and random_plaintext_element().

◆ get_oid()

OID Botan::Public_Key::get_oid ( ) const
inlineinherited

Deprecated version of object_identifier

Definition at line 168 of file pk_keys.h.

168{ return this->object_identifier(); }

References get_oid(), and Botan::Asymmetric_Key::object_identifier().

Referenced by get_oid().

◆ get_public_matrix()

const std::vector< uint8_t > & Botan::McEliece_PublicKey::get_public_matrix ( ) const
inlineinherited

Definition at line 56 of file mceliece.h.

56{ return m_public_matrix; }

References m_public_matrix.

Referenced by Botan::mceliece_encrypt(), and Botan::McEliece_PrivateKey::public_key().

◆ get_sqrtmod()

const std::vector< polyn_gf2m > & Botan::McEliece_PrivateKey::get_sqrtmod ( ) const
inline

Definition at line 123 of file mceliece.h.

123{ return m_sqrtmod; }

Referenced by Botan::mceliece_decrypt().

◆ get_t()

size_t Botan::McEliece_PublicKey::get_t ( ) const
inlineinherited

◆ key_length()

size_t Botan::McEliece_PublicKey::key_length ( ) const
overridevirtualinherited

Return an integer value best approximating the length of the primary security parameter. For example for RSA this will be the size of the modulus, for ECDSA the size of the ECC group, and for McEliece the size of the code will be returned.

Implements Botan::Public_Key.

Definition at line 98 of file mceliece_key.cpp.

98 {
99 return m_code_length;
100}

References m_code_length.

◆ message_part_size()

size_t Botan::Public_Key::message_part_size ( ) const
inlineinherited

Returns how large each of the message parts referred to by message_parts() is

This function is public but applications should have few reasons to ever call this.

Returns
size of the message parts in bits

Definition at line 228 of file pk_keys.h.

228 {
229 return _signature_element_size_for_DER_encoding().value_or(0);
230 }

References Botan::Asymmetric_Key::_signature_element_size_for_DER_encoding(), and message_part_size().

Referenced by message_part_size().

◆ message_parts()

size_t Botan::Public_Key::message_parts ( ) const
inlineinherited

Returns more than 1 if the output of this algorithm (ciphertext, signature) should be treated as more than one value. This is used for algorithms like DSA and ECDSA, where the (r,s) output pair can be encoded as either a plain binary list or a TLV tagged DER encoding depending on the protocol.

This function is public but applications should have few reasons to ever call this.

Returns
number of message parts

Definition at line 215 of file pk_keys.h.

215 {
217 }

References Botan::Asymmetric_Key::_signature_element_size_for_DER_encoding(), and message_parts().

Referenced by message_parts().

◆ object_identifier()

◆ operator!=() [1/2]

bool Botan::McEliece_PrivateKey::operator!= ( const McEliece_PrivateKey & other) const
inline

Definition at line 135 of file mceliece.h.

135{ return !(*this == other); }

References McEliece_PrivateKey().

◆ operator!=() [2/2]

bool Botan::McEliece_PublicKey::operator!= ( const McEliece_PublicKey & other) const
inlineinherited

Definition at line 60 of file mceliece.h.

60{ return !(*this == other); }

References McEliece_PublicKey().

◆ operator=() [1/2]

McEliece_PrivateKey & Botan::McEliece_PrivateKey::operator= ( const McEliece_PrivateKey & )
default

References McEliece_PrivateKey().

◆ operator=() [2/2]

McEliece_PrivateKey & Botan::McEliece_PrivateKey::operator= ( McEliece_PrivateKey && )
defaultnoexcept

◆ operator==() [1/2]

bool Botan::McEliece_PrivateKey::operator== ( const McEliece_PrivateKey & other) const

Definition at line 292 of file mceliece_key.cpp.

292 {
293 if(*static_cast<const McEliece_PublicKey*>(this) != *static_cast<const McEliece_PublicKey*>(&other)) {
294 return false;
295 }
296 if(m_g != other.m_g) {
297 return false;
298 }
299
300 if(m_sqrtmod != other.m_sqrtmod) {
301 return false;
302 }
303 if(m_Linv != other.m_Linv) {
304 return false;
305 }
306 if(m_coeffs != other.m_coeffs) {
307 return false;
308 }
309
310 if(m_codimension != other.m_codimension || m_dimension != other.m_dimension) {
311 return false;
312 }
313
314 return true;
315}
McEliece_PublicKey(std::span< const uint8_t > key_bits)

References McEliece_PrivateKey(), and Botan::McEliece_PublicKey::McEliece_PublicKey().

◆ operator==() [2/2]

bool Botan::McEliece_PublicKey::operator== ( const McEliece_PublicKey & other) const
inherited

Definition at line 321 of file mceliece_key.cpp.

321 {
322 if(m_public_matrix != other.m_public_matrix) {
323 return false;
324 }
325 if(m_t != other.m_t) {
326 return false;
327 }
328 if(m_code_length != other.m_code_length) {
329 return false;
330 }
331 return true;
332}

References m_code_length, m_public_matrix, m_t, and McEliece_PublicKey().

◆ pkcs8_algorithm_identifier()

virtual AlgorithmIdentifier Botan::Private_Key::pkcs8_algorithm_identifier ( ) const
inlinevirtualinherited
Returns
PKCS #8 AlgorithmIdentifier for this key Might be different from the X.509 identifier, but normally is not

Reimplemented in Botan::GOST_3410_PrivateKey, and Botan::HSS_LMS_PrivateKey.

Definition at line 334 of file pk_keys.h.

334{ return algorithm_identifier(); }
virtual AlgorithmIdentifier algorithm_identifier() const =0

References Botan::Public_Key::algorithm_identifier().

Referenced by private_key_info().

◆ private_key_bits()

secure_vector< uint8_t > Botan::McEliece_PrivateKey::private_key_bits ( ) const
overridevirtual
Returns
BER encoded private key bits

Implements Botan::Private_Key.

Definition at line 153 of file mceliece_key.cpp.

153 {
154 DER_Encoder enc;
155 enc.start_sequence()
156 .start_sequence()
157 .encode(get_code_length())
158 .encode(get_t())
159 .end_cons()
161 .encode(m_g[0].encode(), ASN1_Type::OctetString); // g as octet string
162 enc.start_sequence();
163 for(const auto& x : m_sqrtmod) {
164 enc.encode(x.encode(), ASN1_Type::OctetString);
165 }
166 enc.end_cons();
167 secure_vector<uint8_t> enc_support;
168
169 for(const uint16_t Linv : m_Linv) {
170 enc_support.push_back(get_byte<0>(Linv));
171 enc_support.push_back(get_byte<1>(Linv));
172 }
173 enc.encode(enc_support, ASN1_Type::OctetString);
175 for(const uint32_t coef : m_coeffs) {
176 enc_H.push_back(get_byte<0>(coef));
177 enc_H.push_back(get_byte<1>(coef));
178 enc_H.push_back(get_byte<2>(coef));
179 enc_H.push_back(get_byte<3>(coef));
180 }
181 enc.encode(enc_H, ASN1_Type::OctetString);
182 enc.end_cons();
183 return enc.get_contents();
184}
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:39
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::get_byte(), Botan::McEliece_PublicKey::get_code_length(), Botan::DER_Encoder::get_contents(), Botan::McEliece_PublicKey::get_t(), Botan::McEliece_PublicKey::m_public_matrix, Botan::OctetString, and Botan::DER_Encoder::start_sequence().

◆ private_key_info()

secure_vector< uint8_t > Botan::Private_Key::private_key_info ( ) const
inherited
Returns
PKCS #8 private key encoding for this key object

Definition at line 75 of file pk_keys.cpp.

75 {
76 const size_t PKCS8_VERSION = 0;
77
78 return DER_Encoder()
79 .start_sequence()
80 .encode(PKCS8_VERSION)
83 .end_cons()
84 .get_contents();
85}
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition pk_keys.h:334

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::OctetString, pkcs8_algorithm_identifier(), private_key_bits(), and Botan::DER_Encoder::start_sequence().

Referenced by Botan::PKCS8::BER_encode(), Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(), Botan::PKCS8::PEM_encode(), and public_key().

◆ public_key()

std::unique_ptr< Public_Key > Botan::McEliece_PrivateKey::public_key ( ) const
overridevirtual

Allocate a new object for the public key associated with this private key.

Returns
public key

Implements Botan::Private_Key.

Definition at line 317 of file mceliece_key.cpp.

317 {
318 return std::make_unique<McEliece_PublicKey>(get_public_matrix(), get_t(), get_code_length());
319}
const std::vector< uint8_t > & get_public_matrix() const
Definition mceliece.h:56

References Botan::McEliece_PublicKey::get_code_length(), Botan::McEliece_PublicKey::get_public_matrix(), and Botan::McEliece_PublicKey::get_t().

◆ public_key_bits()

std::vector< uint8_t > Botan::McEliece_PublicKey::public_key_bits ( ) const
overridevirtualinherited
Returns
BER encoded public key bits

Implements Botan::Public_Key.

Definition at line 85 of file mceliece_key.cpp.

85 {
86 std::vector<uint8_t> output;
87 DER_Encoder(output)
88 .start_sequence()
89 .start_sequence()
90 .encode(get_code_length())
91 .encode(get_t())
92 .end_cons()
94 .end_cons();
95 return output;
96}

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), get_code_length(), get_t(), m_public_matrix, Botan::OctetString, and Botan::DER_Encoder::start_sequence().

◆ random_plaintext_element()

secure_vector< uint8_t > Botan::McEliece_PublicKey::random_plaintext_element ( RandomNumberGenerator & rng) const
inherited

Definition at line 62 of file mceliece_key.cpp.

62 {
63 const size_t bits = get_message_word_bit_length();
64
65 secure_vector<uint8_t> plaintext((bits + 7) / 8);
66 rng.randomize(plaintext.data(), plaintext.size());
67
68 // unset unused bits in the last plaintext byte
69 if(const uint32_t used = bits % 8) {
70 const uint8_t mask = (1 << used) - 1;
71 plaintext[plaintext.size() - 1] &= mask;
72 }
73
74 return plaintext;
75}
size_t get_message_word_bit_length() const

References get_message_word_bit_length(), and Botan::RandomNumberGenerator::randomize().

Referenced by Botan::McEliece_PrivateKey::check_key(), and ~McEliece_PublicKey().

◆ raw_private_key_bits()

secure_vector< uint8_t > Botan::Private_Key::raw_private_key_bits ( ) const
virtualinherited
Returns
binary private key bits, with no additional encoding

Note: some algorithms (for example RSA) do not have an obvious encoding for this value due to having many different values, and thus not implement this function. The default implementation throws Not_Implemented

Reimplemented in Botan::Classic_McEliece_PrivateKey, Botan::DH_PrivateKey, Botan::Dilithium_PrivateKey, Botan::DSA_PrivateKey, Botan::EC_PrivateKey, Botan::Ed25519_PrivateKey, Botan::Ed448_PrivateKey, Botan::ElGamal_PrivateKey, Botan::FrodoKEM_PrivateKey, Botan::HSS_LMS_PrivateKey, Botan::KEX_to_KEM_Adapter_PrivateKey, Botan::Kyber_PrivateKey, Botan::SphincsPlus_PrivateKey, Botan::TPM2::PrivateKey, Botan::X25519_PrivateKey, and Botan::X448_PrivateKey.

Definition at line 87 of file pk_keys.cpp.

87 {
88 throw Not_Implemented(algo_name() + " does not implement raw_private_key_bits");
89}

References Botan::Asymmetric_Key::algo_name().

Referenced by private_key_bits().

◆ raw_public_key_bits()

std::vector< uint8_t > Botan::McEliece_PublicKey::raw_public_key_bits ( ) const
overridevirtualinherited
Returns
binary public key bits, with no additional encoding

For key agreements this is an alias for PK_Key_Agreement_Key::public_value.

Note: some algorithms (for example RSA) do not have an obvious encoding for this value due to having many different values, and thus throw Not_Implemented when invoking this method.

Implements Botan::Public_Key.

Definition at line 81 of file mceliece_key.cpp.

81 {
82 return m_public_matrix;
83}

References m_public_matrix.

◆ remaining_operations()

virtual std::optional< uint64_t > Botan::Private_Key::remaining_operations ( ) const
inlinevirtualinherited

Retrieves the number of remaining operations if this is a stateful private key.

Returns
the number of remaining operations or std::nullopt if not applicable.

Reimplemented in Botan::HSS_LMS_PrivateKey, and Botan::XMSS_PrivateKey.

Definition at line 347 of file pk_keys.h.

347{ return std::nullopt; }

◆ stateful_operation()

virtual bool Botan::Private_Key::stateful_operation ( ) const
inlinevirtualinherited

Indicates if this key is stateful, ie that performing a private key operation requires updating the key storage.

Reimplemented in Botan::HSS_LMS_PrivateKey, and Botan::XMSS_PrivateKey.

Definition at line 340 of file pk_keys.h.

340{ return false; }

◆ subject_public_key()

std::vector< uint8_t > Botan::Public_Key::subject_public_key ( ) const
inherited
Returns
X.509 subject key encoding for this key object

Definition at line 63 of file pk_keys.cpp.

63 {
64 std::vector<uint8_t> output;
65
66 DER_Encoder(output)
67 .start_sequence()
68 .encode(algorithm_identifier())
70 .end_cons();
71
72 return output;
73}
virtual std::vector< uint8_t > public_key_bits() const =0

References algorithm_identifier(), Botan::BitString, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), public_key_bits(), and Botan::DER_Encoder::start_sequence().

Referenced by Botan::X509::BER_encode(), Botan::PKCS10_Request::create(), fingerprint_public(), Botan::X509::PEM_encode(), and public_key_bits().

◆ supports_operation()

bool Botan::McEliece_PublicKey::supports_operation ( PublicKeyOperation op) const
inlineoverridevirtualinherited

Return true if this key could be used for the specified type of operation.

Implements Botan::Asymmetric_Key.

Definition at line 64 of file mceliece.h.

64 {
66 }

References Botan::KeyEncapsulation.

Member Data Documentation

◆ m_code_length

◆ m_public_matrix

std::vector<uint8_t> Botan::McEliece_PublicKey::m_public_matrix
protectedinherited

◆ m_t


The documentation for this class was generated from the following files: