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_PrivateKey Class Referencefinal

#include <kyber.h>

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

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::Decryptioncreate_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
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_Decryptioncreate_kem_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const override
 
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::Key_Agreementcreate_key_agreement_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
virtual std::unique_ptr< PK_Ops::Signaturecreate_signature_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
 
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_private (const std::string &alg) const
 
std::string fingerprint_public (const std::string &alg="SHA-256") const
 
virtual OID get_oid () const
 
size_t key_length () const override
 
 Kyber_PrivateKey (RandomNumberGenerator &rng, KyberMode mode)
 
 Kyber_PrivateKey (secure_vector< uint8_t > sk, KyberMode mode, KyberKeyEncoding encoding)
 
virtual size_t message_part_size () const
 
virtual size_t message_parts () const
 
KyberMode mode () 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::unique_ptr< Public_Keypublic_key () const override
 
std::vector< uint8_t > public_key_bits () const override
 
void set_binary_encoding (KyberKeyEncoding encoding)
 
virtual bool stateful_operation () const
 
std::vector< uint8_t > subject_public_key () const
 

Protected Member Functions

void initialize_from_encoding (std::vector< uint8_t > pub_key, KyberMode m, KyberKeyEncoding encoding)
 
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
 

Detailed Description

Definition at line 124 of file kyber.h.

Constructor & Destructor Documentation

◆ Kyber_PrivateKey() [1/2]

Botan::Kyber_PrivateKey::Kyber_PrivateKey ( RandomNumberGenerator rng,
KyberMode  mode 
)

Definition at line 1396 of file kyber.cpp.

1397 {
1398 KyberConstants mode(m);
1399
1400 auto G = mode.G();
1401 auto seed = G->process(rng.random_vec(KyberConstants::kSymBytes));
1402
1403 const auto middle = G->output_length() / 2;
1404 std::vector<uint8_t> seed1(seed.begin(), seed.begin() + middle);
1405 secure_vector<uint8_t> seed2(seed.begin() + middle, seed.end());
1406
1407 auto a = PolynomialMatrix::generate(seed1, false, mode);
1408 auto skpv = PolynomialVector::getnoise_eta1(seed2, 0, mode);
1409 auto e = PolynomialVector::getnoise_eta1(seed2, mode.k(), mode);
1410
1411 skpv.ntt();
1412 e.ntt();
1413
1414 // matrix-vector multiplication
1415 auto pkpv = a.pointwise_acc_montgomery(skpv, true);
1416 pkpv += e;
1417 pkpv.reduce();
1418
1419 m_public = std::make_shared<Kyber_PublicKeyInternal>(mode, std::move(pkpv), std::move(seed1));
1420 m_private = std::make_shared<Kyber_PrivateKeyInternal>(std::move(mode), std::move(skpv),
1421 rng.random_vec(KyberConstants::kZLength));
1422 }
std::shared_ptr< Kyber_PublicKeyInternal > m_public
Definition: kyber.h:120
KyberMode mode() const
Definition: kyber.cpp:1290

References Botan::Kyber_PublicKey::mode(), and Botan::RandomNumberGenerator::random_vec().

◆ Kyber_PrivateKey() [2/2]

Botan::Kyber_PrivateKey::Kyber_PrivateKey ( secure_vector< uint8_t >  sk,
KyberMode  mode,
KyberKeyEncoding  encoding 
)

Definition at line 1424 of file kyber.cpp.

