Botan 3.7.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 |
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) | |
EC_Group_Engine | engine () const |
const BigInt & | get_a () const |
const BigInt & | get_b () 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 |
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 |
std::string | PEM_encode () const |
size_t | point_size (EC_Point_Format format) 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 |
~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 () |
static bool | supports_application_specific_group () |
static bool | supports_named_group (std::string_view 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 87 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.
Some build configurations do not support application specific curves, in which case this constructor will throw an exception. You can check for this situation beforehand using the function EC_Group::supports_application_specific_group()
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 402 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.
Some build configurations do not support application specific curves, in which case this constructor will throw an exception. You can check for this situation beforehand using the function EC_Group::supports_application_specific_group()
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 414 of file ec_group.cpp.
References Botan::abs(), Botan::b, Botan::BigInt::bits(), BOTAN_ARG_CHECK, Botan::ExternalSource, Botan::Modular_Reducer::for_public_modulus(), Botan::OID::has_value(), Botan::is_bailie_psw_probable_prime(), mod_order(), Botan::BigInt::power_of_2(), and Botan::BigInt::set_bit().
|
explicit |
Decode a BER encoded ECC domain parameter set
ber | the bytes of the BER encoding |
Definition at line 485 of file ec_group.cpp.
References Botan::ExternalSource.
|
inline |
Definition at line 184 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 190 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 368 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 442 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 |
|
static |
Definition at line 182 of file ec_group.cpp.
Definition at line 689 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 594 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 604 of file ec_group.cpp.
References DER_encode(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::Explicit, Botan::EC_AffinePoint::generator(), get_a(), get_b(), get_cofactor(), get_order(), get_p(), get_p_bytes(), Botan::ImplicitCA, Botan::NamedCurve, Botan::OctetString, Botan::EC_AffinePoint::serialize_uncompressed(), and Botan::DER_Encoder::start_sequence().
Referenced by Botan::EC_PublicKey::DER_domain(), and Botan::TLS::Signature_Scheme::key_algorithm_identifier().
|
inlinestatic |
Definition at line 217 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.
EC_Group_Engine Botan::EC_Group::engine | ( | ) | const |
Return how this EC_Group is implemented under the hood
This is mostly useful for diagnostic or debugging purposes
Definition at line 590 of file ec_group.cpp.
|
static |
Initialize an EC group from a group common name (eg "secp256r1")
Definition at line 354 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 343 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 397 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), and EC_Group().
const BigInt & Botan::EC_Group::get_a | ( | ) | const |
Return the a parameter of the elliptic curve equation
Definition at line 518 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), 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 522 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), operator==(), Botan::sm2_compute_za(), and verify_group().
const BigInt & Botan::EC_Group::get_cofactor | ( | ) | const |
Return the cofactor
Definition at line 574 of file ec_group.cpp.
Referenced by DER_encode(), Botan::ECIES_KA_Operation::derive_secret(), Botan::EC_PublicKey::get_int_field(), operator==(), and verify_group().
const OID & Botan::EC_Group::get_curve_oid | ( | ) | const |
Return the OID of these domain parameters
Definition at line 582 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 566 of file ec_group.cpp.
Referenced by Botan::EC_AffinePoint::generator(), 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 570 of file ec_group.cpp.
Referenced by Botan::EC_AffinePoint::generator(), 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 562 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_PublicKey::get_int_field(), operator==(), and verify_group().
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 506 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 510 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::_signature_element_size_for_DER_encoding(), and Botan::ECIES_KA_Operation::derive_secret().
const BigInt & Botan::EC_Group::get_p | ( | ) | const |
Return the prime modulus of the field
Definition at line 514 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 498 of file ec_group.cpp.
Referenced by Botan::GOST_3410_PublicKey::algo_name(), 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 502 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_AffinePoint::from_bigint_xy(), and Botan::sm2_compute_za().
bool Botan::EC_Group::has_cofactor | ( | ) | const |
Return true if the cofactor is > 1 TODO(Botan4): Remove this
Definition at line 578 of file ec_group.cpp.
Referenced by Botan::ECIES_KA_Operation::derive_secret().
|
inline |
Definition at line 234 of file ec_group.h.
Definition at line 653 of file ec_group.h.
|
static |
Return a set of known named EC groups
This returns the set of groups for which from_name should succeed Note that the set of included groups can vary based on the build configuration.
Definition at line 481 of file ec_named.cpp.
Referenced by supports_named_group().
Definition at line 646 of file ec_group.h.
Referenced by EC_Group().
Definition at line 669 of file ec_group.h.
|
inline |
Definition at line 679 of file ec_group.h.
bool Botan::EC_Group::operator== | ( | const EC_Group & | other | ) | const |
Definition at line 644 of file ec_group.cpp.
References get_a(), get_b(), get_cofactor(), get_g_x(), get_g_y(), get_order(), and get_p().
std::string Botan::EC_Group::PEM_encode | ( | ) | const |
Return the PEM encoding (always in explicit form)
Definition at line 639 of file ec_group.cpp.
References DER_encode(), Botan::PEM_Code::encode(), and Botan::Explicit.
|
inline |
Definition at line 694 of file ec_group.h.
EC_Group_Source Botan::EC_Group::source | ( | ) | const |
Definition at line 660 of file ec_group.h.
|
static |
Return true if in this build configuration it is possible to register an application specific elliptic curve.
Definition at line 334 of file ec_group.cpp.
|
static |
Return true if in this build configuration EC_Group::from_name(name) will succeed
Definition at line 476 of file ec_named.cpp.
References known_named_groups(), and name.
Referenced by Botan::create_private_key().
|
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 263 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 654 of file ec_group.cpp.
References Botan::abs(), Botan::b, Botan::BigInt::bits(), Botan::Builtin, Botan::Modular_Reducer::for_public_modulus(), get_a(), get_b(), get_cofactor(), get_order(), get_p(), Botan::is_prime(), Botan::EC_Point::on_the_curve(), and source().
Referenced by Botan::EC_PublicKey::check_key().