Botan 3.6.1
Crypto and TLS for C&
|
#include <dl_group.h>
Public Types | |
using | Format = DL_Group_Format |
enum | PrimeType { Strong , Prime_Subgroup , DSA_Kosherizer } |
Public Member Functions | |
void | BER_decode (const std::vector< uint8_t > &ber, DL_Group_Format format) |
std::vector< uint8_t > | DER_encode (DL_Group_Format format) const |
DL_Group ()=default | |
DL_Group (const BigInt &p, const BigInt &g) | |
DL_Group (const BigInt &p, const BigInt &q, const BigInt &g) | |
template<typename Alloc > | |
DL_Group (const std::vector< uint8_t, Alloc > &ber, DL_Group_Format format) | |
DL_Group (const uint8_t ber[], size_t ber_len, DL_Group_Format format) | |
DL_Group (RandomNumberGenerator &rng, const std::vector< uint8_t > &seed, size_t pbits=1024, size_t qbits=0) | |
DL_Group (RandomNumberGenerator &rng, PrimeType type, size_t pbits, size_t qbits=0) | |
DL_Group (std::string_view name) | |
size_t | estimated_strength () const |
size_t | exponent_bits () const |
const BigInt & | get_g () const |
const BigInt & | get_p () const |
const BigInt & | get_q () const |
bool | has_q () const |
BigInt | inverse_mod_p (const BigInt &x) const |
BigInt | inverse_mod_q (const BigInt &x) const |
BigInt | mod_p (const BigInt &x) const |
BigInt | mod_q (const BigInt &x) const |
std::shared_ptr< const Montgomery_Params > | monty_params_p () const |
BigInt | multi_exponentiate (const BigInt &x, const BigInt &y, const BigInt &z) const |
BigInt | multiply_mod_p (const BigInt &x, const BigInt &y) const |
BigInt | multiply_mod_q (const BigInt &x, const BigInt &y) const |
BigInt | multiply_mod_q (const BigInt &x, const BigInt &y, const BigInt &z) const |
size_t | p_bits () const |
size_t | p_bytes () const |
std::string | PEM_encode (DL_Group_Format format) const |
BigInt | power_b_p (const BigInt &b, const BigInt &x) const |
BigInt | power_b_p (const BigInt &b, const BigInt &x, size_t max_x_bits) const |
BigInt | power_g_p (const BigInt &x) const |
BigInt | power_g_p (const BigInt &x, size_t max_x_bits) const |
size_t | q_bits () const |
size_t | q_bytes () const |
DL_Group_Source | source () const |
BigInt | square_mod_q (const BigInt &x) const |
bool | verify_element_pair (const BigInt &y, const BigInt &x) const |
bool | verify_group (RandomNumberGenerator &rng, bool strong=true) const |
bool | verify_private_element (const BigInt &x) const |
bool | verify_public_element (const BigInt &y) const |
Static Public Member Functions | |
static DL_Group | DL_Group_from_PEM (std::string_view pem) |
static std::shared_ptr< DL_Group_Data > | DL_group_info (std::string_view name) |
This class represents discrete logarithm groups. It holds a prime modulus p, a generator g, and (optionally) a prime q which is a factor of (p-1). In most cases g generates the order-q subgroup.
Definition at line 44 of file dl_group.h.
Definition at line 51 of file dl_group.h.
Determine the prime creation for DL groups.
Enumerator | |
---|---|
Strong | |
Prime_Subgroup | |
DSA_Kosherizer |
Definition at line 49 of file dl_group.h.
|
default |
Construct a DL group with uninitialized internal value. Use this constructor is you wish to set the groups values from a DER or PEM encoded group.
Referenced by DL_Group_from_PEM().
|
explicit |
Construct a DL group that is registered in the configuration.
name | the name of the group, for example "modp/ietf/3072" |
Definition at line 176 of file dl_group.cpp.
References Botan::PEM_Code::decode(), DL_group_info(), Botan::ExternalSource, Botan::fmt(), and Botan::unlock().
Botan::DL_Group::DL_Group | ( | RandomNumberGenerator & | rng, |
PrimeType | type, | ||
size_t | pbits, | ||
size_t | qbits = 0 ) |
Create a new group randomly.
rng | the random number generator to use |
type | specifies how the creation of primes p and q shall be performed. If type=Strong, then p will be determined as a safe prime, and q will be chosen as (p-1)/2. If type=Prime_Subgroup and qbits = 0, then the size of q will be determined according to the estimated difficulty of the DL problem. If type=DSA_Kosherizer, DSA primes will be created. |
pbits | the number of bits of p |
qbits | the number of bits of q. Leave it as 0 to have the value determined according to pbits. |
Definition at line 224 of file dl_group.cpp.
References Botan::BigInt::bits(), Botan::dl_exponent_size(), DSA_Kosherizer, Botan::fmt(), Botan::BigInt::from_word(), Botan::generate_dsa_primes(), Botan::is_prime(), Botan::jacobi(), Prime_Subgroup, Botan::PRIME_TABLE_SIZE, Botan::PRIMES, Botan::random_prime(), Botan::random_safe_prime(), Botan::RandomlyGenerated, Botan::Modular_Reducer::reduce(), and X.
Botan::DL_Group::DL_Group | ( | RandomNumberGenerator & | rng, |
const std::vector< uint8_t > & | seed, | ||
size_t | pbits = 1024, | ||
size_t | qbits = 0 ) |
Create a DSA group with a given seed.
rng | the random number generator to use |
seed | the seed to use to create the random primes |
pbits | the desired bit size of the prime p |
qbits | the desired bit size of the prime q. |
Definition at line 290 of file dl_group.cpp.
References Botan::generate_dsa_primes(), and Botan::RandomlyGenerated.
Create a DL group.
p | the prime p |
g | the base g |
Definition at line 305 of file dl_group.cpp.
References Botan::ExternalSource, and Botan::BigInt::zero().
Create a DL group.
p | the prime p |
q | the prime q |
g | the base g |
Definition at line 312 of file dl_group.cpp.
References Botan::ExternalSource.
Botan::DL_Group::DL_Group | ( | const uint8_t | ber[], |
size_t | ber_len, | ||
DL_Group_Format | format ) |
Decode a BER-encoded DL group param
Definition at line 582 of file dl_group.cpp.
References Botan::ExternalSource.
|
inline |
Decode a BER-encoded DL group param
Definition at line 123 of file dl_group.h.
void Botan::DL_Group::BER_decode | ( | const std::vector< uint8_t > & | ber, |
DL_Group_Format | format ) |
Decode a DER/BER encoded group into this instance.
ber | a vector containing the DER/BER encoded group |
format | the format of the encoded group |
Definition at line 586 of file dl_group.cpp.
References Botan::ExternalSource.
std::vector< uint8_t > Botan::DL_Group::DER_encode | ( | DL_Group_Format | format | ) | const |
Encode this group into a string using DER encoding.
format | the encoding format |
Definition at line 544 of file dl_group.cpp.
References Botan::ANSI_X9_42, Botan::ANSI_X9_57, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), get_g(), get_p(), get_q(), Botan::PKCS_3, and Botan::DER_Encoder::start_sequence().
Referenced by PEM_encode().
|
static |
Definition at line 591 of file dl_group.cpp.
References Botan::PEM_Code::decode(), DL_Group(), and Botan::unlock().
|
static |
Definition at line 13 of file dl_named.cpp.
References name.
Referenced by DL_Group().
size_t Botan::DL_Group::estimated_strength | ( | ) | const |
Return an estimate of the strength of this group against discrete logarithm attacks (eg NFS). Warning: since this only takes into account known attacks it is by necessity an overestimate of the actual strength.
Definition at line 470 of file dl_group.cpp.
Referenced by Botan::DL_PublicKey::estimated_strength().
size_t Botan::DL_Group::exponent_bits | ( | ) | const |
Return size in bits of a secret exponent
This attempts to balance between the attack costs of NFS (which depends on the size of the modulus) and Pollard's rho (which depends on the size of the exponent).
It may vary over time for a particular group, if the attack costs change.
Definition at line 474 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step1().
const BigInt & Botan::DL_Group::get_g | ( | ) | const |
Get the base g.
Definition at line 433 of file dl_group.cpp.
Referenced by DER_encode(), Botan::DL_PrivateKey::get_int_field(), Botan::DL_PublicKey::get_int_field(), multi_exponentiate(), Botan::srp6_client_agree(), Botan::srp6_group_identifier(), Botan::SRP6_Server_Session::step1(), and verify_group().
const BigInt & Botan::DL_Group::get_p | ( | ) | const |
Get the prime p.
Definition at line 426 of file dl_group.cpp.
Referenced by DER_encode(), Botan::DL_PrivateKey::get_int_field(), Botan::DL_PublicKey::get_int_field(), inverse_mod_p(), Botan::srp6_client_agree(), Botan::srp6_group_identifier(), Botan::SRP6_Server_Session::step1(), Botan::SRP6_Server_Session::step2(), verify_element_pair(), verify_group(), verify_private_element(), and verify_public_element().
const BigInt & Botan::DL_Group::get_q | ( | ) | const |
Get the prime q, returns zero if q is not used
Definition at line 440 of file dl_group.cpp.
Referenced by DER_encode(), Botan::DL_PrivateKey::get_int_field(), Botan::DL_PublicKey::get_int_field(), inverse_mod_q(), verify_group(), verify_private_element(), and verify_public_element().
bool Botan::DL_Group::has_q | ( | ) | const |
Return if the q value is set
Definition at line 448 of file dl_group.cpp.
Referenced by Botan::DSA_PrivateKey::DSA_PrivateKey(), and Botan::DSA_PrivateKey::DSA_PrivateKey().
Return the inverse of x mod p
Definition at line 478 of file dl_group.cpp.
References get_p(), and Botan::inverse_mod().
Return the inverse of x mod q Throws if q is unset on this DL_Group
Definition at line 491 of file dl_group.cpp.
References get_q(), and Botan::inverse_mod().
Reduce an integer modulo p
Definition at line 483 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step1().
Reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 497 of file dl_group.cpp.
std::shared_ptr< const Montgomery_Params > Botan::DL_Group::monty_params_p | ( | ) | const |
Return parameters for Montgomery reduction/exponentiation mod p
Definition at line 444 of file dl_group.cpp.
Referenced by multi_exponentiate().
BigInt Botan::DL_Group::multi_exponentiate | ( | const BigInt & | x, |
const BigInt & | y, | ||
const BigInt & | z ) const |
Multi-exponentiate Return (g^x * y^z) % p
Definition at line 517 of file dl_group.cpp.
References get_g(), Botan::monty_multi_exp(), and monty_params_p().
Multiply and reduce an integer modulo p
Definition at line 487 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step2().
Multiply and reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 502 of file dl_group.cpp.
Referenced by multiply_mod_q().
BigInt Botan::DL_Group::multiply_mod_q | ( | const BigInt & | x, |
const BigInt & | y, | ||
const BigInt & | z ) const |
Multiply and reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 507 of file dl_group.cpp.
References multiply_mod_q().
size_t Botan::DL_Group::p_bits | ( | ) | const |
Return the size of p in bits Same as get_p().bits()
Definition at line 452 of file dl_group.cpp.
Referenced by Botan::DL_PublicKey::p_bits(), power_b_p(), Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), Botan::SRP6_Server_Session::step1(), and Botan::SRP6_Server_Session::step2().
size_t Botan::DL_Group::p_bytes | ( | ) | const |
Return the size of p in bytes Same as get_p().bytes()
Definition at line 456 of file dl_group.cpp.
Referenced by botan_srp6_group_size(), Botan::DL_PublicKey::public_key_as_bytes(), Botan::srp6_client_agree(), Botan::SRP6_Server_Session::step1(), and Botan::SRP6_Server_Session::step2().
std::string Botan::DL_Group::PEM_encode | ( | DL_Group_Format | format | ) | const |
Encode this group into a string using PEM encoding.
format | the encoding format |
Definition at line 568 of file dl_group.cpp.
References Botan::ANSI_X9_42, Botan::ANSI_X9_57, DER_encode(), Botan::PEM_Code::encode(), and Botan::PKCS_3.
Modular exponentiation
b | the base |
x | the exponent |
Definition at line 529 of file dl_group.cpp.
References p_bits(), and power_b_p().
Modular exponentiation
b | the base |
x | the exponent |
max_x_bits | x is assumed to be at most this many bits long. |
Definition at line 533 of file dl_group.cpp.
References Botan::b.
Referenced by power_b_p(), Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step2().
Modular exponentiation
Definition at line 521 of file dl_group.cpp.
References Botan::BigInt::bits().
Referenced by Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), Botan::SRP6_Server_Session::step1(), and verify_element_pair().
Modular exponentiation
x | the exponent |
max_x_bits | x is assumed to be at most this many bits long. |
Definition at line 525 of file dl_group.cpp.
size_t Botan::DL_Group::q_bits | ( | ) | const |
Return the size of q in bits Same as get_q().bits() Throws if q is unset
Definition at line 460 of file dl_group.cpp.
size_t Botan::DL_Group::q_bytes | ( | ) | const |
Return the size of q in bytes Same as get_q().bytes() Throws if q is unset
Definition at line 465 of file dl_group.cpp.
DL_Group_Source Botan::DL_Group::source | ( | ) | const |
Definition at line 537 of file dl_group.cpp.
Referenced by verify_group().
Square and reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 512 of file dl_group.cpp.
Verify a pair of elements y = g^x
This verifies that 1 < x,y < p and that y=g^x mod p
Definition at line 356 of file dl_group.cpp.
References get_p(), and power_g_p().
bool Botan::DL_Group::verify_group | ( | RandomNumberGenerator & | rng, |
bool | strong = true ) const |
Perform validity checks on the group.
rng | the rng to use |
strong | whether to perform stronger by lengthier tests |
Definition at line 373 of file dl_group.cpp.
References Botan::Builtin, Botan::ExternalSource, Botan::BigInt::from_word(), get_g(), get_p(), get_q(), Botan::is_prime(), and source().
Referenced by Botan::DL_PrivateKey::check_key(), Botan::DL_PublicKey::check_key(), and Botan::TLS::Client_Key_Exchange::Client_Key_Exchange().
bool Botan::DL_Group::verify_private_element | ( | const BigInt & | x | ) | const |
Verify a private element
Specifically this checks that x is > 1 and < p, and additionally if q is set then x must be < q
Definition at line 341 of file dl_group.cpp.
References get_p(), and get_q().
Referenced by Botan::DL_PrivateKey::check_key().
bool Botan::DL_Group::verify_public_element | ( | const BigInt & | y | ) | const |
Verify a public element, ie check if y = g^x for some x.
This is not a perfect test. It verifies that 1 < y < p and (if q is set) that y is in the subgroup of size q.
Definition at line 324 of file dl_group.cpp.
References get_p(), get_q(), and Botan::BigInt::is_zero().
Referenced by Botan::DL_PublicKey::check_key().