Botan 3.7.1
Crypto and TLS for C&
|
#include <ec_apoint.h>
Public Member Functions | |
const std::shared_ptr< const EC_Group_Data > & | _group () const |
const EC_AffinePoint_Data & | _inner () const |
EC_AffinePoint | add (const EC_AffinePoint &q) const |
EC_AffinePoint (const EC_AffinePoint &other) | |
EC_AffinePoint (const EC_Group &group, std::span< const uint8_t > bytes) | |
EC_AffinePoint (EC_AffinePoint &&other) noexcept | |
size_t | field_element_bytes () const |
bool | is_identity () const |
Return true if this point is the identity element. | |
EC_AffinePoint | mul (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
secure_vector< uint8_t > | mul_x_only (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws) const |
EC_AffinePoint | negate () const |
Point negation. | |
bool | operator!= (const EC_AffinePoint &other) const |
EC_AffinePoint & | operator= (const EC_AffinePoint &other) |
EC_AffinePoint & | operator= (EC_AffinePoint &&other) noexcept |
bool | operator== (const EC_AffinePoint &other) const |
std::vector< uint8_t > | serialize (EC_Point_Format format) const |
Return an encoding depending on the requested format. | |
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>> | |
T | serialize_compressed () const |
void | serialize_compressed_to (std::span< uint8_t > bytes) const |
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>> | |
T | serialize_uncompressed () const |
void | serialize_uncompressed_to (std::span< uint8_t > bytes) const |
void | serialize_x_to (std::span< uint8_t > bytes) const |
void | serialize_xy_to (std::span< uint8_t > bytes) const |
void | serialize_y_to (std::span< uint8_t > bytes) const |
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>> | |
T | x_bytes () const |
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>> | |
T | xy_bytes () const |
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>> | |
T | y_bytes () const |
~EC_AffinePoint () | |
Static Public Member Functions | |
static EC_AffinePoint | _from_inner (std::unique_ptr< EC_AffinePoint_Data > inner) |
static std::optional< EC_AffinePoint > | deserialize (const EC_Group &group, std::span< const uint8_t > bytes) |
static std::optional< EC_AffinePoint > | from_bigint_xy (const EC_Group &group, const BigInt &x, const BigInt &y) |
static EC_AffinePoint | g_mul (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws) |
static EC_AffinePoint | generator (const EC_Group &group) |
Return the standard group generator. | |
static EC_AffinePoint | hash_to_curve_nu (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep) |
static EC_AffinePoint | hash_to_curve_ro (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep) |
static EC_AffinePoint | identity (const EC_Group &group) |
Return the identity element. | |
static std::optional< EC_AffinePoint > | mul_px_qy (const EC_AffinePoint &p, const EC_Scalar &x, const EC_AffinePoint &q, const EC_Scalar &y, RandomNumberGenerator &rng) |
Friends | |
class | EC_Mul2Table |
Elliptic Curve Point in Affine Representation
Definition at line 35 of file ec_apoint.h.
Botan::EC_AffinePoint::EC_AffinePoint | ( | const EC_Group & | group, |
std::span< const uint8_t > | bytes ) |
Point deserialization. Throws if wrong length or not a valid point
This accepts SEC1 compressed or uncompressed formats
Definition at line 35 of file ec_apoint.cpp.
References Botan::EC_Group::_data().
Referenced by _from_inner(), add(), deserialize(), g_mul(), hash_to_curve_nu(), hash_to_curve_ro(), identity(), mul(), mul_px_qy(), and negate().
Botan::EC_AffinePoint::EC_AffinePoint | ( | const EC_AffinePoint & | other | ) |
Definition at line 19 of file ec_apoint.cpp.
|
noexcept |
Definition at line 21 of file ec_apoint.cpp.
|
default |
|
static |
Definition at line 221 of file ec_apoint.cpp.
References EC_AffinePoint().
Referenced by Botan::EC_Group::Mul2Table::mul2_vartime().
const std::shared_ptr< const EC_Group_Data > & Botan::EC_AffinePoint::_group | ( | ) | const |
Definition at line 225 of file ec_apoint.cpp.
References Botan::EC_AffinePoint_Data::group().
Referenced by operator==().
|
inline |
Definition at line 237 of file ec_apoint.h.
Referenced by add(), mul_px_qy(), and negate().
EC_AffinePoint Botan::EC_AffinePoint::add | ( | const EC_AffinePoint & | q | ) | const |
Point addition
Note that this is quite slow since it converts the resulting projective point immediately to affine coordinates, which requires a field inversion. This can be sufficient when implementing protocols that just need to perform a few additions.
In the future a cooresponding EC_ProjectivePoint type may be added which would avoid the expensive affine conversions
Definition at line 171 of file ec_apoint.cpp.
References _inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().
|
static |
Point deserialization. Returns nullopt if wrong length or not a valid point
This accepts SEC1 compressed or uncompressed formats
Definition at line 135 of file ec_apoint.cpp.
References Botan::EC_Group::_data(), and EC_AffinePoint().
Referenced by from_bigint_xy().
size_t Botan::EC_AffinePoint::field_element_bytes | ( | ) | const |
Return the number of bytes of a field element
A point consists of two field elements, plus possibly a header
Definition at line 109 of file ec_apoint.cpp.
References Botan::EC_AffinePoint_Data::field_element_bytes().
|
static |
Create a point from a pair (x,y) of integers
The integers must be within the field - in the range [0,p) and must satisfy the curve equation
Definition at line 92 of file ec_apoint.cpp.
References deserialize(), Botan::EC_Group::get_p(), Botan::EC_Group::get_p_bytes(), Botan::BigInt::is_negative(), and Botan::BigInt::serialize_to().
Referenced by generator().
|
static |
Multiply by the group generator returning a complete point
Workspace argument is transitional
Definition at line 143 of file ec_apoint.cpp.
References Botan::EC_Scalar::_inner(), EC_AffinePoint(), and Botan::EC_Scalar_Data::group().
Referenced by Botan::EC_PrivateKey_Data::public_key().
|
static |
Return the standard group generator.
Definition at line 83 of file ec_apoint.cpp.
References from_bigint_xy(), Botan::EC_Group::get_g_x(), and Botan::EC_Group::get_g_y().
Referenced by Botan::EC_Group::DER_encode().
|
static |
Hash to curve (RFC 9380), non uniform variant
Only supported for specific groups
Definition at line 125 of file ec_apoint.cpp.
References Botan::EC_Group::_data(), and EC_AffinePoint().
|
static |
Hash to curve (RFC 9380), random oracle variant
Only supported for specific groups
Definition at line 117 of file ec_apoint.cpp.
References Botan::EC_Group::_data(), and EC_AffinePoint().
|
static |
Return the identity element.
Definition at line 78 of file ec_apoint.cpp.
References EC_AffinePoint().
bool Botan::EC_AffinePoint::is_identity | ( | ) | const |
Return true if this point is the identity element.
Definition at line 113 of file ec_apoint.cpp.
References Botan::EC_AffinePoint_Data::is_identity().
Referenced by Botan::EC_PublicKey::check_key(), Botan::ECIES_KA_Operation::derive_secret(), operator==(), serialize_compressed_to(), serialize_uncompressed_to(), serialize_x_to(), serialize_xy_to(), and serialize_y_to().
EC_AffinePoint Botan::EC_AffinePoint::mul | ( | const EC_Scalar & | scalar, |
RandomNumberGenerator & | rng, | ||
std::vector< BigInt > & | ws ) const |
Multiply a point by a scalar returning a complete point
Workspace argument is transitional
Definition at line 148 of file ec_apoint.cpp.
References Botan::EC_Scalar::_inner(), EC_AffinePoint(), and mul().
Referenced by mul().
|
static |
Compute 2-ary multiscalar multiplication - p*x + q*y
This operation runs in constant time with respect to p, x, q, and y
Definition at line 158 of file ec_apoint.cpp.
References _inner(), Botan::EC_Scalar::_inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().
secure_vector< uint8_t > Botan::EC_AffinePoint::mul_x_only | ( | const EC_Scalar & | scalar, |
RandomNumberGenerator & | rng, | ||
std::vector< BigInt > & | ws ) const |
Multiply a point by a scalar, returning the byte encoding of the x coordinate only
Workspace argument is transitional
Definition at line 152 of file ec_apoint.cpp.
References Botan::EC_Scalar::_inner(), and Botan::EC_AffinePoint_Data::mul_x_only().
EC_AffinePoint Botan::EC_AffinePoint::negate | ( | ) | const |
Point negation.
Definition at line 176 of file ec_apoint.cpp.
References _inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().
|
inline |
Definition at line 212 of file ec_apoint.h.
EC_AffinePoint & Botan::EC_AffinePoint::operator= | ( | const EC_AffinePoint & | other | ) |
Definition at line 23 of file ec_apoint.cpp.
References Botan::EC_AffinePoint_Data::clone().
|
noexcept |
Definition at line 30 of file ec_apoint.cpp.
bool Botan::EC_AffinePoint::operator== | ( | const EC_AffinePoint & | other | ) | const |
Definition at line 53 of file ec_apoint.cpp.
References _group(), BOTAN_ASSERT_NOMSG, Botan::CT::is_equal(), is_identity(), and serialize_uncompressed().
std::vector< uint8_t > Botan::EC_AffinePoint::serialize | ( | EC_Point_Format | format | ) | const |
Return an encoding depending on the requested format.
Definition at line 181 of file ec_apoint.cpp.
References Botan::Compressed, serialize_compressed(), serialize_uncompressed(), and Botan::Uncompressed.
Referenced by Botan::ECIES_KA_Operation::derive_secret(), Botan::ECDH_PublicKey::public_value(), and Botan::EC_PublicKey::raw_public_key_bits().
|
inline |
Return the bytes of the affine x and y coordinates in a container
This function will fail if this point is the identity element
Definition at line 204 of file ec_apoint.h.
References T.
Referenced by Botan::ECDSA_PublicKey::recovery_param(), and serialize().
void Botan::EC_AffinePoint::serialize_compressed_to | ( | std::span< uint8_t > | bytes | ) | const |
Write the fixed length SEC1 compressed encoding
The output span must be exactly 1 + field_element_bytes long
This function will fail if this point is the identity element
Definition at line 211 of file ec_apoint.cpp.
References BOTAN_STATE_CHECK, and is_identity().
|
inline |
Return the bytes of the affine x and y coordinates in a container
This function will fail if this point is the identity element
Definition at line 194 of file ec_apoint.h.
References T.
Referenced by Botan::EC_Group::DER_encode(), operator==(), and serialize().
void Botan::EC_AffinePoint::serialize_uncompressed_to | ( | std::span< uint8_t > | bytes | ) | const |
Return the fixed length encoding of SEC1 uncompressed encoding
The output span must be exactly 1 + 2*field_element_bytes long
This function will fail if this point is the identity element
Definition at line 216 of file ec_apoint.cpp.
References BOTAN_STATE_CHECK, and is_identity().
void Botan::EC_AffinePoint::serialize_x_to | ( | std::span< uint8_t > | bytes | ) | const |
Write the fixed length encoding of affine x coordinate
The output span must be exactly field_element_bytes long
This function will fail if this point is the identity element
Definition at line 196 of file ec_apoint.cpp.
References BOTAN_STATE_CHECK, and is_identity().
void Botan::EC_AffinePoint::serialize_xy_to | ( | std::span< uint8_t > | bytes | ) | const |
Write the fixed length encoding of affine x and y coordinates
The output span must be exactly 2*field_element_bytes long
This function will fail if this point is the identity element
Definition at line 206 of file ec_apoint.cpp.
References BOTAN_STATE_CHECK, and is_identity().
void Botan::EC_AffinePoint::serialize_y_to | ( | std::span< uint8_t > | bytes | ) | const |
Write the fixed length encoding of affine y coordinate
The output span must be exactly field_element_bytes long
This function will fail if this point is the identity element
Definition at line 201 of file ec_apoint.cpp.
References BOTAN_STATE_CHECK, and is_identity().
|
inline |
Return the bytes of the affine x coordinate in a container
This function will fail if this point is the identity element
Definition at line 164 of file ec_apoint.h.
References T.
|
inline |
Return the bytes of the affine x and y coordinates in a container
This function will fail if this point is the identity element
Definition at line 184 of file ec_apoint.h.
References T.
Referenced by Botan::GOST_3410_PublicKey::public_key_bits(), and Botan::sm2_compute_za().
|
inline |
Return the bytes of the affine y coordinate in a container
This function will fail if this point is the identity element
Definition at line 174 of file ec_apoint.h.
References T.
|
friend |
Definition at line 244 of file ec_apoint.h.