Botan 3.6.1
Crypto and TLS for C&
Botan::DL_PrivateKey Class Referencefinal

#include <dl_scheme.h>

Public Member Functions

bool check_key (RandomNumberGenerator &rng, bool strong) const
 
secure_vector< uint8_t > DER_encode () const
 
 DL_PrivateKey (const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits, DL_Group_Format format)
 
 DL_PrivateKey (const DL_Group &group, const BigInt &private_key)
 
 DL_PrivateKey (const DL_Group &group, RandomNumberGenerator &rng)
 
const BigIntget_int_field (std::string_view algo_name, std::string_view field) const
 
const DL_Groupgroup () const
 
const BigIntprivate_key () const
 
std::shared_ptr< DL_PublicKeypublic_key () const
 
secure_vector< uint8_t > raw_private_key_bits () const
 

Detailed Description

Definition at line 49 of file dl_scheme.h.

Constructor & Destructor Documentation

◆ DL_PrivateKey() [1/3]

Botan::DL_PrivateKey::DL_PrivateKey ( const DL_Group & group,
const BigInt & private_key )

Definition at line 68 of file dl_scheme.cpp.

68 :
69 m_group(group),
70 m_private_key(check_dl_private_key_input(private_key, m_group)),
71 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}
size_t bits() const
Definition bigint.cpp:295
BigInt power_g_p(const BigInt &x) const
Definition dl_group.cpp:521
const BigInt & private_key() const
Definition dl_scheme.h:72
const DL_Group & group() const
Definition dl_scheme.h:67

◆ DL_PrivateKey() [2/3]

Botan::DL_PrivateKey::DL_PrivateKey ( const DL_Group & group,
RandomNumberGenerator & rng )

Definition at line 73 of file dl_scheme.cpp.

73 :
74 m_group(group),
75 m_private_key(generate_private_dl_key(group, rng)),
76 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}

◆ DL_PrivateKey() [3/3]

Botan::DL_PrivateKey::DL_PrivateKey ( const AlgorithmIdentifier & alg_id,
std::span< const uint8_t > key_bits,
DL_Group_Format format )

Definition at line 78 of file dl_scheme.cpp.

80 :
81 m_group(alg_id.parameters(), format),
82 m_private_key(check_dl_private_key_input(decode_single_bigint(key_bits), m_group)),
83 m_public_key(m_group.power_g_p(m_private_key, m_group.p_bits())) {}
size_t p_bits() const
Definition dl_group.cpp:452

Member Function Documentation

◆ check_key()

bool Botan::DL_PrivateKey::check_key ( RandomNumberGenerator & rng,
bool strong ) const

Definition at line 93 of file dl_scheme.cpp.

93 {
94 return m_group.verify_group(rng, strong) && m_group.verify_private_element(m_private_key);
95}
bool verify_private_element(const BigInt &x) const
Definition dl_group.cpp:341
bool verify_group(RandomNumberGenerator &rng, bool strong=true) const
Definition dl_group.cpp:373

References Botan::DL_Group::verify_group(), and Botan::DL_Group::verify_private_element().

◆ DER_encode()

secure_vector< uint8_t > Botan::DL_PrivateKey::DER_encode ( ) const

DER encode the private key

Definition at line 85 of file dl_scheme.cpp.

85 {
86 return DER_Encoder().encode(m_private_key).get_contents();
87}

References Botan::DER_Encoder::encode(), and Botan::DER_Encoder::get_contents().

◆ get_int_field()

const BigInt & Botan::DL_PrivateKey::get_int_field ( std::string_view algo_name,
std::string_view field ) const

Definition at line 115 of file dl_scheme.cpp.

115 {
116 if(field == "p") {
117 return m_group.get_p();
118 } else if(field == "q") {
119 return m_group.get_q();
120 } else if(field == "g") {
121 return m_group.get_g();
122 } else if(field == "x") {
123 return m_private_key;
124 } else if(field == "y") {
125 return m_public_key;
126 } else {
127 throw Unknown_PK_Field_Name(algo, field);
128 }
129}
const BigInt & get_p() const
Definition dl_group.cpp:426
const BigInt & get_g() const
Definition dl_group.cpp:433
const BigInt & get_q() const
Definition dl_group.cpp:440

References Botan::DL_Group::get_g(), Botan::DL_Group::get_p(), and Botan::DL_Group::get_q().

◆ group()

const DL_Group & Botan::DL_PrivateKey::group ( ) const
inline

Return the group this key operates in

Definition at line 67 of file dl_scheme.h.

67{ return m_group; }

◆ private_key()

const BigInt & Botan::DL_PrivateKey::private_key ( ) const
inline

Return the integer value of the private key

Definition at line 72 of file dl_scheme.h.

72{ return m_private_key; }

◆ public_key()

std::shared_ptr< DL_PublicKey > Botan::DL_PrivateKey::public_key ( ) const

Return a new shared_ptr of the associated public key

Definition at line 97 of file dl_scheme.cpp.

97 {
98 return std::make_shared<DL_PublicKey>(m_group, m_public_key);
99}

◆ raw_private_key_bits()

secure_vector< uint8_t > Botan::DL_PrivateKey::raw_private_key_bits ( ) const

Return the raw serialization of the private key

Definition at line 89 of file dl_scheme.cpp.

89 {
90 return m_private_key.serialize<secure_vector<uint8_t>>();
91}
T serialize(size_t len) const
Definition bigint.h:712
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References Botan::BigInt::serialize().


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