Botan  2.4.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
 
std::string fingerprint_public (const std::string &alg="SHA-256") const
 
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

◆ McEliece_PublicKey() [1/4]

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

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

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

◆ McEliece_PublicKey() [2/4]

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

◆ McEliece_PublicKey() [3/4]

Botan::McEliece_PublicKey::McEliece_PublicKey ( const McEliece_PublicKey other)
default

◆ ~McEliece_PublicKey()

virtual Botan::McEliece_PublicKey::~McEliece_PublicKey ( )
virtualdefault

◆ McEliece_PublicKey() [4/4]

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

◆ algo_name()

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

◆ algorithm_identifier()

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

Implements Botan::Public_Key.

Definition at line 68 of file mceliece_key.cpp.

References Botan::Public_Key::get_oid().

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

◆ check_key()

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

◆ create_encryption_op()

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

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

Return an encryption operation for this key/params or throw

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

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

Definition at line 92 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

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

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

◆ create_kem_encryption_op()

std::unique_ptr< PK_Ops::KEM_Encryption > Botan::McEliece_PublicKey::create_kem_encryption_op ( RandomNumberGenerator rng,
const std::string &  params,
const std::string &  provider 
) const
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 354 of file mceliece_key.cpp.

References algo_name().

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

◆ create_verification_op()

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

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

Return a verification operation for this key/params or throw

Parameters
paramsadditional parameters
providerthe provider to use

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

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

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

◆ estimated_strength()

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

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

92  {
94  }
size_t mceliece_work_factor(size_t n, size_t t)

◆ fingerprint_public()

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

Definition at line 78 of file pk_keys.cpp.

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

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

◆ get_code_length()

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

◆ get_message_word_bit_length()

uint32_t Botan::McEliece_PublicKey::get_message_word_bit_length ( ) const

Definition at line 45 of file mceliece_key.cpp.

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

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

46  {
47  uint32_t codimension = ceil_log2(m_code_length) * m_t;
48  return m_code_length - codimension;
49  }
size_t ceil_log2(T x)
Definition: bit_ops.h:117

◆ get_oid()

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 51 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::Ed25519_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(), Botan::EC_PublicKey::EC_PublicKey(), and Botan::XMSS_WOTS_Addressed_PublicKey::get_oid().

52  {
53  try {
54  return OIDS::lookup(algo_name());
55  }
56  catch(Lookup_Error&)
57  {
58  throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
59  }
60  }
virtual std::string algo_name() const =0
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ get_public_matrix()

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

Definition at line 52 of file mceliece.h.

References Botan::operator==().

Referenced by Botan::mceliece_encrypt().

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

◆ get_t()

uint32_t Botan::McEliece_PublicKey::get_t ( ) const
inline

◆ key_length()

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

References m_code_length.

87  {
88  return m_code_length;
89  }

◆ message_part_size()

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

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

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

Returns
size of the message parts in bits

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

Definition at line 118 of file pk_keys.h.

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

118 { return 0; }

◆ message_parts()

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

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

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

Returns
number of message parts

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

Definition at line 107 of file pk_keys.h.

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

107 { return 1; }

◆ operator!=()

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

Definition at line 55 of file mceliece.h.

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

◆ operator=()

McEliece_PublicKey& Botan::McEliece_PublicKey::operator= ( const McEliece_PublicKey other)
default

◆ operator==()

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

Definition at line 279 of file mceliece_key.cpp.

References m_code_length, m_public_matrix, and m_t.

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

◆ public_key_bits()

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

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

◆ random_plaintext_element()

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

Definition at line 51 of file mceliece_key.cpp.

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

Referenced by Botan::McEliece_PrivateKey::check_key().

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

◆ subject_public_key()

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

Definition at line 38 of file pk_keys.cpp.

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(), Botan::Public_Key::fingerprint_public(), and Botan::X509::PEM_encode().

39  {
40  return DER_Encoder()
41  .start_cons(SEQUENCE)
42  .encode(algorithm_identifier())
43  .encode(public_key_bits(), BIT_STRING)
44  .end_cons()
45  .get_contents_unlocked();
46  }
virtual std::vector< uint8_t > public_key_bits() const =0
virtual AlgorithmIdentifier algorithm_identifier() const =0

Member Data Documentation

◆ m_code_length

uint32_t Botan::McEliece_PublicKey::m_code_length
protected

◆ m_public_matrix

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

◆ m_t

uint32_t Botan::McEliece_PublicKey::m_t
protected

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