Botan 3.1.1
Crypto and TLS for C&
|
#include <ec_group.h>
Public Member Functions | |
bool | a_is_minus_3 () const |
bool | a_is_zero () const |
EC_Point | blinded_base_point_multiply (const BigInt &k, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
BigInt | blinded_base_point_multiply_x (const BigInt &k, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
EC_Point | blinded_var_point_multiply (const EC_Point &point, const BigInt &k, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
BigInt | cube_mod_order (const BigInt &x) const |
std::vector< uint8_t > | DER_encode (EC_Group_Encoding form) const |
EC_Group () | |
EC_Group (const BigInt &p, const BigInt &a, const BigInt &b, const BigInt &base_x, const BigInt &base_y, const BigInt &order, const BigInt &cofactor, const OID &oid=OID()) | |
EC_Group (const EC_Group &)=default | |
EC_Group (const OID &oid) | |
template<typename Alloc > | |
EC_Group (const std::vector< uint8_t, Alloc > &ber) | |
EC_Group (const uint8_t ber[], size_t ber_len) | |
EC_Group (EC_Group &&)=default | |
EC_Group (std::string_view pem_or_oid) | |
const BigInt & | get_a () const |
const BigInt & | get_b () const |
const EC_Point & | get_base_point () const |
const BigInt & | get_cofactor () const |
const OID & | get_curve_oid () const |
const BigInt & | get_g_x () const |
const BigInt & | get_g_y () const |
const BigInt & | get_order () const |
size_t | get_order_bits () const |
size_t | get_order_bytes () const |
const BigInt & | get_p () const |
size_t | get_p_bits () const |
size_t | get_p_bytes () const |
EC_Point | hash_to_curve (std::string_view hash_fn, const uint8_t input[], size_t input_len, const uint8_t domain_sep[], size_t domain_sep_len, bool random_oracle=true) const |
EC_Point | hash_to_curve (std::string_view hash_fn, const uint8_t input[], size_t input_len, std::string_view domain_sep, bool random_oracle=true) const |
bool | initialized () const |
BigInt | inverse_mod_order (const BigInt &x) const |
BigInt | mod_order (const BigInt &x) const |
BigInt | multiply_mod_order (const BigInt &x, const BigInt &y) const |
BigInt | multiply_mod_order (const BigInt &x, const BigInt &y, const BigInt &z) const |
EC_Group & | operator= (const EC_Group &)=default |
EC_Group & | operator= (EC_Group &&)=default |
bool | operator== (const EC_Group &other) const |
EC_Point | OS2ECP (const uint8_t bits[], size_t len) const |
EC_Point | OS2ECP (std::span< const uint8_t > encoded_point) const |
std::string | PEM_encode () const |
EC_Point | point (const BigInt &x, const BigInt &y) const |
EC_Point | point_multiply (const BigInt &x, const EC_Point &pt, const BigInt &y) const |
size_t | point_size (EC_Point_Format format) const |
BigInt | random_scalar (RandomNumberGenerator &rng) const |
EC_Group_Source | source () const |
BigInt | square_mod_order (const BigInt &x) const |
bool | verify_group (RandomNumberGenerator &rng, bool strong=false) const |
bool | verify_public_element (const EC_Point &y) const |
EC_Point | zero_point () const |
~EC_Group () | |
Static Public Member Functions | |
static size_t | clear_registered_curve_data () |
static EC_Group | EC_Group_from_PEM (std::string_view pem) |
static OID | EC_group_identity_from_order (const BigInt &order) |
static std::shared_ptr< EC_Group_Data > | EC_group_info (const OID &oid) |
static const std::set< std::string > & | known_named_groups () |
Class representing an elliptic curve
The internal representation is stored in a shared_ptr, so copying an EC_Group is inexpensive.
Definition at line 48 of file ec_group.h.
Botan::EC_Group::EC_Group | ( | const BigInt & | p, |
const BigInt & | a, | ||
const BigInt & | b, | ||
const BigInt & | base_x, | ||
const BigInt & | base_y, | ||
const BigInt & | order, | ||
const BigInt & | cofactor, | ||
const OID & | oid = OID() |
||
) |
Construct Domain paramers from specified parameters
p | the elliptic curve p |
a | the elliptic curve a param |
b | the elliptic curve b param |
base_x | the x coordinate of the base point |
base_y | the y coordinate of the base point |
order | the order of the base point |
cofactor | the cofactor |
oid | an optional OID used to identify this curve |
Definition at line 428 of file ec_group.cpp.
References Botan::ExternalSource.
|
explicit |
Decode a BER encoded ECC domain parameter set
ber | the bytes of the BER encoding |
ber_len | the length of ber |
Definition at line 440 of file ec_group.cpp.
References Botan::ExternalSource.
|
inline |
Definition at line 78 of file ec_group.h.
|
explicit |
Create an EC domain by OID (or throw if unknown)
oid | the OID of the EC domain to create |
Definition at line 390 of file ec_group.cpp.
References Botan::OID::to_string().
|
explicit |
Create an EC domain from PEM encoding (as from PEM_encode), or from an OID name (eg "secp256r1", or "1.2.840.10045.3.1.7")
pem_or_oid | PEM-encoded data, or an OID |
Definition at line 397 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), Botan::ExternalSource, Botan::fmt(), Botan::OID::from_string(), and Botan::OID::has_value().
|
default |
Create an uninitialized EC_Group
Referenced by EC_Group_from_PEM().
|
default |
|
default |
|
default |
bool Botan::EC_Group::a_is_minus_3 | ( | ) | const |
Return if a == -3 mod p
Definition at line 451 of file ec_group.cpp.
bool Botan::EC_Group::a_is_zero | ( | ) | const |
Return if a == 0 mod p
Definition at line 455 of file ec_group.cpp.
EC_Point Botan::EC_Group::blinded_base_point_multiply | ( | const BigInt & | k, |
RandomNumberGenerator & | rng, | ||
std::vector< BigInt > & | ws | ||
) | const |
Blinded point multiplication, attempts resistance to side channels
k | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 558 of file ec_group.cpp.
Referenced by Botan::EC_PrivateKey::EC_PrivateKey().
BigInt Botan::EC_Group::blinded_base_point_multiply_x | ( | const BigInt & | k, |
RandomNumberGenerator & | rng, | ||
std::vector< BigInt > & | ws | ||
) | const |
Blinded point multiplication, attempts resistance to side channels Returns just the x coordinate of the point
k | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 564 of file ec_group.cpp.
References Botan::EC_Point::get_affine_x(), Botan::EC_Point::is_zero(), and Botan::BigInt::zero().
EC_Point Botan::EC_Group::blinded_var_point_multiply | ( | const EC_Point & | point, |
const BigInt & | k, | ||
RandomNumberGenerator & | rng, | ||
std::vector< BigInt > & | ws | ||
) | const |
Blinded point multiplication, attempts resistance to side channels
point | input point |
k | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 579 of file ec_group.cpp.
References get_order(), Botan::EC_Point_Var_Point_Precompute::mul(), and point().
|
static |
Definition at line 301 of file ec_group.cpp.
Definition at line 225 of file ec_group.h.
std::vector< uint8_t > Botan::EC_Group::DER_encode | ( | EC_Group_Encoding | form | ) | const |
Create the DER encoding of this domain
form | of encoding to use |
Definition at line 621 of file ec_group.cpp.
References Botan::OID::empty(), Botan::DER_Encoder::encode(), Botan::BigInt::encode_1363(), Botan::DER_Encoder::encode_null(), Botan::DER_Encoder::end_cons(), Botan::Explicit, get_a(), get_b(), get_base_point(), get_cofactor(), get_curve_oid(), get_order(), get_p(), get_p_bytes(), Botan::ImplicitCA, Botan::NamedCurve, Botan::OctetString, Botan::DER_Encoder::start_sequence(), and Botan::Uncompressed.
Referenced by Botan::TLS::Signature_Scheme::key_algorithm_identifier(), and PEM_encode().
|
static |
Definition at line 423 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), and EC_Group().
Definition at line 344 of file ec_named.cpp.
References Botan::BigInt::word_at().
|
static |
Definition at line 15 of file ec_named.cpp.
const BigInt & Botan::EC_Group::get_a | ( | ) | const |
Return the a parameter of the elliptic curve equation
Definition at line 479 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), hash_to_curve(), operator==(), Botan::sm2_compute_za(), and verify_group().
const BigInt & Botan::EC_Group::get_b | ( | ) | const |
Return the b parameter of the elliptic curve equation
Definition at line 483 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), hash_to_curve(), operator==(), Botan::sm2_compute_za(), and verify_group().
const EC_Point & Botan::EC_Group::get_base_point | ( | ) | const |
Return group base point
Definition at line 487 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PrivateKey::EC_PrivateKey(), point_multiply(), and verify_group().
const BigInt & Botan::EC_Group::get_cofactor | ( | ) | const |
Return the cofactor
Definition at line 503 of file ec_group.cpp.
Referenced by DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), Botan::ECIES_Decryptor::ECIES_Decryptor(), Botan::EC_PublicKey::get_int_field(), operator==(), verify_group(), and verify_public_element().
const OID & Botan::EC_Group::get_curve_oid | ( | ) | const |
Return the OID of these domain parameters
Definition at line 527 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), DER_encode(), and Botan::EC_PublicKey::set_parameter_encoding().
const BigInt & Botan::EC_Group::get_g_x | ( | ) | const |
Return the x coordinate of the base point
Definition at line 495 of file ec_group.cpp.
Referenced by Botan::EC_PublicKey::get_int_field(), operator==(), and Botan::sm2_compute_za().
const BigInt & Botan::EC_Group::get_g_y | ( | ) | const |
Return the y coordinate of the base point
Definition at line 499 of file ec_group.cpp.
Referenced by Botan::EC_PublicKey::get_int_field(), operator==(), and Botan::sm2_compute_za().
const BigInt & Botan::EC_Group::get_order | ( | ) | const |
Return the order of the base point
Definition at line 491 of file ec_group.cpp.
Referenced by blinded_var_point_multiply(), DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), Botan::ECIES_Decryptor::ECIES_Decryptor(), Botan::EC_PublicKey::get_int_field(), operator==(), random_scalar(), verify_group(), and verify_public_element().
size_t Botan::EC_Group::get_order_bits | ( | ) | const |
Return the size of group order in bits (same as get_order().bits())
Definition at line 467 of file ec_group.cpp.
size_t Botan::EC_Group::get_order_bytes | ( | ) | const |
Return the size of p in bytes (same as get_order().bytes())
Definition at line 471 of file ec_group.cpp.
const BigInt & Botan::EC_Group::get_p | ( | ) | const |
Return the prime modulus of the field
Definition at line 475 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), hash_to_curve(), Botan::hash_to_curve_sswu(), operator==(), and verify_group().
size_t Botan::EC_Group::get_p_bits | ( | ) | const |
Return the size of p in bits (same as get_p().bits())
Definition at line 459 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algo_name(), Botan::GOST_3410_PrivateKey::GOST_3410_PrivateKey(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), and Botan::EC_PublicKey::key_length().
size_t Botan::EC_Group::get_p_bytes | ( | ) | const |
Return the size of p in bits (same as get_p().bytes())
Definition at line 463 of file ec_group.cpp.
Referenced by DER_encode(), point_size(), and Botan::sm2_compute_za().
EC_Point Botan::EC_Group::hash_to_curve | ( | std::string_view | hash_fn, |
const uint8_t | input[], | ||
size_t | input_len, | ||
const uint8_t | domain_sep[], | ||
size_t | domain_sep_len, | ||
bool | random_oracle = true |
||
) | const |
Hash onto the curve. For some curve types no mapping is currently available, in this case this function will throw an exception.
hash_fn | the hash function to use (typically "SHA-256" or "SHA-512") |
input | the input to hash |
input_len | length of input in bytes |
domain_sep | a domain seperator |
domain_sep_len | length of domain_sep in bytes |
random_oracle | if the mapped point must be uniform (use "true" here unless you know what you are doing) |
Definition at line 600 of file ec_group.cpp.
References BOTAN_UNUSED, get_a(), get_b(), get_p(), and Botan::hash_to_curve_sswu().
Referenced by hash_to_curve().
EC_Point Botan::EC_Group::hash_to_curve | ( | std::string_view | hash_fn, |
const uint8_t | input[], | ||
size_t | input_len, | ||
std::string_view | domain_sep, | ||
bool | random_oracle = true |
||
) | const |
Hash onto the curve. For some curve types no mapping is currently available, in this case this function will throw an exception.
hash_fn | the hash function to use (typically "SHA-256" or "SHA-512") |
input | the input to hash |
input_len | length of input in bytes |
domain_sep | a domain seperator |
random_oracle | if the mapped point must be uniform (use "true" here unless you know what you are doing) |
Definition at line 591 of file ec_group.cpp.
References hash_to_curve().
|
inline |
Definition at line 341 of file ec_group.h.
Definition at line 523 of file ec_group.cpp.
Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), and Botan::SM2_PrivateKey::SM2_PrivateKey().
|
static |
Return a set of known named EC groups
Definition at line 460 of file ec_named.cpp.
Definition at line 507 of file ec_group.cpp.
Definition at line 515 of file ec_group.cpp.
BigInt Botan::EC_Group::multiply_mod_order | ( | const BigInt & | x, |
const BigInt & | y, | ||
const BigInt & | z | ||
) | const |
Definition at line 519 of file ec_group.cpp.
bool Botan::EC_Group::operator== | ( | const EC_Group & | other | ) | const |
Definition at line 666 of file ec_group.cpp.
References get_a(), get_b(), get_cofactor(), get_g_x(), get_g_y(), get_order(), and get_p().
EC_Point Botan::EC_Group::OS2ECP | ( | const uint8_t | bits[], |
size_t | len | ||
) | const |
Definition at line 544 of file ec_group.cpp.
References Botan::OS2ECP().
Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), Botan::ECIES_Encryptor::ECIES_Encryptor(), and Botan::TLS::Callbacks::tls_ephemeral_key_agreement().
|
inline |
Definition at line 337 of file ec_group.h.
References Botan::OS2ECP().
std::string Botan::EC_Group::PEM_encode | ( | ) | const |
Return the PEM encoding (always in explicit form)
Definition at line 661 of file ec_group.cpp.
References DER_encode(), Botan::PEM_Code::encode(), and Botan::Explicit.
Return a point on this curve with the affine values x, y
Definition at line 548 of file ec_group.cpp.
Referenced by blinded_var_point_multiply(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), and verify_public_element().
EC_Point Botan::EC_Group::point_multiply | ( | const BigInt & | x, |
const EC_Point & | pt, | ||
const BigInt & | y | ||
) | const |
Multi exponentiate. Not constant time.
Definition at line 553 of file ec_group.cpp.
References get_base_point(), and Botan::EC_Point_Multi_Point_Precompute::multi_exp().
size_t Botan::EC_Group::point_size | ( | EC_Point_Format | format | ) | const |
Definition at line 535 of file ec_group.cpp.
References Botan::Compressed, and get_p_bytes().
BigInt Botan::EC_Group::random_scalar | ( | RandomNumberGenerator & | rng | ) | const |
Return a random scalar ie an integer in [1,order)
Definition at line 575 of file ec_group.cpp.
References get_order(), Botan::BigInt::one(), and Botan::BigInt::random_integer().
Referenced by Botan::EC_PrivateKey::EC_PrivateKey().
EC_Group_Source Botan::EC_Group::source | ( | ) | const |
Definition at line 531 of file ec_group.cpp.
Referenced by verify_group().
Definition at line 511 of file ec_group.cpp.
bool Botan::EC_Group::verify_group | ( | RandomNumberGenerator & | rng, |
bool | strong = false |
||
) | const |
Verify EC_Group domain
Definition at line 701 of file ec_group.cpp.
References Botan::Builtin, Botan::Modular_Reducer::cube(), get_a(), get_b(), get_base_point(), get_cofactor(), get_order(), get_p(), Botan::is_prime(), Botan::Modular_Reducer::multiply(), Botan::EC_Point::on_the_curve(), Botan::Modular_Reducer::reduce(), source(), and Botan::Modular_Reducer::square().
Referenced by Botan::EC_PublicKey::check_key().
bool Botan::EC_Group::verify_public_element | ( | const EC_Point & | y | ) | const |
Check if y is a plausible point on the curve
In particular, checks that it is a point on the curve, not infinity, and that it has order matching the group.
Definition at line 676 of file ec_group.cpp.
References get_cofactor(), get_order(), Botan::EC_Point::is_zero(), Botan::EC_Point::on_the_curve(), and point().
Referenced by Botan::EC_PublicKey::check_key().
EC_Point Botan::EC_Group::zero_point | ( | ) | const |
Return the zero (or infinite) point on this curve
Definition at line 587 of file ec_group.cpp.