Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | Protected Attributes | List of all members
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

Public Member Functions

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, const std::string &params, const std::string &provider) const
 
virtual std::unique_ptr< PK_Ops::Encryptioncreate_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
std::unique_ptr< PK_Ops::KEM_Decryptioncreate_kem_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
 
std::unique_ptr< PK_Ops::KEM_Encryptioncreate_kem_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
 
virtual std::unique_ptr< PK_Ops::Key_Agreementcreate_key_agreement_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
virtual std::unique_ptr< PK_Ops::Signaturecreate_signature_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
virtual std::unique_ptr< PK_Ops::Verificationcreate_verification_op (const std::string &params, const std::string &provider) const
 
virtual Signature_Format default_x509_signature_format () const
 
size_t estimated_strength () const override
 
std::string fingerprint_private (const std::string &alg) const
 
std::string fingerprint_public (const std::string &alg="SHA-256") const
 
size_t get_code_length () const
 
size_t get_codimension () const
 
size_t get_dimension () const
 
polyn_gf2m const & get_goppa_polyn () const
 
std::vector< uint32_t > const & get_H_coeffs () const
 
std::vector< gf2m > const & get_Linv () const
 
size_t get_message_word_bit_length () const
 
virtual OID get_oid () const
 
const std::vector< uint8_t > & get_public_matrix () const
 
std::vector< polyn_gf2m > const & get_sqrtmod () const
 
size_t get_t () const
 
size_t key_length () const override
 
 McEliece_PrivateKey (const McEliece_PrivateKey &)
 
 McEliece_PrivateKey (const secure_vector< uint8_t > &key_bits)
 
 McEliece_PrivateKey (McEliece_PrivateKey &&)
 
 McEliece_PrivateKey (polyn_gf2m const &goppa_polyn, std::vector< uint32_t > const &parity_check_matrix_coeffs, std::vector< polyn_gf2m > const &square_root_matrix, std::vector< gf2m > const &inverse_support, std::vector< uint8_t > const &public_matrix)
 
 McEliece_PrivateKey (RandomNumberGenerator &rng, size_t code_length, size_t t)
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
bool operator!= (const McEliece_PrivateKey &other) const
 
bool operator!= (const McEliece_PublicKey &other) const
 
McEliece_PrivateKeyoperator= (const McEliece_PrivateKey &)
 
McEliece_PrivateKeyoperator= (McEliece_PrivateKey &&)
 
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 bool stateful_operation () const
 
std::vector< uint8_t > subject_public_key () const
 
 ~McEliece_PrivateKey ()
 

Protected Attributes

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

Detailed Description

Definition at line 72 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 47 of file mceliece_key.cpp.

