|
Botan 3.12.0
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 der[], size_t der_len) | |
| EC_Group (EC_Group &&)=default | |
| EC_Group (std::span< const uint8_t > der) | |
| 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 (EC_Group_Encoding form=EC_Group_Encoding::Explicit) 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_application_specific_group_with_cofactor () |
| static bool | supports_named_group (std::string_view name) |
| static bool | unregister (const OID &oid) |
Class representing an elliptic curve
The internal representation is stored in a shared_ptr, so copying an EC_Group is inexpensive.
Definition at line 69 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 516 of file ec_group.cpp.
References Botan::ExternalSource, and Botan::OID::has_value().
Referenced by EC_Group(), EC_Group(), EC_Group(), EC_Group(), EC_Group(), EC_Group_from_PEM(), from_name(), from_OID(), from_PEM(), operator=(), operator=(), operator==(), and ~EC_Group().
| 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 533 of file ec_group.cpp.
References Botan::abs(), Botan::BigInt::bits(), BOTAN_ARG_CHECK, Botan::ExternalSource, Botan::Barrett_Reduction::for_public_modulus(), Botan::BigInt::from_s32(), 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 DER encoded ECC domain parameter set
| der | the bytes of the DER encoding |
Definition at line 605 of file ec_group.cpp.
References Botan::ExternalSource.
|
inline |
Definition at line 166 of file ec_group.h.
References EC_Group().
|
inlineexplicit |
Create an EC domain by OID (or throw if unknown)
| oid | the OID of the EC domain to create |
Definition at line 172 of file ec_group.h.
References EC_Group(), and from_OID().
|
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 482 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
References EC_Group(), and unregister().
Referenced by from_name(), from_OID(), and from_PEM().
|
default |
References EC_Group().
|
default |
References EC_Group().
|
default |
References EC_Group().
|
inline |
Definition at line 458 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 |
Return if a == -3 mod p
Definition at line 650 of file ec_group.h.
References a_is_minus_3(), get_a(), and get_p().
Referenced by a_is_minus_3().
|
inline |
Return if a == 0 mod p
Definition at line 655 of file ec_group.h.
References a_is_zero(), and get_a().
Referenced by a_is_zero().
|
static |
Definition at line 233 of file ec_group.cpp.
Definition at line 703 of file ec_group.h.
References cube_mod_order(), and Botan::EC_Scalar::from_bigint().
Referenced by cube_mod_order().
| std::vector< uint8_t > Botan::EC_Group::DER_encode | ( | ) | const |
Create the DER encoding of this domain, using namedCurve format
Definition at line 719 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 729 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().
|
inlinestatic |
Definition at line 199 of file ec_group.h.
References BOTAN_DEPRECATED, EC_Group(), EC_Group_from_PEM(), and from_PEM().
Referenced by EC_Group_from_PEM().
Definition at line 357 of file ec_named.cpp.
References Botan::BigInt::word_at().
|
static |
Definition at line 16 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 715 of file ec_group.cpp.
|
static |
Initialize an EC group from a group common name (eg "secp256r1")
Definition at line 468 of file ec_group.cpp.
References EC_Group(), EC_Group(), Botan::fmt(), and Botan::OID::from_name().
Referenced by botan_ec_group_from_name(), Botan::create_private_key(), 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 457 of file ec_group.cpp.
References EC_Group(), EC_Group(), Botan::fmt(), and Botan::OID::to_string().
Referenced by botan_ec_group_from_oid(), EC_Group(), and Botan::GOST_3410_PublicKey::GOST_3410_PublicKey().
|
static |
Initialize an EC group from the PEM/ASN.1 encoding
Definition at line 511 of file ec_group.cpp.
References Botan::PEM_Code::decode_check_label(), EC_Group(), and EC_Group().
Referenced by botan_ec_group_from_pem(), and EC_Group_from_PEM().
| const BigInt & Botan::EC_Group::get_a | ( | ) | const |
Return the a parameter of the elliptic curve equation
Definition at line 643 of file ec_group.cpp.
Referenced by a_is_minus_3(), a_is_zero(), 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 647 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 699 of file ec_group.cpp.
Referenced by DER_encode(), 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 707 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 691 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 695 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 687 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 631 of file ec_group.cpp.
Referenced by Botan::EC_Scalar::hash().
| 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 635 of file ec_group.cpp.
Referenced by Botan::ECDSA_PublicKey::_signature_element_size_for_DER_encoding(), Botan::GOST_3410_PublicKey::_signature_element_size_for_DER_encoding(), and Botan::SM2_PublicKey::_signature_element_size_for_DER_encoding().
| const BigInt & Botan::EC_Group::get_p | ( | ) | const |
Return the prime modulus of the field
Definition at line 639 of file ec_group.cpp.
Referenced by a_is_minus_3(), 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 623 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 627 of file ec_group.cpp.
Referenced by DER_encode(), Botan::EC_AffinePoint::from_bigint_xy(), point_size(), 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 703 of file ec_group.cpp.
|
inline |
Definition at line 226 of file ec_group.h.
References initialized().
Referenced by initialized().
Definition at line 667 of file ec_group.h.
References Botan::EC_Scalar::from_bigint(), and inverse_mod_order().
Referenced by inverse_mod_order().
|
static |
Return a set of known named EC groups
This returns a set of groups for which from_name should succeed.
Note that the set of included groups can vary based on the build configuration, and that this list does not include any groups registered by the application at runtime.
Definition at line 477 of file ec_named.cpp.
Referenced by supports_named_group().
Definition at line 660 of file ec_group.h.
References Botan::EC_Scalar::from_bytes_mod_order(), and mod_order().
Referenced by EC_Group(), and mod_order().
Definition at line 683 of file ec_group.h.
References Botan::EC_Scalar::from_bigint(), and multiply_mod_order().
Referenced by multiply_mod_order(), and multiply_mod_order().
|
inline |
Definition at line 693 of file ec_group.h.
References Botan::EC_Scalar::from_bigint(), and multiply_mod_order().
References EC_Group().
References EC_Group().
| bool Botan::EC_Group::operator== | ( | const EC_Group & | other | ) | const |
Definition at line 769 of file ec_group.cpp.
References EC_Group(), get_a(), get_b(), get_cofactor(), get_g_x(), get_g_y(), get_order(), and get_p().
| std::string Botan::EC_Group::PEM_encode | ( | EC_Group_Encoding | form = EC_Group_Encoding::Explicit | ) | const |
Return the PEM encoding
TODO(Botan4) remove the argument
Definition at line 764 of file ec_group.cpp.
References DER_encode(), and Botan::PEM_Code::encode().
|
inline |
Definition at line 708 of file ec_group.h.
References Botan::Compressed, get_p_bytes(), and point_size().
Referenced by point_size().
| EC_Group_Source Botan::EC_Group::source | ( | ) | const |
Definition at line 711 of file ec_group.cpp.
Referenced by verify_group().
Definition at line 674 of file ec_group.h.
References Botan::EC_Scalar::from_bigint(), and square_mod_order().
Referenced by square_mod_order().
|
static |
Return true if in this build configuration it is possible to register an application specific elliptic curve.
Definition at line 439 of file ec_group.cpp.
Referenced by botan_ec_group_supports_application_specific_group().
|
static |
Return true if in this build configuration it is possible to register an application specific elliptic curve with a cofactor larger than 1.
Definition at line 448 of file ec_group.cpp.
|
static |
Return true if EC_Group::from_name(name) should succeed for this name either because it is a group compiled into the library or it is a group which has already been registered by the application at runtime.
Definition at line 412 of file ec_group.cpp.
References Botan::OID::from_name(), and known_named_groups().
Referenced by botan_ec_group_supports_named_group(), and Botan::create_private_key().
|
static |
Unregister a previously registered group.
Using this is discouraged for normal use. This is only useful or necessary if you are registering a very large number of distinct groups, and need to worry about memory constraints.
Returns true if the group was found and unregistered.
Definition at line 612 of file ec_group.cpp.
Referenced by botan_ec_group_unregister(), and EC_Group().
|
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 264 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 779 of file ec_group.cpp.
References Botan::abs(), Botan::BigInt::bits(), Botan::Builtin, Botan::Barrett_Reduction::for_public_modulus(), Botan::BigInt::from_s32(), 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().