Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Botan::Kyber_PublicKey Class Reference

#include <kyber.h>

Inheritance diagram for Botan::Kyber_PublicKey:
Botan::Public_Key Botan::Kyber_PrivateKey

Public Member Functions

std::string algo_name () const override
 
AlgorithmIdentifier algorithm_identifier () const override
 
KyberKeyEncoding binary_encoding () const
 
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
 
virtual Signature_Format default_x509_signature_format () const
 
size_t estimated_strength () const override
 
std::string fingerprint_public (const std::string &alg="SHA-256") const
 
virtual OID get_oid () const
 
size_t key_length () const override
 
 Kyber_PublicKey (const Kyber_PublicKey &other)
 
 Kyber_PublicKey (std::vector< uint8_t > pub_key, KyberMode mode, KyberKeyEncoding encoding)
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
KyberMode mode () const
 
Kyber_PublicKeyoperator= (const Kyber_PublicKey &other)=default
 
std::vector< uint8_t > public_key_bits () const override
 
void set_binary_encoding (KyberKeyEncoding encoding)
 
std::vector< uint8_t > subject_public_key () const
 
virtual ~Kyber_PublicKey ()=default
 

Protected Member Functions

void initialize_from_encoding (std::vector< uint8_t > pub_key, KyberMode m, KyberKeyEncoding encoding)
 
 Kyber_PublicKey ()
 
std::vector< uint8_t > public_key_bits_der () const
 
std::vector< uint8_t > public_key_bits_raw () const
 

Protected Attributes

KyberKeyEncoding m_key_encoding
 
std::shared_ptr< Kyber_PublicKeyInternal > m_public
 

Friends

class Kyber_KEM_Decryptor
 
class Kyber_KEM_Encryptor
 

Detailed Description

Definition at line 68 of file kyber.h.

Constructor & Destructor Documentation

◆ Kyber_PublicKey() [1/3]

Botan::Kyber_PublicKey::Kyber_PublicKey ( std::vector< uint8_t >  pub_key,
KyberMode  mode,
KyberKeyEncoding  encoding 
)

Definition at line 1343 of file kyber.cpp.

1344 : Kyber_PublicKey()
1345 {
1346 initialize_from_encoding(std::move(pub_key), m, encoding);
1347 }
void initialize_from_encoding(std::vector< uint8_t > pub_key, KyberMode m, KyberKeyEncoding encoding)
Definition: kyber.cpp:1305

References initialize_from_encoding().

◆ Kyber_PublicKey() [2/3]

Botan::Kyber_PublicKey::Kyber_PublicKey ( const Kyber_PublicKey other)

Definition at line 1349 of file kyber.cpp.

1350 : m_public(std::make_shared<Kyber_PublicKeyInternal>(*other.m_public)), m_key_encoding(other.m_key_encoding)
1351 {
1352 }
std::shared_ptr< Kyber_PublicKeyInternal > m_public
Definition: kyber.h:120
KyberKeyEncoding m_key_encoding
Definition: kyber.h:121

◆ ~Kyber_PublicKey()

virtual Botan::Kyber_PublicKey::~Kyber_PublicKey ( )
virtualdefault

◆ Kyber_PublicKey() [3/3]

Botan::Kyber_PublicKey::Kyber_PublicKey ( )
inlineprotected

Definition at line 107 of file kyber.h.

References Botan::Full.

Member Function Documentation

◆ algo_name()

std::string Botan::Kyber_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 79 of file kyber.h.

79{ return "Kyber-r3"; }

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

◆ algorithm_identifier()

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

Implements Botan::Public_Key.

Definition at line 1295 of file kyber.cpp.

1296 {
1297 return AlgorithmIdentifier(mode().get_oid(), AlgorithmIdentifier::USE_EMPTY_PARAM);
1298 }
KyberMode mode() const
Definition: kyber.cpp:1290
virtual OID get_oid() const
Definition: pk_keys.cpp:53

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