48 {
49 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:119
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().

◆ McEliece_PrivateKey() [2/5]

Botan::McEliece_PrivateKey::McEliece_PrivateKey ( const secure_vector< uint8_t > &  key_bits)
explicit

Definition at line 181 of file mceliece_key.cpp.

182 {
183 size_t n, t;
184 secure_vector<uint8_t> enc_g;
185 BER_Decoder dec_base(key_bits);
186 BER_Decoder dec = dec_base.start_sequence()
187 .start_sequence()
188 .decode(n)
189 .decode(t)
190 .end_cons()
192 .decode(enc_g, ASN1_Type::OctetString);
193
194 if(t == 0 || n == 0)
195 throw Decoding_Error("invalid McEliece parameters");
196
197 uint32_t ext_deg = ceil_log2(n);
198 m_code_length = n;
199 m_t = t;
200 m_codimension = (ext_deg * t);
201 m_dimension = (n - m_codimension);
202
203 auto sp_field = std::make_shared<GF2m_Field>(ext_deg);
204 m_g = { polyn_gf2m(enc_g, sp_field) };
205 if(m_g[0].get_degree() != static_cast<int>(t))
206 {
207 throw Decoding_Error("degree of decoded Goppa polynomial is incorrect");
208 }
209 BER_Decoder dec2 = dec.start_sequence();
210 for(uint32_t i = 0; i < t/2; i++)
211 {
212 secure_vector<uint8_t> sqrt_enc;
213 dec2.decode(sqrt_enc, ASN1_Type::OctetString);
214 while(sqrt_enc.size() < (t*2))
215 {
216 // ensure that the length is always t
217 sqrt_enc.push_back(0);
218 sqrt_enc.push_back(0);
219 }
220 if(sqrt_enc.size() != t*2)
221 {
222 throw Decoding_Error("length of square root polynomial entry is too large");
223 }
224 m_sqrtmod.push_back(polyn_gf2m(sqrt_enc, sp_field));
225 }
226 secure_vector<uint8_t> enc_support;
227 BER_Decoder dec3 = dec2.end_cons()
228 .decode(enc_support, ASN1_Type::OctetString);
229 if(enc_support.size() % 2)
230 {
231 throw Decoding_Error("encoded support has odd length");
232 }
233 if(enc_support.size() / 2 != n)
234 {
235 throw Decoding_Error("encoded support has length different from code length");
236 }
237 for(uint32_t i = 0; i < n*2; i+=2)
238 {
239 gf2m el = (enc_support[i] << 8) | enc_support[i+1];
240 m_Linv.push_back(el);
241 }
242 secure_vector<uint8_t> enc_H;
243 dec3.decode(enc_H, ASN1_Type::OctetString)
244 .end_cons();
245 if(enc_H.size() % 4)
246 {
247 throw Decoding_Error("encoded parity check matrix has length which is not a multiple of four");
248 }
249 if(enc_H.size() / 4 != bit_size_to_32bit_size(m_codimension) * m_code_length)
250 {
251 throw Decoding_Error("encoded parity check matrix has wrong length");
252 }
253
254 for(uint32_t i = 0; i < enc_H.size(); i+=4)
255 {
256 uint32_t coeff = (enc_H[i] << 24) | (enc_H[i+1] << 16) | (enc_H[i+2] << 8) | enc_H[i+3];
257 m_coeffs.push_back(coeff);
258 }
259
260 }
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:67
size_t bit_size_to_32bit_size(size_t bit_size)
uint16_t gf2m
Definition: gf2m_small_m.h:20

References Botan::bit_size_to_32bit_size(), Botan::ceil_log2(), Botan::BER_Decoder::decode(), 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(), and Botan::BER_Decoder::start_sequence().

◆ McEliece_PrivateKey() [3/5]

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

Definition at line 32 of file mceliece_key.cpp.

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

◆ ~McEliece_PrivateKey()

Botan::McEliece_PrivateKey::~McEliece_PrivateKey ( )
default

◆ McEliece_PrivateKey() [4/5]

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

◆ McEliece_PrivateKey() [5/5]

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

Member Function Documentation

◆ 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::Public_Key.

Definition at line 39 of file mceliece.h.

39{ return "McEliece"; }

Referenced by create_kem_decryption_op(), and Botan::McEliece_PublicKey::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 81 of file mceliece_key.cpp.

82 {
83 return AlgorithmIdentifier(get_oid(), AlgorithmIdentifier::USE_EMPTY_PARAM);
84 }
virtual OID get_oid() const
Definition: pk_keys.cpp:53

References Botan::Public_Key::get_oid(), and Botan::AlgorithmIdentifier::USE_EMPTY_PARAM.

◆ check_key()

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

Test the key values for consistency.

Parameters
rngrng to use
strongwhether to perform strong and lengthy version of the test
Returns
true if the test is passed

Reimplemented from Botan::McEliece_PublicKey.

Definition at line 163 of file mceliece_key.cpp.

164 {
165 const secure_vector<uint8_t> plaintext = this->random_plaintext_element(rng);
166
167 secure_vector<uint8_t> ciphertext;
168 secure_vector<uint8_t> errors;
169 mceliece_encrypt(ciphertext, errors, plaintext, *this, rng);
170
171 secure_vector<uint8_t> plaintext_out;
172 secure_vector<uint8_t> errors_out;
173 mceliece_decrypt(plaintext_out, errors_out, ciphertext, *this);
174
175 if(errors != errors_out || plaintext != plaintext_out)
176 return false;
177
178 return true;
179 }
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)
Definition: goppa_code.cpp:130
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:120

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

◆ create_decryption_op()

