Botan 2.1.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 Reference

`#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
size_t | estimated_strength () const override
std::string | fingerprint (const std::string &alg="SHA") const
uint32_t | get_code_length () const
uint32_t | get_codimension () const
uint32_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
uint32_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
uint32_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
std::vector< uint8_t > | subject_public_key () const

## Protected Attributes
uint32_t | m_code_length
std::vector< uint8_t > | m_public_matrix
uint32_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 38 of file mceliece_key.cpp.

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

39 {
40 uint32_t ext_deg = ceil_log2(code_length);
41 *this = generate_mceliece_key(rng, ext_deg, code_length, t);
42 }
Botan::generate_mceliece_key
McEliece_PrivateKey generate_mceliece_key(RandomNumberGenerator &rng, uint32_t ext_deg, uint32_t code_length, uint32_t t)
Definition: code_based_key_gen.cpp:208
Botan::ceil_log2
size_t ceil_log2(T x)
Definition: bit_ops.h:106
code_length
uint32_t code_length
Definition: gf2m_rootfind_dcmp.cpp:48

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

Definition at line 165 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().

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

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

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

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

References Botan::Public_Key::get_oid().

68 {
69 return AlgorithmIdentifier(get_oid(), std::vector<uint8_t>());
70 }
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:30

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

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

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

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, and Botan::ElGamal_PrivateKey.

Definition at line 102 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

105 {
106 throw Lookup_Error(algo_name() + " does not support decryption");
107 }
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, and Botan::ElGamal_PublicKey.

Definition at line 79 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

82 {
83 throw Lookup_Error(algo_name() + " does not support encryption");
84 }
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 363 of file mceliece_key.cpp.

References Botan::McEliece_PublicKey::algo_name().

366 {
367 if(provider == "base" || provider.empty())
368 return std::unique_ptr<PK_Ops::KEM_Decryption>(new MCE_KEM_Decryptor(*this, params));
369 throw Provider_Not_Found(algo_name(), provider);
370 }
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 353 of file mceliece_key.cpp.

References Botan::McEliece_PublicKey::algo_name().

356 {
357 if(provider == "base" || provider.empty())
358 return std::unique_ptr<PK_Ops::KEM_Encryption>(new MCE_KEM_Encryptor(*this, params));
359 throw Provider_Not_Found(algo_name(), provider);
360 }
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 126 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

129 {
130 throw Lookup_Error(algo_name() + " does not support key agreement");
131 }
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_WOTS_PrivateKey, Botan::XMSS_PrivateKey, Botan::TPM_PrivateKey, Botan::RSA_PrivateKey, Botan::GOST_3410_PrivateKey, Botan::ECDSA_PrivateKey, Botan::ECGDSA_PrivateKey, Botan::ECKCDSA_PrivateKey, and Botan::DSA_PrivateKey.

Definition at line 118 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

121 {
122 throw Lookup_Error(algo_name() + " does not support signatures");
123 }
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_WOTS_PublicKey, Botan::XMSS_PublicKey, Botan::RSA_PublicKey, Botan::XMSS_WOTS_Addressed_PublicKey, Botan::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, and Botan::DSA_PublicKey.

Definition at line 95 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

97 {
98 throw Lookup_Error(algo_name() + " does not support verification");
99 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

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

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

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

std::string Botan::Private_Key::fingerprint | ( | const std::string & | alg = `"SHA"` | ) | const
| inherited

Returns
  Hash of the PKCS #8 encoding for this key object

Definition at line 57 of file pk_keys.cpp.

References Botan::HashFunction::create(), hash, Botan::hex_encode(), 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().

58 {
59 secure_vector<uint8_t> buf = private_key_bits();
60 std::unique_ptr<HashFunction> hash(HashFunction::create(alg));
61 hash->update(buf);
62 const auto hex_print = hex_encode(hash->final());
63
64 std::string formatted_print;
65
66 for(size_t i = 0; i != hex_print.size(); i += 2)
67 {
68 formatted_print.push_back(hex_print[i]);
69 formatted_print.push_back(hex_print[i+1]);
70
71 if(i != hex_print.size() - 2)
72 formatted_print.push_back(':');
73 }
74
75 return formatted_print;
76 }
Botan::Private_Key::private_key_bits
virtual secure_vector< uint8_t > private_key_bits() const =0
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

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

Definition at line 50 of file mceliece.h.

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
uint32_t m_code_length
Definition: mceliece.h:67

uint32_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; }

uint32_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.

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; }

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

Definition at line 44 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().

45 {
46 uint32_t codimension = ceil_log2(m_code_length) * m_t;
47 return m_code_length - codimension;
48 }
Botan::McEliece_PublicKey::m_code_length
uint32_t m_code_length
Definition: mceliece.h:67
Botan::McEliece_PublicKey::m_t
uint32_t m_t
Definition: mceliece.h:66
Botan::ceil_log2
size_t ceil_log2(T x)
Definition: bit_ops.h:106

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 30 of file pk_keys.cpp.

References Botan::Public_Key::algo_name(), and Botan::OIDS::lookup().

Referenced by Botan::DL_Scheme_PublicKey::algorithm_identifier(), Botan::Curve25519_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().

31 {
32 try {
33 return OIDS::lookup(algo_name());
34 }
35 catch(Lookup_Error&)
36 {
37 throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
38 }
39 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18

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; }

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

References Botan::McEliece_PublicKey::m_code_length.

86 {
87 return m_code_length;
88 }
Botan::McEliece_PublicKey::m_code_length
uint32_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::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, and Botan::DSA_PublicKey.

Definition at line 114 of file pk_keys.h.

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

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

Definition at line 103 of file pk_keys.h.

Referenced by Botan::X509_Object::check_signature(), Botan::choose_sig_format(), Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

103 { 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 278 of file mceliece_key.cpp.

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

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

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

Definition at line 246 of file mceliece_key.cpp.

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

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

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

189 { 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 111 of file mceliece_key.cpp.

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

112 {
113 DER_Encoder enc;
114 enc.start_cons(SEQUENCE)
115 .start_cons(SEQUENCE)
116 .encode(static_cast<size_t>(get_code_length()))
117 .encode(static_cast<size_t>(get_t()))
118 .end_cons()
119 .encode(m_public_matrix, OCTET_STRING)
120 .encode(m_g.encode(), OCTET_STRING); // g as octet string
121 enc.start_cons(SEQUENCE);
122 for(uint32_t i = 0; i < m_sqrtmod.size(); i++)
123 {
124 enc.encode(m_sqrtmod[i].encode(), OCTET_STRING);
125 }
126 enc.end_cons();
127 secure_vector<uint8_t> enc_support;
128 for(uint32_t i = 0; i < m_Linv.size(); i++)
129 {
130 enc_support.push_back(m_Linv[i] >> 8);
131 enc_support.push_back(m_Linv[i]);
132 }
133 enc.encode(enc_support, OCTET_STRING);
134 secure_vector<uint8_t> enc_H;
135 for(uint32_t i = 0; i < m_coeffs.size(); i++)
136 {
137 enc_H.push_back(m_coeffs[i] >> 24);
138 enc_H.push_back(m_coeffs[i] >> 16);
139 enc_H.push_back(m_coeffs[i] >> 8);
140 enc_H.push_back(m_coeffs[i]);
141 }
142 enc.encode(enc_H, OCTET_STRING);
143 enc.end_cons();
144 return enc.get_contents();
145 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::get_t
uint32_t get_t() const
Definition: mceliece.h:49
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_code_length
uint32_t get_code_length() const
Definition: mceliece.h:50
Botan::polyn_gf2m::encode
secure_vector< uint8_t > encode() const
Definition: polyn_gf2m.cpp:771
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::SEQUENCE
Definition: asn1_obj.h:39

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 41 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().

42 {
43 const size_t PKCS8_VERSION = 0;
44
45 return DER_Encoder()
46 .start_cons(SEQUENCE)
47 .encode(PKCS8_VERSION)
48 .encode(pkcs8_algorithm_identifier())
49 .encode(private_key_bits(), OCTET_STRING)
50 .end_cons()
51 .get_contents();
52 }
Botan::Private_Key::private_key_bits
virtual secure_vector< uint8_t > private_key_bits() const =0
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::Private_Key::pkcs8_algorithm_identifier
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:188
Botan::SEQUENCE
Definition: asn1_obj.h:39

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

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::McEliece_PublicKey::get_code_length(), Botan::DER_Encoder::get_contents_unlocked(), Botan::McEliece_PublicKey::get_t(), Botan::McEliece_PublicKey::m_public_matrix, Botan::OCTET_STRING, Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

73 {
74 return DER_Encoder()
75 .start_cons(SEQUENCE)
76 .start_cons(SEQUENCE)
77 .encode(static_cast<size_t>(get_code_length()))
78 .encode(static_cast<size_t>(get_t()))
79 .end_cons()
80 .encode(m_public_matrix, OCTET_STRING)
81 .end_cons()
82 .get_contents_unlocked();
83 }
Botan::McEliece_PublicKey::m_public_matrix
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::get_t
uint32_t get_t() const
Definition: mceliece.h:49
Botan::McEliece_PublicKey::get_code_length
uint32_t get_code_length() const
Definition: mceliece.h:50
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::SEQUENCE
Definition: asn1_obj.h:39

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

Definition at line 50 of file mceliece_key.cpp.

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

Referenced by check_key().

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

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 17 of file pk_keys.cpp.

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

Referenced by Botan::X509::BER_encode(), and Botan::X509::PEM_encode().

18 {
19 return DER_Encoder()
20 .start_cons(SEQUENCE)
21 .encode(algorithm_identifier())
22 .encode(public_key_bits(), BIT_STRING)
23 .end_cons()
24 .get_contents_unlocked();
25 }
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:39
Botan::BIT_STRING
Definition: asn1_obj.h:34

## Member Data Documentation

uint32_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().

uint32_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