Botan 3.6.1
Crypto and TLS for C&
|
#include <ec_group.h>
Classes | |
class | Mul2Table |
Table for computing g*x + h*y. More... | |
Public Member Functions | |
const std::shared_ptr< EC_Group_Data > & | _data () const |
bool | a_is_minus_3 () const |
bool | a_is_zero () const |
EC_Point | blinded_base_point_multiply (const BigInt &k_bn, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
BigInt | blinded_base_point_multiply_x (const BigInt &k_bn, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
EC_Point | blinded_var_point_multiply (const EC_Point &point, const BigInt &k_bn, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
BigInt | cube_mod_order (const BigInt &x) const |
std::vector< uint8_t > | DER_encode () 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 &) | |
EC_Group (const OID &oid) | |
EC_Group (const OID &oid, const BigInt &p, const BigInt &a, const BigInt &b, const BigInt &base_x, const BigInt &base_y, const BigInt &order) | |
EC_Group (const uint8_t ber[], size_t ber_len) | |
EC_Group (EC_Group &&)=default | |
EC_Group (std::span< const uint8_t > ber) | |
EC_Group (std::string_view pem_or_oid) | |
const EC_Point & | generator () const |
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 |
bool | has_cofactor () 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 &) |
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_bn, const EC_Point &h_pt, const BigInt &y_bn) 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 | used_explicit_encoding () 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 EC_Group | from_name (std::string_view name) |
static EC_Group | from_OID (const OID &oid) |
static EC_Group | from_PEM (std::string_view pem) |
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 51 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 elliptic curve from the specified parameters
This is used for example to create custom (application-specific) curves.
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 355 of file ec_group.cpp.
References Botan::b, and Botan::ExternalSource.
Botan::EC_Group::EC_Group | ( | const OID & | oid, |
const BigInt & | p, | ||
const BigInt & | a, | ||
const BigInt & | b, | ||
const BigInt & | base_x, | ||
const BigInt & | base_y, | ||
const BigInt & | order ) |
Construct elliptic curve from the specified parameters
This is used for example to create custom (application-specific) curves.
Unlike the deprecated constructor, this constructor imposes additional restrictions on the parameters, namely:
oid | an object identifier used to identify this curve |
p | the elliptic curve prime (at most 521 bits) |
a | the elliptic curve a param |
b | the elliptic curve b param |
base_x | the x coordinate of the group generator |
base_y | the y coordinate of the group generator |
order | the order of the group |
Definition at line 367 of file ec_group.cpp.
References Botan::abs(), Botan::b, Botan::BigInt::bits(), BOTAN_ARG_CHECK, Botan::ExternalSource, Botan::OID::has_value(), Botan::is_bailie_psw_probable_prime(), and Botan::BigInt::power_of_2().
|
explicit |
Decode a BER encoded ECC domain parameter set
ber | the bytes of the BER encoding |
Definition at line 405 of file ec_group.cpp.
References Botan::ExternalSource.
|
inline |
Definition at line 131 of file ec_group.h.
|
inlineexplicit |
Create an EC domain by OID (or throw if unknown)
oid | the OID of the EC domain to create |
Definition at line 137 of file ec_group.h.
|
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 321 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 from_name(), from_OID(), and from_PEM().
|
default |
|
default |
|
default |
|
inline |
Definition at line 370 of file ec_group.h.
Referenced by Botan::EC_AffinePoint::deserialize(), Botan::EC_Scalar::deserialize(), Botan::EC_AffinePoint::EC_AffinePoint(), Botan::EC_Scalar::EC_Scalar(), Botan::EC_Scalar::from_bigint(), Botan::EC_Scalar::from_bytes_mod_order(), Botan::EC_Scalar::from_bytes_with_trunc(), Botan::EC_AffinePoint::hash_to_curve_nu(), Botan::EC_AffinePoint::hash_to_curve_ro(), Botan::EC_Scalar::one(), and Botan::EC_Scalar::random().
|
inline |
|
inline |
|
inline |
Blinded point multiplication, attempts resistance to side channels
k_bn | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 427 of file ec_group.h.
|
inline |
Blinded point multiplication, attempts resistance to side channels Returns just the x coordinate of the point
k_bn | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 444 of file ec_group.h.
|
inline |
Blinded point multiplication, attempts resistance to side channels
point | input point |
k_bn | the scalar |
rng | a random number generator |
ws | a temp workspace |
Definition at line 458 of file ec_group.h.
|
static |
Definition at line 182 of file ec_group.cpp.
Definition at line 586 of file ec_group.h.
std::vector< uint8_t > Botan::EC_Group::DER_encode | ( | ) | const |
Create the DER encoding of this domain, using namedCurve format
Definition at line 486 of file ec_group.cpp.
Referenced by DER_encode(), and PEM_encode().
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 496 of file ec_group.cpp.
References DER_encode(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::Explicit, get_a(), get_b(), get_base_point(), get_cofactor(), get_order(), get_p(), get_p_bytes(), Botan::ImplicitCA, Botan::NamedCurve, Botan::OctetString, Botan::DER_Encoder::start_sequence(), and Botan::Uncompressed.
Referenced by Botan::EC_PublicKey::DER_domain(), and Botan::TLS::Signature_Scheme::key_algorithm_identifier().
|
inlinestatic |
Definition at line 164 of file ec_group.h.
Definition at line 356 of file ec_named.cpp.
References Botan::BigInt::word_at().
|
static |
Definition at line 15 of file ec_named.cpp.
|
static |
Initialize an EC group from a group common name (eg "secp256r1")
Definition at line 307 of file ec_group.cpp.
References EC_Group(), Botan::fmt(), Botan::OID::from_name(), and name.
Referenced by Botan::create_private_key(), Botan::TLS::Signature_Scheme::key_algorithm_identifier(), Botan::TLS::Callbacks::tls_deserialize_peer_public_key(), and Botan::TLS::Callbacks::tls_generate_ephemeral_key().
Initialize an EC group from a group named by an object identifier
Definition at line 296 of file ec_group.cpp.
References EC_Group(), Botan::fmt(), and Botan::OID::to_string().
Referenced by Botan::GOST_3410_PublicKey::GOST_3410_PublicKey().
|
static |
Initialize an EC group from the PEM/ASN.1 encoding
Definition at line 350 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), and EC_Group().
const EC_Point & Botan::EC_Group::generator | ( | ) | const |
Return the canonical group generator
Definition at line 450 of file ec_group.cpp.
const BigInt & Botan::EC_Group::get_a | ( | ) | const |
Return the a parameter of the elliptic curve equation
Definition at line 438 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), operator==(), and verify_group().
const BigInt & Botan::EC_Group::get_b | ( | ) | const |
Return the b parameter of the elliptic curve equation
Definition at line 442 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), operator==(), and verify_group().
const EC_Point & Botan::EC_Group::get_base_point | ( | ) | const |
Return group base point
Definition at line 446 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_AffinePoint::generator(), and verify_group().
const BigInt & Botan::EC_Group::get_cofactor | ( | ) | const |
Return the cofactor
Definition at line 466 of file ec_group.cpp.
Referenced by DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), 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 478 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), and Botan::TPM2::EC_PrivateKey::create_unrestricted_transient().
const BigInt & Botan::EC_Group::get_g_x | ( | ) | const |
Return the x coordinate of the base point
Definition at line 458 of file ec_group.cpp.
Referenced by Botan::EC_PublicKey::get_int_field(), and operator==().
const BigInt & Botan::EC_Group::get_g_y | ( | ) | const |
Return the y coordinate of the base point
Definition at line 462 of file ec_group.cpp.
Referenced by Botan::EC_PublicKey::get_int_field(), and operator==().
const BigInt & Botan::EC_Group::get_order | ( | ) | const |
Return the order of the base point
Definition at line 454 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), operator==(), 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 426 of file ec_group.cpp.
size_t Botan::EC_Group::get_order_bytes | ( | ) | const |
Return the size of the group order in bytes (same as get_order().bytes())
Definition at line 430 of file ec_group.cpp.
Referenced by Botan::ECIES_KA_Operation::derive_secret().
const BigInt & Botan::EC_Group::get_p | ( | ) | const |
Return the prime modulus of the field
Definition at line 434 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_AffinePoint::from_bigint_xy(), Botan::EC_PublicKey::get_int_field(), 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 418 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algo_name(), Botan::GOST_3410_PrivateKey::GOST_3410_PrivateKey(), and Botan::EC_PublicKey::key_length().
size_t Botan::EC_Group::get_p_bytes | ( | ) | const |
Return the size of p in bytes (same as get_p().bytes())
Definition at line 422 of file ec_group.cpp.
Referenced by DER_encode(), and Botan::EC_AffinePoint::from_bigint_xy().
bool Botan::EC_Group::has_cofactor | ( | ) | const |
Return true if the cofactor is > 1
Definition at line 470 of file ec_group.cpp.
Referenced by verify_public_element().
|
inline |
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 488 of file ec_group.h.
|
inline |
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 517 of file ec_group.h.
|
inline |
Definition at line 181 of file ec_group.h.
Definition at line 550 of file ec_group.h.
|
static |
Return a set of known named EC groups
Definition at line 476 of file ec_named.cpp.
Definition at line 474 of file ec_group.cpp.
Definition at line 566 of file ec_group.h.
|
inline |
Definition at line 576 of file ec_group.h.
bool Botan::EC_Group::operator== | ( | const EC_Group & | other | ) | const |
Definition at line 534 of file ec_group.cpp.
References get_a(), get_b(), get_cofactor(), get_g_x(), get_g_y(), get_order(), and get_p().
|
inline |
OS2ECP (Octet String To Elliptic Curve Point)
Deserialize an encoded point. Verifies that the point is on the curve.
Definition at line 377 of file ec_group.h.
|
inline |
Definition at line 381 of file ec_group.h.
References Botan::EC_AffinePoint::to_legacy_point().
std::string Botan::EC_Group::PEM_encode | ( | ) | const |
Return the PEM encoding (always in explicit form)
Definition at line 529 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 594 of file ec_group.h.
Referenced by verify_public_element().
|
inline |
Multi exponentiate. Not constant time.
Definition at line 404 of file ec_group.h.
References Botan::EC_Group::Mul2Table::mul2_vartime().
|
inline |
Definition at line 609 of file ec_group.h.
|
inline |
Return a random scalar ie an integer in [1,order)
Definition at line 470 of file ec_group.h.
EC_Group_Source Botan::EC_Group::source | ( | ) | const |
Definition at line 557 of file ec_group.h.
|
inline |
Return true if this EC_Group was derived from an explicit encoding
Explicit encoding of groups is deprecated; when support for explicit curves is removed in a future major release, this function will also be removed.
Definition at line 199 of file ec_group.h.
Referenced by botan_pubkey_ecc_key_used_explicit_encoding().
bool Botan::EC_Group::verify_group | ( | RandomNumberGenerator & | rng, |
bool | strong = false ) const |
Verify EC_Group domain
Definition at line 569 of file ec_group.cpp.
References Botan::abs(), Botan::b, Botan::BigInt::bits(), 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 544 of file ec_group.cpp.
References get_cofactor(), get_order(), has_cofactor(), Botan::EC_Point::is_zero(), Botan::EC_Point::on_the_curve(), and point().
Referenced by Botan::EC_PublicKey::check_key().
|
inline |
Return the zero (or infinite) point on this curve
Definition at line 605 of file ec_group.h.