std::unique_ptr< PK_Ops::Decryption > Botan::Private_Key::create_decryption_op ( RandomNumberGenerator rng,
const std::string &  params,
const std::string &  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 decryption operation for this key/params or throw

Parameters
rnga 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, and Botan::SM2_PrivateKey.

Definition at line 114 of file pk_keys.cpp.

117 {
118 throw Lookup_Error(algo_name() + " does not support decryption");
119 }
virtual std::string algo_name() const =0

References Botan::Public_Key::algo_name().

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,
const std::string &  params,
const std::string &  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
rnga 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, and Botan::SM2_PublicKey.

Definition at line 91 of file pk_keys.cpp.

94 {
95 throw Lookup_Error(algo_name() + " does not support encryption");
96 }

References Botan::Public_Key::algo_name().

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,
const std::string &  params,
const std::string &  provider 
) const
overridevirtual

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

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

Parameters
rnga 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 385 of file mceliece_key.cpp.

388 {
389 if(provider == "base" || provider.empty())
390 return std::make_unique<MCE_KEM_Decryptor>(*this, params);
391 throw Provider_Not_Found(algo_name(), provider);
392 }
std::string algo_name() const override
Definition: mceliece.h:39

References Botan::McEliece_PublicKey::algo_name().

◆ create_kem_encryption_op()

