Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Attributes | List of all members
Botan::McEliece_PrivateKey Class Referencefinal

`#include <mceliece.h>`

Inheritance diagram for Botan::McEliece_PrivateKey:

## 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::Decryption > | create_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Encryption > | create_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
std::unique_ptr< PK_Ops::KEM_Decryption > | create_kem_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
std::unique_ptr< PK_Ops::KEM_Encryption > | create_kem_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
virtual std::unique_ptr< PK_Ops::Key_Agreement > | create_key_agreement_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Signature > | create_signature_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Verification > | create_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 (const std::string &alg) const
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 (RandomNumberGenerator &rng, size_t code_length, size_t t)
| McEliece_PrivateKey (const secure_vector< uint8_t > &key_bits)
| 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)
virtual size_t | message_part_size () const
virtual size_t | message_parts () const
bool | operator!= (const McEliece_PublicKey &other) const
bool | operator!= (const McEliece_PrivateKey &other) const
bool | operator== (const McEliece_PublicKey &other) const
bool | operator== (const McEliece_PrivateKey &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::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

## Protected Attributes
size_t | m_code_length
std::vector< uint8_t > | m_public_matrix
size_t | m_t

## Detailed Description

Definition at line 70 of file mceliece.h.

## Constructor & Destructor Documentation

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

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

41 {
42 uint32_t ext_deg = ceil_log2(code_length);
43 *this = generate_mceliece_key(rng, ext_deg, code_length, t);
44 }
Botan::ceil_log2
uint8_t ceil_log2(T x)
Definition: bit_ops.h:119
Botan::generate_mceliece_key
McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator &rng, size_t ext_deg, size_t code_length, size_t t)
Definition: code_based_key_gen.cpp:215

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

Definition at line 169 of file mceliece_key.cpp.