1425 {
1426 KyberConstants mode(m);
1427
1428 if(encoding == KyberKeyEncoding::Full)
1429 {
1430 secure_vector<uint8_t> z, skpv;
1431 BER_Object pub_key;
1432
1433 std::vector<uint8_t> pkpv, seed;
1434
1435 auto dec = BER_Decoder(sk)
1436 .start_sequence()
1437 .decode_and_check<size_t>(0, "kyber private key does have a version other than 0")
1439 .decode(skpv, ASN1_Type::OctetString);
1440
1441 try
1442 {
1443 dec.start_sequence().decode(pkpv, ASN1_Type::OctetString).decode(seed, ASN1_Type::OctetString).end_cons();
1444 }
1445 catch(const BER_Decoding_Error&)
1446 {
1447 throw Botan::Invalid_Argument("reading private key without an embedded public key is not supported");
1448 }
1449
1450 // skipping the public key hash
1451 dec.discard_remaining().end_cons();
1452
1453 if(skpv.size() != mode.polynomial_vector_byte_length())
1454 {
1455 throw Botan::Invalid_Argument("kyber private key sample-param does not have the correct byte count");
1456 }
1457
1458 if(z.size() != KyberConstants::kZLength)
1459 {
1460 throw Botan::Invalid_Argument("kyber private key z-param does not have the correct byte count");
1461 }
1462
1463 m_public = std::make_shared<Kyber_PublicKeyInternal>(m, std::move(pkpv), std::move(seed));
1464 m_private = std::make_shared<Kyber_PrivateKeyInternal>(std::move(mode),
1465 PolynomialVector::from_bytes(skpv, mode), std::move(z));
1466 }
1467 else if(encoding == KyberKeyEncoding::Raw)
1468 {
1469 if(mode.private_key_byte_length() != sk.size())
1470 {
1471 throw Botan::Invalid_Argument("kyber private key does not have the correct byte count");
1472 }
1473
1474 const auto off_pub_key = mode.polynomial_vector_byte_length();
1475 const auto pub_key_len = mode.public_key_byte_length();
1476
1477 auto skpv = secure_vector<uint8_t>(sk.begin(), sk.begin() + off_pub_key);
1478 auto pub_key = std::vector<uint8_t>(sk.begin() + off_pub_key, sk.begin() + off_pub_key + pub_key_len);
1479 // skipping the public key hash
1480 auto z = secure_vector<uint8_t>(sk.end() - KyberConstants::kZLength, sk.end());
1481
1482 initialize_from_encoding(std::move(pub_key), m, encoding);
1483 m_private = std::make_shared<Kyber_PrivateKeyInternal>(std::move(mode),
1484 PolynomialVector::from_bytes(skpv, mode), std::move(z));
1485 }
1486
1487 BOTAN_ASSERT(m_private && m_public, "reading private key encoding");
1488 }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:54
void initialize_from_encoding(std::vector< uint8_t > pub_key, KyberMode m, KyberKeyEncoding encoding)
Definition: kyber.cpp:1305
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:66

References Botan::PEM_Code::decode(), Botan::BER_Decoder::decode_and_check(), Botan::Full, Botan::Kyber_PublicKey::mode(), Botan::OctetString, and Botan::BER_Decoder::start_sequence().

Member Function Documentation

◆ algo_name()

std::string Botan::Kyber_PublicKey::algo_name ( ) const
inlineoverridevirtualinherited

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

◆ algorithm_identifier()

AlgorithmIdentifier Botan::Kyber_PublicKey::algorithm_identifier ( ) const
overridevirtualinherited
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 }
virtual OID get_oid() const
Definition: pk_keys.cpp:53

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

◆ binary_encoding()

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

Definition at line 101 of file kyber.h.

102 {
103 return m_key_encoding;
104 }
KyberKeyEncoding m_key_encoding
Definition: kyber.h:121

Referenced by public_key().

◆ check_key()

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

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_decryption_op()

std::unique_ptr< PK_Ops::Decryption > Botan::Private_Key::create_decryption_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 decryption 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_PrivateKey, Botan::RSA_PrivateKey, and Botan::SM2_PrivateKey.

Definition at line 114 of file pk_keys.cpp.

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

References Botan::Public_Key::algo_name().

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

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

References Botan::Public_Key::algo_name().

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

◆ create_kem_decryption_op()

std::unique_ptr< PK_Ops::KEM_Decryption > Botan::Kyber_PrivateKey::create_kem_decryption_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 decryption 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::Private_Key.

Definition at line 1550 of file kyber.cpp.

1553 {
1554 BOTAN_UNUSED(rng);
1555 if(provider.empty() || provider == "base")
1556 return std::make_unique<Kyber_KEM_Decryptor>(*this, params);
1557 throw Provider_Not_Found(algo_name(), provider);
1558 }
#define BOTAN_UNUSED(...)
Definition: assert.h:141
std::string algo_name() const override
Definition: kyber.h:79

References Botan::Kyber_PublicKey::algo_name(), and BOTAN_UNUSED.

◆ 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
overridevirtualinherited

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 }

References Botan::Kyber_PublicKey::algo_name(), and BOTAN_UNUSED.

◆ create_key_agreement_op()

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
virtualinherited

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
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::Curve25519_PrivateKey, Botan::DH_PrivateKey, and Botan::ECDH_PrivateKey.

Definition at line 138 of file pk_keys.cpp.

141 {
142 throw Lookup_Error(algo_name() + " does not support key agreement");
143 }

References Botan::Public_Key::algo_name().

◆ create_signature_op()

std::unique_ptr< PK_Ops::Signature > Botan::Private_Key::create_signature_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 a signature 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::XMSS_PrivateKey, Botan::TPM_PrivateKey, Botan::DSA_PrivateKey, Botan::ECDSA_PrivateKey, Botan::ECGDSA_PrivateKey, Botan::ECKCDSA_PrivateKey, Botan::Ed25519_PrivateKey, Botan::GOST_3410_PrivateKey, Botan::RSA_PrivateKey, and Botan::SM2_PrivateKey.