std::unique_ptr< PK_Ops::KEM_Encryption > Botan::McEliece_PublicKey::create_kem_encryption_op ( RandomNumberGenerator rng,
const std::string &  params,
const std::string &  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
rnga 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::Public_Key.

Definition at line 375 of file mceliece_key.cpp.

378 {
379 if(provider == "base" || provider.empty())
380 return std::make_unique<MCE_KEM_Encryptor>(*this, params);
381 throw Provider_Not_Found(algo_name(), provider);
382 }

References Botan::McEliece_PublicKey::algo_name().

◆ create_key_agreement_op()

std::unique_ptr< PK_Ops::Key_Agreement > Botan::Private_Key::create_key_agreement_op ( RandomNumberGenerator rng,
const std::string &  params,
const std::string &  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 a key agreement operation for this key/params or throw

Parameters
rnga 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::Curve25519_PrivateKey, Botan::DH_PrivateKey, and Botan::ECDH_PrivateKey.

Definition at line 138 of file pk_keys.cpp.

141 {
142 throw Lookup_Error(algo_name() + " does not support key agreement");
143 }

References Botan::Public_Key::algo_name().

◆ create_signature_op()

std::unique_ptr< PK_Ops::Signature > Botan::Private_Key::create_signature_op ( RandomNumberGenerator rng,
const std::string &  params,
const std::string &  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 a signature operation for this key/params or throw

Parameters
rnga 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::XMSS_PrivateKey, Botan::TPM_PrivateKey, Botan::DSA_PrivateKey, Botan::ECDSA_PrivateKey, Botan::ECGDSA_PrivateKey, Botan::ECKCDSA_PrivateKey, Botan::Ed25519_PrivateKey, Botan::GOST_3410_PrivateKey, Botan::RSA_PrivateKey, and Botan::SM2_PrivateKey.

Definition at line 130 of file pk_keys.cpp.

133 {
134 throw Lookup_Error(algo_name() + " does not support signatures");
135 }

References Botan::Public_Key::algo_name().

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

◆ create_verification_op()

std::unique_ptr< PK_Ops::Verification > Botan::Public_Key::create_verification_op ( const std::string &  params,
const std::string &  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 a verification operation for this key/params or throw

Parameters
paramsadditional parameters
providerthe provider to use

Reimplemented in Botan::XMSS_PublicKey, Botan::DSA_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::Ed25519_PublicKey, Botan::GOST_3410_PublicKey, Botan::RSA_PublicKey, Botan::SM2_PublicKey, and Botan::XMSS_WOTS_Addressed_PublicKey.

Definition at line 107 of file pk_keys.cpp.

109 {
110 throw Lookup_Error(algo_name() + " does not support verification");
111 }

References Botan::Public_Key::algo_name().

Referenced by Botan::XMSS_WOTS_Addressed_PublicKey::create_verification_op(), and Botan::PK_Verifier::PK_Verifier().

◆ default_x509_signature_format()

virtual Signature_Format Botan::Public_Key::default_x509_signature_format ( ) const
inlinevirtualinherited

Reimplemented in Botan::GOST_3410_PublicKey.

Definition at line 125 of file pk_keys.h.

126 {
127 return (this->message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363;
128 }
virtual size_t message_parts() const
Definition: pk_keys.h:112
@ DER_SEQUENCE
Definition: pk_keys.h:23
@ IEEE_1363
Definition: pk_keys.h:23

References Botan::DER_SEQUENCE, and Botan::IEEE_1363.

Referenced by Botan::X509_Object::choose_sig_format(), and Botan::X509_Object::verify_signature().

◆ 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::Public_Key.

Definition at line 105 of file mceliece_key.cpp.

106 {
108 }
size_t mceliece_work_factor(size_t n, size_t t)

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

◆ fingerprint_private()

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

Definition at line 85 of file pk_keys.cpp.

86 {
88 }
virtual secure_vector< uint8_t > private_key_bits() const =0
std::string create_hex_fingerprint(const uint8_t bits[], size_t bits_len, const std::string &hash_name)
Definition: pk_keys.cpp:17
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22

References Botan::create_hex_fingerprint(), hash_algo, and Botan::Private_Key::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 ( const std::string &  alg = "SHA-256") const
inherited
Returns
Hash of the subject public key

Definition at line 77 of file pk_keys.cpp.

78 {
80 }
std::vector< uint8_t > subject_public_key() const
Definition: pk_keys.cpp:38

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

◆ 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 116 of file mceliece.h.

116{ return m_codimension; }

Referenced by Botan::mceliece_decrypt().

◆ get_dimension()

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

Definition at line 114 of file mceliece.h.

114{ 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.

54 {
55 return m_g[0];
56 }

Referenced by Botan::mceliece_decrypt().

◆ get_H_coeffs()

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

Definition at line 110 of file mceliece.h.

110{ return m_coeffs; }

References m_coeffs.

Referenced by Botan::mceliece_decrypt().

◆ get_Linv()

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

Definition at line 111 of file mceliece.h.

111{ 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

◆ get_oid()

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

◆ get_public_matrix()

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

Definition at line 54 of file mceliece.h.

54{ return m_public_matrix; }

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

◆ get_sqrtmod()

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

Definition at line 112 of file mceliece.h.

112{ 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 100 of file mceliece_key.cpp.

101 {
102 return m_code_length;
103 }

References Botan::McEliece_PublicKey::m_code_length.

◆ message_part_size()

virtual size_t Botan::Public_Key::message_part_size ( ) const
inlinevirtualinherited

Returns how large each of the message parts refered 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

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 123 of file pk_keys.h.

123{ return 0; }

Referenced by Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

◆ message_parts()

virtual size_t Botan::Public_Key::message_parts ( ) const
inlinevirtualinherited

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

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 112 of file pk_keys.h.

112{ return 1; }

Referenced by Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

◆ operator!=() [1/2]

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

Definition at line 124 of file mceliece.h.

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

◆ operator!=() [2/2]

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

Definition at line 57 of file mceliece.h.

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==() [1/2]

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

Definition at line 262 of file mceliece_key.cpp.

263 {
264 if(*static_cast<const McEliece_PublicKey*>(this) != *static_cast<const McEliece_PublicKey*>(&other))
265 {
266 return false;
267 }
268 if(m_g != other.m_g)
269 {
270 return false;
271 }
272
273 if( m_sqrtmod != other.m_sqrtmod)
274 {
275 return false;
276 }
277 if( m_Linv != other.m_Linv)
278 {
279 return false;
280 }
281 if( m_coeffs != other.m_coeffs)
282 {
283 return false;
284 }
285
286 if(m_codimension != other.m_codimension || m_dimension != other.m_dimension)
287 {
288 return false;
289 }
290
291 return true;
292 }

◆ operator==() [2/2]

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

Definition at line 300 of file mceliece_key.cpp.

301 {
302 if(m_public_matrix != other.m_public_matrix)
303 {
304 return false;
305 }
306 if(m_t != other.m_t)
307 {
308 return false;
309 }
310 if( m_code_length != other.m_code_length)
311 {
312 return false;
313 }
314 return true;
315 }

References Botan::McEliece_PublicKey::m_code_length, Botan::McEliece_PublicKey::m_public_matrix, and Botan::McEliece_PublicKey::m_t.

◆ 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, Botan::XMSS_WOTS_PrivateKey, and Botan::XMSS_WOTS_Addressed_PrivateKey.

Definition at line 212 of file pk_keys.h.

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

Referenced by Botan::Private_Key::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 126 of file mceliece_key.cpp.

127 {
128 DER_Encoder enc;
129 enc.start_sequence()
130 .start_sequence()
131 .encode(static_cast<size_t>(get_code_length()))
132 .encode(static_cast<size_t>(get_t()))
133 .end_cons()
135 .encode(m_g[0].encode(), ASN1_Type::OctetString); // g as octet string
136 enc.start_sequence();
137 for(size_t i = 0; i < m_sqrtmod.size(); i++)
138 {
139 enc.encode(m_sqrtmod[i].encode(), ASN1_Type::OctetString);
140 }
141 enc.end_cons();
142 secure_vector<uint8_t> enc_support;
143
144 for(uint16_t Linv : m_Linv)
145 {
146 enc_support.push_back(get_byte<0>(Linv));
147 enc_support.push_back(get_byte<1>(Linv));
148 }
149 enc.encode(enc_support, ASN1_Type::OctetString);
150 secure_vector<uint8_t> enc_H;
151 for(uint32_t coef : m_coeffs)
152 {
153 enc_H.push_back(get_byte<0>(coef));
154 enc_H.push_back(get_byte<1>(coef));
155 enc_H.push_back(get_byte<2>(coef));
156 enc_H.push_back(get_byte<3>(coef));
157 }
158 enc.encode(enc_H, ASN1_Type::OctetString);
159 enc.end_cons();
160 return enc.get_contents();
161 }
size_t get_t() const
Definition: mceliece.h:51
size_t get_code_length() const
Definition: mceliece.h:52
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:41

References Botan::DER_Encoder::encode(), Botan::PEM_Code::encode(), Botan::DER_Encoder::end_cons(), 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 61 of file pk_keys.cpp.

62 {
63 const size_t PKCS8_VERSION = 0;
64
65 return DER_Encoder()
66 .start_sequence()
67 .encode(PKCS8_VERSION)
70 .end_cons()
71 .get_contents();
72 }
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:212

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::OctetString, Botan::Private_Key::pkcs8_algorithm_identifier(), Botan::Private_Key::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(), and Botan::PKCS8::PEM_encode().

◆ 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 294 of file mceliece_key.cpp.

295 {
296 return std::make_unique<McEliece_PublicKey>(
298 }
const std::vector< uint8_t > & get_public_matrix() const
Definition: mceliece.h:54

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 86 of file mceliece_key.cpp.

87 {
88 std::vector<uint8_t> output;
89 DER_Encoder(output)
90 .start_sequence()
91 .start_sequence()
92 .encode(static_cast<size_t>(get_code_length()))
93 .encode(static_cast<size_t>(get_t()))
94 .end_cons()
96 .end_cons();
97 return output;
98 }

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::McEliece_PublicKey::get_code_length(), Botan::McEliece_PublicKey::get_t(), Botan::McEliece_PublicKey::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 64 of file mceliece_key.cpp.

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

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

Referenced by check_key().

◆ stateful_operation()

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

Reimplemented in Botan::XMSS_PrivateKey.

Definition at line 188 of file pk_keys.h.

188{ 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 38 of file pk_keys.cpp.

39 {
40 std::vector<uint8_t> output;
41
42 DER_Encoder(output).start_sequence()
43 .encode(algorithm_identifier())
45 .end_cons();
46
47 return output;
48 }
virtual std::vector< uint8_t > public_key_bits() const =0

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

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

Member Data Documentation

◆ m_code_length

size_t Botan::McEliece_PublicKey::m_code_length
protectedinherited

◆ m_public_matrix

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

◆ m_t

size_t Botan::McEliece_PublicKey::m_t
protectedinherited

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