Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | List of all members
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 70 of file dl_scheme.cpp.

70 :
71 m_group(group),
72 m_private_key(check_dl_private_key_input(private_key, m_group)),
73 m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits())) {}
size_t bits() const
Definition bigint.cpp:290
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 75 of file dl_scheme.cpp.

75 :
76 m_group(group),
77 m_private_key(generate_private_dl_key(group, rng)),
78 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 80 of file dl_scheme.cpp.

82 :
83 m_group(alg_id.parameters(), format),
84 m_private_key(check_dl_private_key_input(decode_single_bigint(key_bits), m_group)),
85 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 95 of file dl_scheme.cpp.

95 {
96 return m_group.verify_group(rng, strong) && m_group.verify_private_element(m_private_key);
97}
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 87 of file dl_scheme.cpp.

87 {
88 return DER_Encoder().encode(m_private_key).get_contents();
89}

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 117 of file dl_scheme.cpp.

117 {
118 if(field == "p") {
119 return m_group.get_p();
120 } else if(field == "q") {
121 return m_group.get_q();
122 } else if(field == "g") {
123 return m_group.get_g();
124 } else if(field == "x") {
125 return m_private_key;
126 } else if(field == "y") {
127 return m_public_key;
128 } else {
129 throw Unknown_PK_Field_Name(algo, field);
130 }
131}
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 99 of file dl_scheme.cpp.

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

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

91 {
92 return BigInt::encode_locked(m_private_key);
93}
static secure_vector< uint8_t > encode_locked(const BigInt &n)
Definition bigint.h:761

References Botan::BigInt::encode_locked().


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