|
Botan 3.12.0
Crypto and TLS for C&
|
#include <dl_group.h>
Public Types | |
| using | Format = DL_Group_Format |
| enum | PrimeType : uint8_t { Strong , Prime_Subgroup , DSA_Kosherizer } |
Public Member Functions | |
| const Montgomery_Params & | _monty_params_p () const |
| const Barrett_Reduction & | _reducer_mod_p () const |
| void | BER_decode (const std::vector< uint8_t > &der, 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) | |
| DL_Group (const uint8_t der[], size_t der_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::span< const uint8_t > der, DL_Group_Format format) | |
| 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 |
| 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) |
| static DL_Group | from_name (std::string_view name) |
| static DL_Group | from_PEM (std::string_view pem) |
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 46 of file dl_group.h.
Definition at line 53 of file dl_group.h.
| enum Botan::DL_Group::PrimeType : uint8_t |
Determine the prime creation for DL groups.
| Enumerator | |
|---|---|
| Strong | |
| Prime_Subgroup | |
| DSA_Kosherizer | |
Definition at line 51 of file dl_group.h.
|
default |
Construct a DL group with uninitialized internal value.
References BOTAN_DEPRECATED, DL_Group(), from_name(), and from_PEM().
Referenced by BER_decode(), DL_Group(), DL_Group(), DL_Group_from_PEM(), from_name(), and 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 243 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.
| Random Number Generators | 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 313 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::random_prime(), Botan::random_safe_prime(), Botan::BigInt::randomize(), Botan::RandomlyGenerated, and Strong.
| 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.
| Random Number Generators | 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 378 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 394 of file dl_group.cpp.
References Botan::ExternalSource.
Create a DL group.
| p | the prime p |
| q | the prime q |
| g | the base g |
Definition at line 401 of file dl_group.cpp.
References Botan::ExternalSource, and Botan::BigInt::is_zero().
|
inline |
Decode a DER-encoded DL group param
Definition at line 131 of file dl_group.h.
References DL_Group().
| Botan::DL_Group::DL_Group | ( | std::span< const uint8_t > | der, |
| DL_Group_Format | format ) |
Decode a DER-encoded DL group param
Definition at line 675 of file dl_group.cpp.
References Botan::ExternalSource.
| const Montgomery_Params & Botan::DL_Group::_monty_params_p | ( | ) | const |
Return parameters for Montgomery reduction/exponentiation mod p
For internal use only
Definition at line 537 of file dl_group.cpp.
| const Barrett_Reduction & Botan::DL_Group::_reducer_mod_p | ( | ) | const |
Definition at line 584 of file dl_group.cpp.
|
inline |
Decode a DER encoded group into this instance.
| der | a vector containing the DER encoded group |
| format | the format of the encoded group |
Definition at line 360 of file dl_group.h.
References BER_decode(), and DL_Group().
Referenced by BER_decode().
| 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 637 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().
|
inlinestatic |
Definition at line 85 of file dl_group.h.
References BOTAN_DEPRECATED, DL_Group(), DL_Group_from_PEM(), and from_PEM().
Referenced by DL_Group_from_PEM().
|
static |
Definition at line 13 of file dl_named.cpp.
Referenced by DL_Group(), and from_name().
| 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 563 of file dl_group.cpp.
| 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 567 of file dl_group.cpp.
|
static |
Construct a DL group that is registered in the configuration.
| name | the name of the group, for example "modp/ietf/3072" |
| Invalid_Argument | if the named group is unknown |
Definition at line 262 of file dl_group.cpp.
References DL_Group(), DL_group_info(), and Botan::fmt().
Referenced by botan_srp6_client_agree(), botan_srp6_generate_verifier(), botan_srp6_group_size(), botan_srp6_server_session_step1(), Botan::create_private_key(), DL_Group(), Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), Botan::srp6_group_identifier(), and Botan::SRP6_Server_Session::step1().
|
static |
Definition at line 273 of file dl_group.cpp.
References Botan::PEM_Code::decode(), DL_Group(), and Botan::unlock().
Referenced by DL_Group(), and DL_Group_from_PEM().
| const BigInt & Botan::DL_Group::get_g | ( | ) | const |
Get the base g.
Definition at line 526 of file dl_group.cpp.
Referenced by DER_encode(), multi_exponentiate(), Botan::srp6_client_agree(), and verify_group().
| const BigInt & Botan::DL_Group::get_p | ( | ) | const |
Get the prime p.
Definition at line 519 of file dl_group.cpp.
Referenced by DER_encode(), inverse_mod_p(), Botan::srp6_client_agree(), 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 533 of file dl_group.cpp.
Referenced by DER_encode(), 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 541 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 571 of file dl_group.cpp.
References get_p(), and Botan::inverse_mod_public_prime().
Return the inverse of x mod q Throws if q is unset on this DL_Group
Definition at line 588 of file dl_group.cpp.
References get_q(), and Botan::inverse_mod_public_prime().
Reduce an integer modulo p
Definition at line 576 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree().
Reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 594 of file dl_group.cpp.
| 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 614 of file dl_group.cpp.
References get_g(), Botan::monty_multi_exp(), and Botan::Montgomery_Int::value().
Multiply and reduce an integer modulo p
Definition at line 580 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree().
Multiply and reduce an integer modulo q Throws if q is unset on this DL_Group
Definition at line 599 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 604 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 545 of file dl_group.cpp.
Referenced by power_b_p(), Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), and Botan::SRP6_Server_Session::step1().
| size_t Botan::DL_Group::p_bytes | ( | ) | const |
Return the size of p in bytes Same as get_p().bytes()
Definition at line 549 of file dl_group.cpp.
Referenced by Botan::srp6_client_agree().
| 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 661 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 622 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 626 of file dl_group.cpp.
Referenced by power_b_p(), and Botan::srp6_client_agree().
Modular exponentiation
Definition at line 261 of file dl_group.h.
References BOTAN_DEPRECATED, and power_g_p().
Referenced by power_g_p(), Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), 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 618 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 553 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 558 of file dl_group.cpp.
| DL_Group_Source Botan::DL_Group::source | ( | ) | const |
Definition at line 630 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 609 of file dl_group.cpp.
References Botan::BigInt::square().
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 449 of file dl_group.cpp.
References Botan::BigInt::bits(), get_p(), and power_g_p().
| bool Botan::DL_Group::verify_group | ( | RandomNumberGenerator & | rng, |
| bool | strong = true ) const |
Perform validity checks on the group.
| Random Number Generators | the rng to use |
| strong | whether to perform stronger by lengthier tests |
Definition at line 466 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::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 434 of file dl_group.cpp.
| 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 417 of file dl_group.cpp.
References get_p(), get_q(), and Botan::BigInt::is_zero().