◆ binary_encoding()

KyberKeyEncoding Botan::Kyber_PublicKey::binary_encoding ( ) const
inline

Definition at line 101 of file kyber.h.

102 {
103 return m_key_encoding;
104 }

Referenced by Botan::Kyber_PrivateKey::public_key().

◆ check_key()

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

Test the key values for consistency.

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

Implements Botan::Public_Key.

Definition at line 1391 of file kyber.cpp.

1392 {
1393 return true; // ??
1394 }

◆ create_encryption_op()

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

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

Return an encryption operation for this key/params or throw

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

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

Definition at line 91 of file pk_keys.cpp.

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

References Botan::Public_Key::algo_name().

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

◆ create_kem_encryption_op()

std::unique_ptr< PK_Ops::KEM_Encryption > Botan::Kyber_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 1540 of file kyber.cpp.

1543 {
1544 BOTAN_UNUSED(rng);
1545 if(provider.empty() || provider == "base")
1546 return std::make_unique<Kyber_KEM_Encryptor>(*this, params);
1547 throw Provider_Not_Found(algo_name(), provider);
1548 }
#define BOTAN_UNUSED(...)
Definition: assert.h:141
std::string algo_name() const override
Definition: kyber.h:79

References algo_name(), and BOTAN_UNUSED.

◆ create_verification_op()

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

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

Return a verification operation for this key/params or throw

Parameters
paramsadditional parameters
providerthe provider to use

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

Definition at line 107 of file pk_keys.cpp.

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

References Botan::Public_Key::algo_name().

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

◆ default_x509_signature_format()

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

Reimplemented in Botan::GOST_3410_PublicKey.

Definition at line 125 of file pk_keys.h.

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

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

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

◆ estimated_strength()

size_t Botan::Kyber_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 1300 of file kyber.cpp.

1301 {
1302 return m_public->mode().estimated_strength();
1303 }

References m_public.

◆ fingerprint_public()

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

Definition at line 77 of file pk_keys.cpp.

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

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

◆ get_oid()

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

◆ initialize_from_encoding()

void Botan::Kyber_PublicKey::initialize_from_encoding ( std::vector< uint8_t >  pub_key,
KyberMode  m,
KyberKeyEncoding  encoding 
)
protected

Definition at line 1305 of file kyber.cpp.

1306 {
1307 KyberConstants mode(m);
1308
1309 std::vector<uint8_t> poly_vec, seed;
1310
1311 switch(encoding)
1312 {
1314 BER_Decoder(pub_key)
1315 .start_sequence()
1316 .decode(poly_vec, ASN1_Type::OctetString)
1317 .decode(seed, ASN1_Type::OctetString)
1318 .end_cons();
1319 break;
1321 if(pub_key.size() != mode.public_key_byte_length())
1322 {
1323 throw Botan::Invalid_Argument("kyber public key does not have the correct byte count");
1324 }
1325 poly_vec = std::vector<uint8_t>(pub_key.begin(), pub_key.end() - KyberConstants::kSeedLength);
1326 seed = std::vector<uint8_t>(pub_key.end() - KyberConstants::kSeedLength, pub_key.end());
1327 break;
1328 }
1329
1330 if(poly_vec.size() != mode.polynomial_vector_byte_length())
1331 {
1332 throw Botan::Invalid_Argument("kyber public key t-param does not have the correct byte count");
1333 }
1334
1335 if(seed.size() != KyberConstants::kSeedLength)
1336 {
1337 throw Botan::Invalid_Argument("kyber public key rho-param does not have the correct byte count");
1338 }
1339
1340 m_public = std::make_shared<Kyber_PublicKeyInternal>(std::move(mode), std::move(poly_vec), std::move(seed));
1341 }

References Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::Full, mode(), Botan::OctetString, Botan::Raw, and Botan::BER_Decoder::start_sequence().

Referenced by Kyber_PublicKey().

◆ key_length()

size_t Botan::Kyber_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 1386 of file kyber.cpp.

