Botan  2.1.0
Crypto and TLS for C++11
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::McEliece_PublicKey Class Reference

#include <mceliece.h>

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

Public Member Functions

std::string algo_name () const override
 
AlgorithmIdentifier algorithm_identifier () const override
 
bool check_key (RandomNumberGenerator &, bool) const override
 
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_Encryptioncreate_kem_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
 
virtual std::unique_ptr< PK_Ops::Verificationcreate_verification_op (const std::string &params, const std::string &provider) const
 
size_t estimated_strength () const override
 
uint32_t get_code_length () const
 
uint32_t get_message_word_bit_length () const
 
virtual OID get_oid () const
 
const std::vector< uint8_t > & get_public_matrix () const
 
uint32_t get_t () const
 
size_t key_length () const override
 
 McEliece_PublicKey (const std::vector< uint8_t > &key_bits)
 
 McEliece_PublicKey (const std::vector< uint8_t > &pub_matrix, uint32_t the_t, uint32_t the_code_length)
 
 McEliece_PublicKey (const McEliece_PublicKey &other)=default
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
bool operator!= (const McEliece_PublicKey &other) const
 
McEliece_PublicKeyoperator= (const McEliece_PublicKey &other)=default
 
bool operator== (const McEliece_PublicKey &other) 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
 
virtual ~McEliece_PublicKey ()=default
 

Protected Member Functions

 McEliece_PublicKey ()
 

Protected Attributes

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

Detailed Description

Definition at line 21 of file mceliece.h.

Constructor & Destructor Documentation

Botan::McEliece_PublicKey::McEliece_PublicKey ( const std::vector< uint8_t > &  key_bits)
explicit

Definition at line 95 of file mceliece_key.cpp.

References Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), m_code_length, m_public_matrix, m_t, Botan::OCTET_STRING, Botan::SEQUENCE, and Botan::BER_Decoder::start_cons().

96  {
97  BER_Decoder dec(key_bits);
98  size_t n;
99  size_t t;
100  dec.start_cons(SEQUENCE)
101  .start_cons(SEQUENCE)
102  .decode(n)
103  .decode(t)
104  .end_cons()
105  .decode(m_public_matrix, OCTET_STRING)
106  .end_cons();
107  m_t = t;
108  m_code_length = n;
109  }
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::McEliece_PublicKey ( const std::vector< uint8_t > &  pub_matrix,
uint32_t  the_t,
uint32_t  the_code_length 
)
inline

Definition at line 26 of file mceliece.h.

26  :
27  m_public_matrix(pub_matrix),
28  m_t(the_t),
29  m_code_length(the_code_length){}
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
Botan::McEliece_PublicKey::McEliece_PublicKey ( const McEliece_PublicKey other)
default
virtual Botan::McEliece_PublicKey::~McEliece_PublicKey ( )
virtualdefault
Botan::McEliece_PublicKey::McEliece_PublicKey ( )
inlineprotected

Definition at line 63 of file mceliece.h.

63 : m_t(0), m_code_length(0) {}

Member Function Documentation

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

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 Botan::McEliece_PrivateKey::create_kem_decryption_op(), and create_kem_encryption_op().

37 { return "McEliece"; }
AlgorithmIdentifier Botan::McEliece_PublicKey::algorithm_identifier ( ) const
overridevirtual
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  }
virtual OID get_oid() const
Definition: pk_keys.cpp:30
bool Botan::McEliece_PublicKey::check_key ( RandomNumberGenerator rng,
bool  strong 
) const
inlineoverridevirtual

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

Implements Botan::Public_Key.

Reimplemented in Botan::McEliece_PrivateKey.

Definition at line 46 of file mceliece.h.

47  { return true; }
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::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  }
virtual std::string algo_name() const =0
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
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 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 353 of file mceliece_key.cpp.

References 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  }
std::string algo_name() const override
Definition: mceliece.h:37
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_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  }
virtual std::string algo_name() const =0
size_t Botan::McEliece_PublicKey::estimated_strength ( ) const
overridevirtual

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 m_code_length, m_t, and Botan::mceliece_work_factor().

91  {
93  }
size_t mceliece_work_factor(size_t n, size_t t)
uint32_t Botan::McEliece_PublicKey::get_code_length ( ) const
inline
uint32_t Botan::McEliece_PublicKey::get_message_word_bit_length ( ) const

Definition at line 44 of file mceliece_key.cpp.

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

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

45  {
46  uint32_t codimension = ceil_log2(m_code_length) * m_t;
47  return m_code_length - codimension;
48  }
size_t ceil_log2(T x)
Definition: bit_ops.h:106
OID Botan::Public_Key::get_oid ( ) const
virtualinherited

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(), 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  }
virtual std::string algo_name() const =0
std::string lookup(const OID &oid)
Definition: oids.cpp:18
const std::vector<uint8_t>& Botan::McEliece_PublicKey::get_public_matrix ( ) const
inline

Definition at line 52 of file mceliece.h.

Referenced by Botan::mceliece_encrypt().

52 { return m_public_matrix; }
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
uint32_t Botan::McEliece_PublicKey::get_t ( ) const
inline
size_t Botan::McEliece_PublicKey::key_length ( ) const
overridevirtual

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

86  {
87  return m_code_length;
88  }
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::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
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::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

Definition at line 55 of file mceliece.h.

55 { return !(*this == other); }
McEliece_PublicKey& Botan::McEliece_PublicKey::operator= ( const McEliece_PublicKey other)
default
bool Botan::McEliece_PublicKey::operator== ( const McEliece_PublicKey other) const

Definition at line 278 of file mceliece_key.cpp.

References m_code_length, m_public_matrix, and 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  }
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
std::vector< uint8_t > Botan::McEliece_PublicKey::public_key_bits ( ) const
overridevirtual
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(), get_code_length(), Botan::DER_Encoder::get_contents_unlocked(), get_t(), 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()
81  .end_cons()
82  .get_contents_unlocked();
83  }
std::vector< uint8_t > m_public_matrix
Definition: mceliece.h:65
uint32_t get_t() const
Definition: mceliece.h:49
uint32_t get_code_length() const
Definition: mceliece.h:50
secure_vector< uint8_t > Botan::McEliece_PublicKey::random_plaintext_element ( RandomNumberGenerator rng) const

Definition at line 50 of file mceliece_key.cpp.

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

Referenced by Botan::McEliece_PrivateKey::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  }
uint32_t get_message_word_bit_length() const
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  }
virtual std::vector< uint8_t > public_key_bits() const =0
virtual AlgorithmIdentifier algorithm_identifier() const =0

Member Data Documentation

uint32_t Botan::McEliece_PublicKey::m_code_length
protected
std::vector<uint8_t> Botan::McEliece_PublicKey::m_public_matrix
protected
uint32_t Botan::McEliece_PublicKey::m_t
protected

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