Definition at line 130 of file pk_keys.cpp.

133 {
134 throw Lookup_Error(algo_name() + " does not support signatures");
135 }

References Botan::Public_Key::algo_name().

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

◆ 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
overridevirtualinherited

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 Botan::Kyber_PublicKey::m_public.

◆ fingerprint_private()

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.

86 {
88 }
virtual secure_vector< uint8_t > private_key_bits() const =0
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::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().

◆ 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

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 
)
protectedinherited

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, Botan::Kyber_PublicKey::mode(), Botan::OctetString, Botan::Raw, and Botan::BER_Decoder::start_sequence().

Referenced by Botan::Kyber_PublicKey::Kyber_PublicKey().

◆ key_length()

size_t Botan::Kyber_PublicKey::key_length ( ) const
overridevirtualinherited

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 Botan::Kyber_PublicKey::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
inherited

◆ pkcs8_algorithm_identifier()

virtual AlgorithmIdentifier Botan::Private_Key::pkcs8_algorithm_identifier ( ) const
inlinevirtualinherited
Returns
PKCS #8 AlgorithmIdentifier for this key Might be different from the X.509 identifier, but normally is not

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

Definition at line 212 of file pk_keys.h.

213 { return algorithm_identifier(); }
virtual AlgorithmIdentifier algorithm_identifier() const =0

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

◆ private_key_bits()

secure_vector< uint8_t > Botan::Kyber_PrivateKey::private_key_bits ( ) const
overridevirtual
Returns
BER encoded private key bits

Implements Botan::Private_Key.

Definition at line 1497 of file kyber.cpp.

1498 {
1499 switch(m_key_encoding)
1500 {
1502 return private_key_bits_der();
1504 return private_key_bits_raw();
1505 }
1506
1508 }
BOTAN_FORCE_INLINE void unreachable()
Definition: assert.h:160

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

◆ private_key_info()

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.

62 {
63 const size_t PKCS8_VERSION = 0;
64
65 return DER_Encoder()
66 .start_sequence()
67 .encode(PKCS8_VERSION)
70 .end_cons()
71 .get_contents();
72 }
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:212

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::OctetString, Botan::Private_Key::pkcs8_algorithm_identifier(), Botan::Private_Key::private_key_bits(), and Botan::DER_Encoder::start_sequence().

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

◆ public_key()

std::unique_ptr< Public_Key > Botan::Kyber_PrivateKey::public_key ( ) const
overridevirtual

Allocate a new object for the public key associated with this private key.

Returns
public key

Implements Botan::Private_Key.

Definition at line 1490 of file kyber.cpp.

1491 {
1492 auto public_key = std::make_unique<Kyber_PublicKey>(*this);
1493 public_key->set_binary_encoding(binary_encoding());
1494 return public_key;
1495 }
std::unique_ptr< Public_Key > public_key() const override
Definition: kyber.cpp:1490
KyberKeyEncoding binary_encoding() const
Definition: kyber.h:101

References Botan::Kyber_PublicKey::binary_encoding(), and public_key().

Referenced by public_key().

◆ public_key_bits()

std::vector< uint8_t > Botan::Kyber_PublicKey::public_key_bits ( ) const
overridevirtualinherited
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

References Botan::Full, Botan::Kyber_PublicKey::m_key_encoding, Botan::Kyber_PublicKey::public_key_bits_der(), Botan::Kyber_PublicKey::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
protectedinherited

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(), Botan::Kyber_PublicKey::m_public, Botan::OctetString, and Botan::DER_Encoder::start_sequence().

Referenced by Botan::Kyber_PublicKey::public_key_bits().

◆ public_key_bits_raw()

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

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 Botan::Kyber_PublicKey::m_public.

Referenced by Botan::Kyber_PublicKey::public_key_bits().

◆ set_binary_encoding()

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

Definition at line 97 of file kyber.h.

98 {
99 m_key_encoding = encoding;
100 }

◆ stateful_operation()

virtual bool Botan::Private_Key::stateful_operation ( ) const
inlinevirtualinherited

Reimplemented in Botan::XMSS_PrivateKey.

Definition at line 188 of file pk_keys.h.

188{ return false; }

◆ 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 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 144 of file kyber.h.

Member Data Documentation

◆ m_key_encoding

KyberKeyEncoding Botan::Kyber_PublicKey::m_key_encoding
protectedinherited

Definition at line 121 of file kyber.h.

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

◆ m_public

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

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