1387 {
1388 return m_public->mode().public_key_byte_length();
1389 }

References m_public.

◆ message_part_size()

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

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

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

Returns
size of the message parts in bits

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

Definition at line 123 of file pk_keys.h.

123{ return 0; }

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

◆ message_parts()

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

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

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

Returns
number of message parts

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

Definition at line 112 of file pk_keys.h.

112{ return 1; }

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

◆ mode()

KyberMode Botan::Kyber_PublicKey::mode ( ) const

Definition at line 1290 of file kyber.cpp.

1291 {
1292 return m_public->mode().mode();
1293 }

References m_public.

Referenced by algorithm_identifier(), initialize_from_encoding(), and Botan::Kyber_PrivateKey::Kyber_PrivateKey().

◆ operator=()

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

◆ public_key_bits()

std::vector< uint8_t > Botan::Kyber_PublicKey::public_key_bits ( ) const
overridevirtual
Returns
BER encoded public key bits

Implements Botan::Public_Key.

Definition at line 1354 of file kyber.cpp.

1355 {
1356 switch(m_key_encoding)
1357 {
1359 return public_key_bits_der();
1361 return public_key_bits_raw();
1362 }
1363
1365 }
std::vector< uint8_t > public_key_bits_raw() const
Definition: kyber.cpp:1367
std::vector< uint8_t > public_key_bits_der() const
Definition: kyber.cpp:1373
BOTAN_FORCE_INLINE void unreachable()
Definition: assert.h:160

References Botan::Full, m_key_encoding, public_key_bits_der(), public_key_bits_raw(), Botan::Raw, and Botan::unreachable().

◆ public_key_bits_der()

std::vector< uint8_t > Botan::Kyber_PublicKey::public_key_bits_der ( ) const
protected

Definition at line 1373 of file kyber.cpp.

1374 {
1375 std::vector<uint8_t> output;
1376 DER_Encoder der(output);
1377
1378 der.start_sequence()
1379 .encode(m_public->polynomials().to_bytes<std::vector<uint8_t>>(), ASN1_Type::OctetString)
1380 .encode(m_public->seed(), ASN1_Type::OctetString)
1381 .end_cons();
1382
1383 return output;
1384 }

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), m_public, Botan::OctetString, and Botan::DER_Encoder::start_sequence().

Referenced by public_key_bits().

◆ public_key_bits_raw()

std::vector< uint8_t > Botan::Kyber_PublicKey::public_key_bits_raw ( ) const
protected

Definition at line 1367 of file kyber.cpp.

1368 {
1369 return concat(m_public->polynomials().to_bytes<std::vector<uint8_t>>(),
1370 m_public->seed());
1371 }
decltype(auto) concat(Ts &&...buffers)
Definition: stl_util.h:116

References Botan::concat(), and m_public.

Referenced by public_key_bits().

◆ set_binary_encoding()

void Botan::Kyber_PublicKey::set_binary_encoding ( KyberKeyEncoding  encoding)
inline

Definition at line 97 of file kyber.h.

98 {
99 m_key_encoding = encoding;
100 }

◆ subject_public_key()

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

Definition at line 38 of file pk_keys.cpp.

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

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

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

Friends And Related Function Documentation

◆ Kyber_KEM_Decryptor

friend class Kyber_KEM_Decryptor
friend

Definition at line 118 of file kyber.h.

◆ Kyber_KEM_Encryptor

friend class Kyber_KEM_Encryptor
friend

Definition at line 117 of file kyber.h.

Member Data Documentation

◆ m_key_encoding

KyberKeyEncoding Botan::Kyber_PublicKey::m_key_encoding
protected

Definition at line 121 of file kyber.h.

Referenced by Botan::Kyber_PrivateKey::private_key_bits(), and public_key_bits().

◆ m_public

std::shared_ptr<Kyber_PublicKeyInternal> Botan::Kyber_PublicKey::m_public
protected

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