References Botan::bit_size_to_32bit_size(), Botan::ceil_log2(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::polyn_gf2m::get_degree(), Botan::McEliece_PublicKey::m_code_length, Botan::McEliece_PublicKey::m_public_matrix, Botan::McEliece_PublicKey::m_t, Botan::OCTET_STRING, Botan::BER_Decoder::push_back(), Botan::SEQUENCE, and Botan::BER_Decoder::start_cons().

170 {
171 size_t n, t;
172 secure_vector<uint8_t> enc_g;
173 BER_Decoder dec_base(key_bits);
174 BER_Decoder dec = dec_base.start_cons(SEQUENCE)
175 .start_cons(SEQUENCE)
176 .decode(n)
177 .decode(t)
178 .end_cons()
179 .decode(m_public_matrix, OCTET_STRING)
180 .decode(enc_g, OCTET_STRING);
181
182 if(t == 0 || n == 0)
183 throw Decoding_Error("invalid McEliece parameters");
184
185 uint32_t ext_deg = ceil_log2(n);
186 m_code_length = n;
187 m_t = t;
188 m_codimension = (ext_deg * t);
189 m_dimension = (n - m_codimension);
190
191 std::shared_ptr<GF2m_Field> sp_field(new GF2m_Field(ext_deg));
192 m_g = polyn_gf2m(enc_g, sp_field);
193 if(m_g.get_degree() != static_cast<int>(t))
194 {
195 throw Decoding_Error("degree of decoded Goppa polynomial is incorrect");
196 }
197 BER_Decoder dec2 = dec.start_cons(SEQUENCE);
198 for(uint32_t i = 0; i < t/2; i++)
199 {
200 secure_vector<uint8_t> sqrt_enc;
201 dec2.decode(sqrt_enc, OCTET_STRING);
202 while(sqrt_enc.size() < (t*2))
203 {
204 // ensure that the length is always t
205 sqrt_enc.push_back(0);
206 sqrt_enc.push_back(0);
207 }
208 if(sqrt_enc.size() != t*2)
209 {
210 throw Decoding_Error("length of square root polynomial entry is too large");
211 }
212 m_sqrtmod.push_back(polyn_gf2m(sqrt_enc, sp_field));
213 }
214 secure_vector<uint8_t> enc_support;
215 BER_Decoder dec3 = dec2.end_cons()
216 .decode(enc_support, OCTET_STRING);
217 if(enc_support.size() % 2)
218 {
219 throw Decoding_Error("encoded support has odd length");
220 }
221 if(enc_support.size() / 2 != n)
222 {
223 throw Decoding_Error("encoded support has length different from code length");
224 }
225 for(uint32_t i = 0; i < n*2; i+=2)
226 {
227 gf2m el = (enc_support[i] << 8) | enc_support[i+1];
228 m_Linv.push_back(el);
229 }
230 secure_vector<uint8_t> enc_H;
231 dec3.decode(enc_H, OCTET_STRING)
232 .end_cons();
233 if(enc_H.size() % 4)
234 {
235 throw Decoding_Error("encoded parity check matrix has length which is not a multiple of four");
236 }
237 if(enc_H.size() / 4 != bit_size_to_32bit_size(m_codimension) * m_code_length)
238 {
239 throw Decoding_Error("encoded parity check matrix has wrong length");
240 }
241
242 for(uint32_t i = 0; i < enc_H.size(); i+=4)
243 {
244 uint32_t coeff = (enc_H[i] << 24) | (enc_H[i+1] << 16) | (enc_H[i+2] << 8) | enc_H[i+3];
245 m_coeffs.push_back(coeff);
246 }
247
248 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::bit_size_to_32bit_size
size_t bit_size_to_32bit_size(size_t bit_size)
Definition: code_based_util.h:50
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::polyn_gf2m::get_degree
int get_degree() const
Definition: polyn_gf2m.cpp:228
Botan::gf2m
uint16_t gf2m
Definition: gf2m_small_m.h:23
Botan::OCTET_STRING
Definition: asn1_obj.h:36
Botan::McEliece_PublicKey::m_t
size_t m_t
Definition: mceliece.h:66
Botan::ceil_log2
uint8_t ceil_log2(T x)
Definition: bit_ops.h:119

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

29 :
30 McEliece_PublicKey(public_matrix, goppa_polyn.get_degree(), inverse_support.size()),
31 m_g(goppa_polyn),
32 m_sqrtmod(square_root_matrix),
33 m_Linv(inverse_support),
34 m_coeffs(parity_check_matrix_coeffs),
35 m_codimension(static_cast<size_t>(ceil_log2(inverse_support.size())) * goppa_polyn.get_degree()),
36 m_dimension(inverse_support.size() - m_codimension)
37 {
38 }
Botan::McEliece_PublicKey::McEliece_PublicKey
McEliece_PublicKey()
Definition: mceliece.h:63
Botan::ceil_log2
uint8_t ceil_log2(T x)
Definition: bit_ops.h:119

## Member Function Documentation

std::string Botan::McEliece_PublicKey::algo_name | ( |  | ) | const
| inline override virtual inherited

Get the name of the underlying public key scheme.

Returns
  name of the public key scheme

Implements Botan::Public_Key.

Definition at line 37 of file mceliece.h.

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

37 { return "McEliece"; }

AlgorithmIdentifier Botan::McEliece_PublicKey::algorithm_identifier | ( |  | ) | const
| override virtual inherited

Returns
  X.509 AlgorithmIdentifier for this key

Implements Botan::Public_Key.

Definition at line 69 of file mceliece_key.cpp.

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

70 {
71 return AlgorithmIdentifier(get_oid(), AlgorithmIdentifier::USE_EMPTY_PARAM);
72 }
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:53
Botan::AlgorithmIdentifier::USE_EMPTY_PARAM
Definition: alg_id.h:24

bool Botan::McEliece_PrivateKey::check_key | ( | RandomNumberGenerator & | rng,
|  | bool | strong
| ) |  | const
| override virtual

Test the key values for consistency.

Parameters

  rng | rng to use
  strong | whether to perform strong and lengthy version of the test

Returns
  true if the test is passed

Reimplemented from Botan::McEliece_PublicKey.

Definition at line 151 of file mceliece_key.cpp.

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

152 {
153 const secure_vector<uint8_t> plaintext = this->random_plaintext_element(rng);
154
155 secure_vector<uint8_t> ciphertext;
156 secure_vector<uint8_t> errors;
157 mceliece_encrypt(ciphertext, errors, plaintext, *this, rng);
158
159 secure_vector<uint8_t> plaintext_out;
160 secure_vector<uint8_t> errors_out;
161 mceliece_decrypt(plaintext_out, errors_out, ciphertext, *this);
162
163 if(errors != errors_out || plaintext != plaintext_out)
164 return false;
165
166 return true;
167 }
Botan::McEliece_PublicKey::random_plaintext_element
secure_vector< uint8_t > random_plaintext_element(RandomNumberGenerator &rng) const
Definition: mceliece_key.cpp:52
Botan::mceliece_decrypt
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
Botan::mceliece_encrypt
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

std::unique_ptr< PK_Ops::Decryption > Botan::Private_Key::create_decryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

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

Definition at line 114 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

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

std::unique_ptr< PK_Ops::Encryption > Botan::Public_Key::create_encryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

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

Definition at line 91 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

94 {
95 throw Lookup_Error(algo_name() + " does not support encryption");
96 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

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
| override virtual

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

Reimplemented from Botan::Private_Key.

Definition at line 367 of file mceliece_key.cpp.

References Botan::McEliece_PublicKey::algo_name().

370 {
371 if(provider == "base" || provider.empty())
372 return std::unique_ptr<PK_Ops::KEM_Decryption>(new MCE_KEM_Decryptor(*this, params));
373 throw Provider_Not_Found(algo_name(), provider);
374 }
Botan::McEliece_PublicKey::algo_name
std::string algo_name() const override
Definition: mceliece.h:37

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
| override virtual inherited

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

Reimplemented from Botan::Public_Key.

Definition at line 357 of file mceliece_key.cpp.

References Botan::McEliece_PublicKey::algo_name().

360 {
361 if(provider == "base" || provider.empty())
362 return std::unique_ptr<PK_Ops::KEM_Encryption>(new MCE_KEM_Encryptor(*this, params));
363 throw Provider_Not_Found(algo_name(), provider);
364 }
Botan::McEliece_PublicKey::algo_name
std::string algo_name() const override
Definition: mceliece.h:37

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
| virtual inherited

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::ECDH_PrivateKey, Botan::Curve25519_PrivateKey, and Botan::DH_PrivateKey.

Definition at line 138 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

141 {
142 throw Lookup_Error(algo_name() + " does not support key agreement");
143 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::Signature > Botan::Private_Key::create_signature_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

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

  rng | a 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.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::XMSS_PrivateKey, Botan::TPM_PrivateKey, Botan::RSA_PrivateKey, Botan::ECDSA_PrivateKey, Botan::GOST_3410_PrivateKey, Botan::SM2_PrivateKey, Botan::ECGDSA_PrivateKey, Botan::ECKCDSA_PrivateKey, Botan::Ed25519_PrivateKey, and Botan::DSA_PrivateKey.

Definition at line 130 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

133 {
134 throw Lookup_Error(algo_name() + " does not support signatures");
135 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::Verification > Botan::Public_Key::create_verification_op | ( | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

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

  params | additional parameters
  provider | the provider to use

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

Definition at line 107 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

109 {
110 throw Lookup_Error(algo_name() + " does not support verification");
111 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

virtual Signature_Format Botan::Public_Key::default_x509_signature_format | ( |  | ) | const
| inline virtual inherited

Reimplemented in Botan::GOST_3410_PublicKey.

Definition at line 126 of file pk_keys.h.

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

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

127 {
128 return (this->message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363;
129 }
Botan::Public_Key::message_parts
virtual size_t message_parts() const
Definition: pk_keys.h:113
Botan::IEEE_1363
Definition: pk_keys.h:24
Botan::DER_SEQUENCE
Definition: pk_keys.h:24

size_t Botan::McEliece_PublicKey::estimated_strength | ( |  | ) | const
| override virtual inherited

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

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

94 {
95 return mceliece_work_factor(m_code_length, m_t);
96 }
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67
Botan::mceliece_work_factor
size_t mceliece_work_factor(size_t n, size_t t)
Definition: mce_workfactor.cpp:95
Botan::McEliece_PublicKey::m_t
size_t m_t
Definition: mceliece.h:66

std::string Botan::Private_Key::fingerprint | ( | const std::string & | alg | ) | const
| inline inherited

Definition at line 216 of file pk_keys.h.

217 {
218 return fingerprint_private(alg); // match behavior in previous versions
219 }
Botan::Private_Key::fingerprint_private
std::string fingerprint_private(const std::string &alg) const
Definition: pk_keys.cpp:85

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.

References Botan::create_hex_fingerprint(), 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().

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

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.

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

78 {
79 return create_hex_fingerprint(subject_public_key(), hash_algo);
80 }
hash_algo
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
Botan::create_hex_fingerprint
std::string create_hex_fingerprint(const uint8_t bits[], size_t bits_len, const std::string &hash_name)
Definition: pk_keys.cpp:17
Botan::Public_Key::subject_public_key
std::vector< uint8_t > subject_public_key() const
Definition: pk_keys.cpp:38

size_t Botan::McEliece_PublicKey::get_code_length | ( |  | ) | const
| inline inherited

Definition at line 50 of file mceliece.h.

References m_code_length.

Referenced by Botan::mceies_decrypt(), Botan::mceies_encrypt(), Botan::mceliece_decrypt(), Botan::mceliece_encrypt(), private_key_bits(), and Botan::McEliece_PublicKey::public_key_bits().

50 { return m_code_length; }
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67

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

Definition at line 106 of file mceliece.h.

Referenced by Botan::mceliece_decrypt().

106 { return m_codimension; }

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

Definition at line 104 of file mceliece.h.

Referenced by Botan::mceliece_decrypt().

104 { return m_dimension; }

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

Definition at line 99 of file mceliece.h.

References m_g.

Referenced by Botan::mceliece_decrypt().

99 { return m_g; }

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

Definition at line 100 of file mceliece.h.

Referenced by Botan::mceliece_decrypt().

100 { return m_coeffs; }

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

Definition at line 101 of file mceliece.h.

Referenced by Botan::mceliece_decrypt().

101 { return m_Linv; }

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

Definition at line 46 of file mceliece_key.cpp.

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

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

47 {
48 size_t codimension = ceil_log2(m_code_length) * m_t;
49 return m_code_length - codimension;
50 }
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67
Botan::McEliece_PublicKey::m_t
size_t m_t
Definition: mceliece.h:66
Botan::ceil_log2
uint8_t ceil_log2(T x)
Definition: bit_ops.h:119

OID Botan::Public_Key::get_oid | ( |  | ) | const
| virtual inherited

Get the OID of the underlying public key scheme.

Returns
  OID of the public key scheme

Reimplemented in Botan::XMSS_WOTS_Addressed_PublicKey.

Definition at line 53 of file pk_keys.cpp.

References Botan::Public_Key::algo_name(), Botan::OID::empty(), and Botan::OIDS::str2oid_or_empty().

Referenced by Botan::DL_Scheme_PublicKey::algorithm_identifier(), Botan::Curve25519_PublicKey::algorithm_identifier(), Botan::Ed25519_PublicKey::algorithm_identifier(), Botan::McEliece_PublicKey::algorithm_identifier(), Botan::RSA_PublicKey::algorithm_identifier(), Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::EC_PublicKey::algorithm_identifier(), Botan::TPM_PrivateKey::algorithm_identifier(), and Botan::XMSS_WOTS_Addressed_PublicKey::get_oid().

54 {
55 const OID o = OIDS::str2oid_or_empty(algo_name());
56 if(o.empty())
57 throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
58 return o;
59 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::OIDS::str2oid_or_empty
BOTAN_UNSTABLE_API OID str2oid_or_empty(const std::string &name)
Definition: oids.cpp:116

const std::vector<uint8_t>& Botan::McEliece_PublicKey::get_public_matrix | ( |  | ) | const
| inline inherited

Definition at line 52 of file mceliece.h.

Referenced by Botan::mceliece_encrypt().

52 { return m_public_matrix; }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65

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

Definition at line 102 of file mceliece.h.

Referenced by Botan::mceliece_decrypt().

102 { return m_sqrtmod; }

size_t Botan::McEliece_PublicKey::get_t | ( |  | ) | const
| inline inherited

Definition at line 49 of file mceliece.h.

Referenced by Botan::mceliece_encrypt(), private_key_bits(), and Botan::McEliece_PublicKey::public_key_bits().

49 { return m_t; }
Botan::McEliece_PublicKey::m_t
size_t m_t
Definition: mceliece.h:66

size_t Botan::McEliece_PublicKey::key_length | ( |  | ) | const
| override virtual inherited

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

References Botan::McEliece_PublicKey::m_code_length.

89 {
90 return m_code_length;
91 }
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67

virtual size_t Botan::Public_Key::message_part_size | ( |  | ) | const
| inline virtual inherited

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::ECDSA_PublicKey, Botan::GOST_3410_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::SM2_PublicKey, and Botan::DSA_PublicKey.

Definition at line 124 of file pk_keys.h.

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

124 { return 0; }

virtual size_t Botan::Public_Key::message_parts | ( |  | ) | const
| inline virtual inherited

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::ECDSA_PublicKey, Botan::GOST_3410_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, Botan::SM2_PublicKey, and Botan::DSA_PublicKey.

Definition at line 113 of file pk_keys.h.

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

113 { return 1; }

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

Definition at line 55 of file mceliece.h.

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

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

Definition at line 112 of file mceliece.h.

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

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

Definition at line 282 of file mceliece_key.cpp.

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

283 {
284 if(m_public_matrix != other.m_public_matrix)
285 {
286 return false;
287 }
288 if(m_t != other.m_t)
289 {
290 return false;
291 }
292 if( m_code_length != other.m_code_length)
293 {
294 return false;
295 }
296 return true;
297 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::m_code_length
size_t m_code_length
Definition: mceliece.h:67
Botan::McEliece_PublicKey::m_t
size_t m_t
Definition: mceliece.h:66

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

Definition at line 250 of file mceliece_key.cpp.

251 {
252 if(*static_cast<const McEliece_PublicKey*>(this) != *static_cast<const McEliece_PublicKey*>(&other))
253 {
254 return false;
255 }
256 if(m_g != other.m_g)
257 {
258 return false;
259 }
260
261 if( m_sqrtmod != other.m_sqrtmod)
262 {
263 return false;
264 }
265 if( m_Linv != other.m_Linv)
266 {
267 return false;
268 }
269 if( m_coeffs != other.m_coeffs)
270 {
271 return false;
272 }
273
274 if(m_codimension != other.m_codimension || m_dimension != other.m_dimension)
275 {
276 return false;
277 }
278
279 return true;
280 }

virtual AlgorithmIdentifier Botan::Private_Key::pkcs8_algorithm_identifier | ( |  | ) | const
| inline virtual inherited

Returns
  PKCS #8 AlgorithmIdentifier for this key Might be different from the X.509 identifier, but normally is not

Reimplemented in Botan::XMSS_WOTS_PrivateKey, Botan::GOST_3410_PrivateKey, and Botan::XMSS_WOTS_Addressed_PrivateKey.

Definition at line 205 of file pk_keys.h.

Referenced by Botan::Private_Key::private_key_info().

206 { return algorithm_identifier(); }
Botan::Public_Key::algorithm_identifier
virtual AlgorithmIdentifier algorithm_identifier() const =0

secure_vector< uint8_t > Botan::McEliece_PrivateKey::private_key_bits | ( |  | ) | const
| override virtual

Returns
  BER encoded private key bits

Implements Botan::Private_Key.

Definition at line 114 of file mceliece_key.cpp.

References Botan::PEM_Code::encode(), Botan::polyn_gf2m::encode(), 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::OCTET_STRING, Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

115 {
116 DER_Encoder enc;
117 enc.start_cons(SEQUENCE)
118 .start_cons(SEQUENCE)
119 .encode(static_cast<size_t>(get_code_length()))
120 .encode(static_cast<size_t>(get_t()))
121 .end_cons()
122 .encode(m_public_matrix, OCTET_STRING)
123 .encode(m_g.encode(), OCTET_STRING); // g as octet string
124 enc.start_cons(SEQUENCE);
125 for(size_t i = 0; i < m_sqrtmod.size(); i++)
126 {
127 enc.encode(m_sqrtmod[i].encode(), OCTET_STRING);
128 }
129 enc.end_cons();
130 secure_vector<uint8_t> enc_support;
131
132 for(uint16_t Linv : m_Linv)
133 {
134 enc_support.push_back(get_byte(0, Linv));
135 enc_support.push_back(get_byte(1, Linv));
136 }
137 enc.encode(enc_support, OCTET_STRING);
138 secure_vector<uint8_t> enc_H;
139 for(uint32_t coef : m_coeffs)
140 {
141 enc_H.push_back(get_byte(0, coef));
142 enc_H.push_back(get_byte(1, coef));
143 enc_H.push_back(get_byte(2, coef));
144 enc_H.push_back(get_byte(3, coef));
145 }
146 enc.encode(enc_H, OCTET_STRING);
147 enc.end_cons();
148 return enc.get_contents();
149 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::get_code_length
size_t get_code_length() const
Definition: mceliece.h:50
Botan::get_byte
constexpr uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:41
Botan::polyn_gf2m::encode
secure_vector< uint8_t > encode() const
Definition: polyn_gf2m.cpp:769
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::PEM_Code::encode
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
Botan::McEliece_PublicKey::get_t
size_t get_t() const
Definition: mceliece.h:49
Botan::OCTET_STRING
Definition: asn1_obj.h:36

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.

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::OCTET_STRING, Botan::Private_Key::pkcs8_algorithm_identifier(), Botan::Private_Key::private_key_bits(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

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

62 {
63 const size_t PKCS8_VERSION = 0;
64
65 return DER_Encoder()
66 .start_cons(SEQUENCE)
67 .encode(PKCS8_VERSION)
68 .encode(pkcs8_algorithm_identifier())
69 .encode(private_key_bits(), OCTET_STRING)
70 .end_cons()
71 .get_contents();
72 }
Botan::Private_Key::private_key_bits
virtual secure_vector< uint8_t > private_key_bits() const =0
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::Private_Key::pkcs8_algorithm_identifier
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:205
Botan::OCTET_STRING
Definition: asn1_obj.h:36

std::vector< uint8_t > Botan::McEliece_PublicKey::public_key_bits | ( |  | ) | const
| override virtual inherited

Returns
  BER encoded public key bits

Implements Botan::Public_Key.

Definition at line 74 of file mceliece_key.cpp.

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::OCTET_STRING, Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

75 {
76 std::vector<uint8_t> output;
77 DER_Encoder(output)
78 .start_cons(SEQUENCE)
79 .start_cons(SEQUENCE)
80 .encode(static_cast<size_t>(get_code_length()))
81 .encode(static_cast<size_t>(get_t()))
82 .end_cons()
83 .encode(m_public_matrix, OCTET_STRING)
84 .end_cons();
85 return output;
86 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::get_code_length
size_t get_code_length() const
Definition: mceliece.h:50
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::McEliece_PublicKey::get_t
size_t get_t() const
Definition: mceliece.h:49
Botan::OCTET_STRING
Definition: asn1_obj.h:36

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

Definition at line 52 of file mceliece_key.cpp.

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

Referenced by check_key().

53 {
54 const size_t bits = get_message_word_bit_length();
55
56 secure_vector<uint8_t> plaintext((bits+7)/8);
57 rng.randomize(plaintext.data(), plaintext.size());
58
59 // unset unused bits in the last plaintext byte
60 if(uint32_t used = bits % 8)
61 {
62 const uint8_t mask = (1 << used) - 1;
63 plaintext[plaintext.size() - 1] &= mask;
64 }
65
66 return plaintext;
67 }
Botan::McEliece_PublicKey::get_message_word_bit_length
size_t get_message_word_bit_length() const
Definition: mceliece_key.cpp:46

virtual bool Botan::Private_Key::stateful_operation | ( |  | ) | const
| inline virtual inherited

Reimplemented in Botan::XMSS_PrivateKey.

Definition at line 189 of file pk_keys.h.

189 { return false; }

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.

References Botan::Public_Key::algorithm_identifier(), Botan::BIT_STRING, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::Public_Key::public_key_bits(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

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

39 {
40 std::vector<uint8_t> output;
41
42 DER_Encoder(output).start_cons(SEQUENCE)
43 .encode(algorithm_identifier())
44 .encode(public_key_bits(), BIT_STRING)
45 .end_cons();
46
47 return output;
48 }
Botan::Public_Key::public_key_bits
virtual std::vector< uint8_t > public_key_bits() const =0
Botan::Public_Key::algorithm_identifier
virtual AlgorithmIdentifier algorithm_identifier() const =0
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::BIT_STRING
Definition: asn1_obj.h:35

## Member Data Documentation

size_t Botan::McEliece_PublicKey::m_code_length
| protected inherited

Definition at line 67 of file mceliece.h.

Referenced by Botan::McEliece_PublicKey::estimated_strength(), Botan::McEliece_PublicKey::get_message_word_bit_length(), Botan::McEliece_PublicKey::key_length(), McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), and Botan::McEliece_PublicKey::operator==().

std::vector<uint8_t> Botan::McEliece_PublicKey::m_public_matrix
| protected inherited

Definition at line 65 of file mceliece.h.

Referenced by McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::McEliece_PublicKey::operator==(), private_key_bits(), and Botan::McEliece_PublicKey::public_key_bits().

size_t Botan::McEliece_PublicKey::m_t
| protected inherited

Definition at line 66 of file mceliece.h.

Referenced by Botan::McEliece_PublicKey::estimated_strength(), Botan::McEliece_PublicKey::get_message_word_bit_length(), McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), and Botan::McEliece_PublicKey::operator==().

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

- src/lib/pubkey/mce/mceliece.h
- src/lib/pubkey/mce/mceliece_key.cpp