Botan 2.19.3
Crypto and TLS for C&
|
#include <ec_group.h>
Public Member Functions | |
bool | a_is_minus_3 () const |
bool | a_is_zero () const |
PointGFp | 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 |
PointGFp | blinded_var_point_multiply (const PointGFp &point, const BigInt &k, RandomNumberGenerator &rng, std::vector< BigInt > &ws) 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 CurveGFp &curve, const PointGFp &base_point, const BigInt &order, const BigInt &cofactor) | |
EC_Group (const EC_Group &)=default | |
EC_Group (const OID &oid) | |
EC_Group (const std::string &pem_or_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 | |
const BigInt & | get_a () const |
const BigInt & | get_b () const |
const PointGFp & | get_base_point () const |
const BigInt & | get_cofactor () const |
const CurveGFp & | get_curve () const |
const OID & | get_curve_oid () const |
const BigInt & | get_g_x () const |
const BigInt & | get_g_y () const |
std::string | get_oid () 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 | 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 |
template<typename Alloc > | |
PointGFp | OS2ECP (const std::vector< uint8_t, Alloc > &vec) const |
PointGFp | OS2ECP (const uint8_t bits[], size_t len) const |
std::string | PEM_encode () const |
PointGFp | point (const BigInt &x, const BigInt &y) const |
PointGFp | point_multiply (const BigInt &x, const PointGFp &pt, const BigInt &y) const |
size_t | point_size (PointGFp::Compression_Type 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 PointGFp &y) const |
PointGFp | zero_point () const |
~EC_Group () | |
Static Public Member Functions | |
static size_t | clear_registered_curve_data () |
static EC_Group | EC_Group_from_PEM (const std::string &pem) |
static std::shared_ptr< EC_Group_Data > | EC_group_info (const OID &oid) |
static const std::set< std::string > & | known_named_groups () |
static std::string | PEM_for_named_group (const std::string &name) |
Class representing an elliptic curve
The internal representation is stored in a shared_ptr, so copying an EC_Group is inexpensive.
Definition at line 45 of file ec_group.h.
|
inline |
Construct Domain paramers from specified parameters
curve | elliptic curve |
base_point | a base point |
order | the order of the base point |
cofactor | the cofactor |
Definition at line 57 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 429 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 442 of file ec_group.cpp.
References Botan::ExternalSource.
|
inline |
Definition at line 97 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 372 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 379 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), Botan::ExternalSource, Botan::OID::from_string(), and Botan::OID::has_value().
Botan::EC_Group::EC_Group | ( | ) |
Create an uninitialized EC_Group
Definition at line 363 of file ec_group.cpp.
Referenced by EC_Group_from_PEM().
Botan::EC_Group::~EC_Group | ( | ) |
Definition at line 367 of file ec_group.cpp.
|
default |
|
default |
bool Botan::EC_Group::a_is_minus_3 | ( | ) | const |
Return if a == -3 mod p
Definition at line 459 of file ec_group.cpp.
References Botan::CurveGFp::a_is_minus_3().
bool Botan::EC_Group::a_is_zero | ( | ) | const |
Return if a == 0 mod p
Definition at line 464 of file ec_group.cpp.
PointGFp 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 590 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 597 of file ec_group.cpp.
References Botan::PointGFp::get_affine_x(), and Botan::PointGFp::is_zero().
PointGFp Botan::EC_Group::blinded_var_point_multiply | ( | const PointGFp & | 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 613 of file ec_group.cpp.
References get_order(), Botan::PointGFp_Var_Point_Precompute::mul(), and point().
|
static |
Definition at line 269 of file ec_group.cpp.
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 628 of file ec_group.cpp.
References Botan::EC_DOMPAR_ENC_EXPLICIT, Botan::EC_DOMPAR_ENC_IMPLICITCA, Botan::EC_DOMPAR_ENC_OID, Botan::OID::empty(), Botan::DER_Encoder::encode(), Botan::BigInt::encode_1363(), Botan::DER_Encoder::encode_null(), Botan::DER_Encoder::end_cons(), get_a(), get_b(), get_base_point(), get_cofactor(), get_curve_oid(), get_order(), get_p(), get_p_bytes(), Botan::OCTET_STRING, Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), and Botan::PointGFp::UNCOMPRESSED.
Referenced by PEM_encode().
|
static |
Definition at line 409 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), and EC_Group().
|
static |
Definition at line 13 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 494 of file ec_group.cpp.
Referenced by DER_encode(), 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 499 of file ec_group.cpp.
Referenced by DER_encode(), operator==(), Botan::sm2_compute_za(), and verify_group().
const PointGFp & Botan::EC_Group::get_base_point | ( | ) | const |
Return group base point
Definition at line 504 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 524 of file ec_group.cpp.
Referenced by DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), Botan::ECIES_Decryptor::ECIES_Decryptor(), verify_group(), and verify_public_element().
const CurveGFp & Botan::EC_Group::get_curve | ( | ) | const |
Return domain parameter curve
Definition at line 454 of file ec_group.cpp.
const OID & Botan::EC_Group::get_curve_oid | ( | ) | const |
Return the OID of these domain parameters
Definition at line 554 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algorithm_identifier(), DER_encode(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::EC_PublicKey::EC_PublicKey(), 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 514 of file ec_group.cpp.
Referenced by 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 519 of file ec_group.cpp.
Referenced by operator==(), and Botan::sm2_compute_za().
|
inline |
Return the OID of these domain parameters
Definition at line 260 of file ec_group.h.
const BigInt & Botan::EC_Group::get_order | ( | ) | const |
Return the order of the base point
Definition at line 509 of file ec_group.cpp.
Referenced by blinded_var_point_multiply(), DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), Botan::ECIES_Decryptor::ECIES_Decryptor(), 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 479 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 484 of file ec_group.cpp.
const BigInt & Botan::EC_Group::get_p | ( | ) | const |
Return the prime modulus of the field
Definition at line 489 of file ec_group.cpp.
Referenced by DER_encode(), 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 469 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 474 of file ec_group.cpp.
Referenced by DER_encode(), point_size(), and Botan::sm2_compute_za().
|
inline |
Definition at line 336 of file ec_group.h.
Definition at line 549 of file ec_group.cpp.
Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::SM2_PrivateKey::SM2_PrivateKey(), and Botan::SM2_PrivateKey::SM2_PrivateKey().
|
static |
Return a set of known named EC groups
Definition at line 268 of file ec_named.cpp.
Definition at line 529 of file ec_group.cpp.
Definition at line 539 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 544 of file ec_group.cpp.
bool Botan::EC_Group::operator== | ( | const EC_Group & | other | ) | const |
Definition at line 685 of file ec_group.cpp.
References get_a(), get_b(), get_g_x(), get_g_y(), and get_p().
|
inline |
Definition at line 331 of file ec_group.h.
References Botan::OS2ECP().
PointGFp Botan::EC_Group::OS2ECP | ( | const uint8_t | bits[], |
size_t | len | ||
) | const |
Definition at line 573 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_ecdh_agree().
std::string Botan::EC_Group::PEM_encode | ( | ) | const |
Return the PEM encoding (always in explicit form)
Definition at line 679 of file ec_group.cpp.
References DER_encode(), Botan::EC_DOMPAR_ENC_EXPLICIT, and Botan::PEM_Code::encode().
Referenced by PEM_for_named_group().
|
static |
Return PEM representation of named EC group Deprecated: Use EC_Group(name).PEM_encode() if this is needed
Definition at line 416 of file ec_group.cpp.
References name, and PEM_encode().
Return a point on this curve with the affine values x, y
Definition at line 578 of file ec_group.cpp.
Referenced by blinded_var_point_multiply(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), and verify_public_element().
PointGFp Botan::EC_Group::point_multiply | ( | const BigInt & | x, |
const PointGFp & | pt, | ||
const BigInt & | y | ||
) | const |
Multi exponentiate. Not constant time.
Definition at line 584 of file ec_group.cpp.
References get_base_point(), and Botan::PointGFp_Multi_Point_Precompute::multi_exp().
size_t Botan::EC_Group::point_size | ( | PointGFp::Compression_Type | format | ) | const |
Definition at line 564 of file ec_group.cpp.
References Botan::PointGFp::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 608 of file ec_group.cpp.
References get_order(), and Botan::BigInt::random_integer().
Referenced by Botan::EC_PrivateKey::EC_PrivateKey().
EC_Group_Source Botan::EC_Group::source | ( | ) | const |
Definition at line 559 of file ec_group.cpp.
Referenced by verify_group().
Definition at line 534 of file ec_group.cpp.
bool Botan::EC_Group::verify_group | ( | RandomNumberGenerator & | rng, |
bool | strong = false |
||
) | const |
Verify EC_Group domain
Definition at line 724 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::PointGFp::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 PointGFp & | 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 701 of file ec_group.cpp.
References get_cofactor(), get_order(), Botan::PointGFp::is_zero(), Botan::PointGFp::on_the_curve(), and point().
Referenced by Botan::EC_PublicKey::check_key().
PointGFp Botan::EC_Group::zero_point | ( | ) | const |
Return the zero (or infinite) point on this curve
Definition at line 622 of file ec_group.cpp.