Botan 3.9.0
Crypto and TLS for C&
|
#include <ec_point.h>
Public Types | |
enum | : uint8_t { WORKSPACE_SIZE = 8 } |
typedef EC_Point_Format | Compression_Type |
Public Member Functions | |
bool | _is_x_eq_to_v_mod_order (const BigInt &v) const |
void | add (const EC_Point &other, std::vector< BigInt > &workspace) |
void | add (const word x_words[], size_t x_size, const word y_words[], size_t y_size, const word z_words[], size_t z_size, std::vector< BigInt > &workspace) |
void | add_affine (const EC_Point &other, std::vector< BigInt > &workspace) |
void | add_affine (const word x_words[], size_t x_size, const word y_words[], size_t y_size, std::vector< BigInt > &workspace) |
EC_Point | double_of (std::vector< BigInt > &workspace) const |
EC_Point ()=default | |
EC_Point (const CurveGFp &curve) | |
EC_Point (const CurveGFp &curve, BigInt x, BigInt y) | |
EC_Point (const EC_Point &)=default | |
EC_Point (EC_Point &&other) noexcept | |
std::vector< uint8_t > | encode (EC_Point_Format format) const |
void | force_affine () |
BigInt | get_affine_x () const |
BigInt | get_affine_y () const |
const CurveGFp & | get_curve () const |
const BigInt & | get_x () const |
const BigInt & | get_y () const |
const BigInt & | get_z () const |
bool | is_affine () const |
bool | is_zero () const |
EC_Point | mul (const BigInt &scalar) const |
void | mult2 (std::vector< BigInt > &workspace) |
void | mult2i (size_t i, std::vector< BigInt > &workspace) |
EC_Point & | negate () |
bool | on_the_curve () const |
bool | operator!= (const EC_Point &other) const =default |
EC_Point & | operator*= (const BigInt &scalar) |
EC_Point & | operator+= (const EC_Point &rhs) |
EC_Point & | operator-= (const EC_Point &rhs) |
EC_Point & | operator= (const EC_Point &)=default |
EC_Point & | operator= (EC_Point &&other) noexcept |
bool | operator== (const EC_Point &other) const |
EC_Point | plus (const EC_Point &other, std::vector< BigInt > &workspace) const |
void | randomize_repr (RandomNumberGenerator &rng) |
void | randomize_repr (RandomNumberGenerator &rng, secure_vector< word > &ws) |
void | swap (EC_Point &other) noexcept |
void | swap_coords (BigInt &new_x, BigInt &new_y, BigInt &new_z) |
secure_vector< uint8_t > | x_bytes () const |
secure_vector< uint8_t > | xy_bytes () const |
secure_vector< uint8_t > | y_bytes () const |
EC_Point | zero () const |
~EC_Point ()=default |
Static Public Member Functions | |
static void | force_all_affine (std::span< EC_Point > points, secure_vector< word > &ws) |
Friends | |
class | EC_Point_Base_Point_Precompute |
class | EC_Point_Multi_Point_Precompute |
class | EC_Point_Var_Point_Precompute |
void | swap (EC_Point &x, EC_Point &y) noexcept |
Deprecated elliptic curve type
Use EC_AffinePoint in new code; this type is no longer used internally at all except to support very unfortunate (and deprecated) curve types, specifically those with a cofactor, or with unreasonable sizes (above 521 bits), which cannot be accomodated by the new faster EC library in math/pcurves. For normal curves EC_AffinePoint will typically be 2 or 3 times faster.
This type will be completely removed in Botan4
Definition at line 33 of file ec_point.h.
Definition at line 39 of file ec_point.h.
anonymous enum : uint8_t |
Enumerator | |
---|---|
WORKSPACE_SIZE |
Definition at line 42 of file ec_point.h.
|
default |
Construct an uninitialized EC_Point
References EC_Point().
Referenced by add(), add_affine(), double_of(), EC_Point(), EC_Point(), EC_Point(), EC_Point(), force_all_affine(), mul(), mult2(), mult2i(), negate(), operator!=(), operator*=(), operator+=(), operator-=(), operator=(), operator=(), operator==(), plus(), swap(), swap, zero(), and ~EC_Point().
|
explicit |
Construct the zero point
curve | The base curve |
Definition at line 108 of file ec_point.cpp.
References EC_Point().
|
default |
Copy constructor
References EC_Point().
|
inlinenoexcept |
Move Constructor
Definition at line 63 of file ec_point.h.
References EC_Point(), and swap().
|
default |
References EC_Point(), encode(), and mul().
Construct a point from its affine coordinates
curve | the base curve |
x | affine x coordinate |
y | affine y coordinate |
Definition at line 114 of file ec_point.cpp.
bool Botan::EC_Point::_is_x_eq_to_v_mod_order | ( | const BigInt & | v | ) | const |
For internal use only
Definition at line 714 of file ec_point.cpp.
References get_affine_x(), get_x(), get_z(), and is_zero().
Referenced by operator!=().
Point addition
other | the point to add to *this |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 266 of file ec_point.cpp.
References Botan::BigInt::_data(), add(), BOTAN_ARG_CHECK, EC_Point(), and Botan::BigInt::size().
Referenced by add(), mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), operator+=(), and plus().
void Botan::EC_Point::add | ( | const word | x_words[], |
size_t | x_size, | ||
const word | y_words[], | ||
size_t | y_size, | ||
const word | z_words[], | ||
size_t | z_size, | ||
std::vector< BigInt > & | workspace ) |
Point addition. Array version.
x_words | the words of the x coordinate of the other point |
x_size | size of x_words |
y_words | the words of the y coordinate of the other point |
y_size | size of y_words |
z_words | the words of the z coordinate of the other point |
z_size | size of z_words |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 280 of file ec_point.cpp.
References Botan::CT::all_zeros(), Botan::BigInt::is_zero(), is_zero(), Botan::BigInt::mod_sub(), and mult2().
Point addition - mixed J+A
other
is affine, if this is not correct the result will be invalid.other | affine point to add - assumed to be affine! |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 175 of file ec_point.cpp.
References Botan::BigInt::_data(), add_affine(), BOTAN_ASSERT_NOMSG, BOTAN_DEBUG_ASSERT, EC_Point(), is_affine(), and Botan::BigInt::size().
Referenced by add_affine(), Botan::EC_Point_Base_Point_Precompute::mul(), and Botan::EC_Point_Multi_Point_Precompute::multi_exp().
void Botan::EC_Point::add_affine | ( | const word | x_words[], |
size_t | x_size, | ||
const word | y_words[], | ||
size_t | y_size, | ||
std::vector< BigInt > & | workspace ) |
Point addition - mixed J+A. Array version.
x_words | the words of the x coordinate of the other point |
x_size | size of x_words |
y_words | the words of the y coordinate of the other point |
y_size | size of y_words |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 187 of file ec_point.cpp.
References Botan::CT::all_zeros(), Botan::BigInt::is_zero(), is_zero(), Botan::BigInt::mod_sub(), mult2(), and Botan::BigInt::swap().
Point doubling
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 350 of file ec_point.h.
References EC_Point(), and mult2().
std::vector< uint8_t > Botan::EC_Point::encode | ( | EC_Point_Format | format | ) | const |
EC2OSP - elliptic curve to octet string primitive
format | which format to encode using |
Definition at line 802 of file ec_point.cpp.
References Botan::BufferStuffer::append(), Botan::Compressed, get_affine_x(), get_affine_y(), Botan::BigInt::get_bit(), Botan::Hybrid, is_zero(), Botan::BufferStuffer::next(), Botan::BigInt::serialize_to(), and Botan::Uncompressed.
Referenced by ~EC_Point().
void Botan::EC_Point::force_affine | ( | ) |
Force this point to affine coordinates
Convert the point to its equivalent affine coordinates. Throws if this is the point at infinity.
Definition at line 584 of file ec_point.cpp.
References is_zero().
|
static |
Force all points on the list to affine coordinates
Force several points to be affine at once. Uses Montgomery's trick to reduce number of inversions required, so this is much faster than calling force_affine on each point in sequence.
Definition at line 520 of file ec_point.cpp.
References EC_Point().
Referenced by Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), and Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute().
BigInt Botan::EC_Point::get_affine_x | ( | ) | const |
get affine x coordinate
Definition at line 631 of file ec_point.cpp.
References is_affine(), and is_zero().
Referenced by _is_x_eq_to_v_mod_order(), encode(), operator==(), and xy_bytes().
BigInt Botan::EC_Point::get_affine_y | ( | ) | const |
get affine y coordinate
Definition at line 653 of file ec_point.cpp.
References is_affine(), and is_zero().
Referenced by encode(), operator==(), and xy_bytes().
|
inline |
Return base curve of this point
You should not need to use this
Definition at line 362 of file ec_point.h.
References get_curve().
Referenced by get_curve().
|
inline |
Return the internal x coordinate
Note this may be in Montgomery form
Definition at line 239 of file ec_point.h.
References get_x().
Referenced by _is_x_eq_to_v_mod_order(), and get_x().
|
inline |
Return the internal y coordinate
Note this may be in Montgomery form
Definition at line 246 of file ec_point.h.
References get_y().
Referenced by get_y().
|
inline |
Return the internal z coordinate
Note this may be in Montgomery form
Definition at line 253 of file ec_point.h.
References get_z().
Referenced by _is_x_eq_to_v_mod_order(), and get_z().
bool Botan::EC_Point::is_affine | ( | ) | const |
Definition at line 601 of file ec_point.cpp.
Referenced by add_affine(), get_affine_x(), and get_affine_y().
|
inline |
Is this the point at infinity?
Definition at line 164 of file ec_point.h.
Referenced by _is_x_eq_to_v_mod_order(), add(), add_affine(), encode(), force_affine(), get_affine_x(), get_affine_y(), mult2(), negate(), on_the_curve(), operator-=(), and operator==().
Point multiplication operator
Simple unblinded Montgomery ladder
Warning: prefer the functions on EC_Group such as blinded_var_point_multiply
scalar | the scalar value |
Definition at line 497 of file ec_point.cpp.
References add(), Botan::BigInt::bits(), BOTAN_DEBUG_ASSERT, EC_Point(), Botan::BigInt::get_bit(), Botan::BigInt::is_negative(), mult2(), negate(), on_the_curve(), WORKSPACE_SIZE, and zero().
Referenced by Botan::operator*(), Botan::operator*(), and ~EC_Point().
void Botan::EC_Point::mult2 | ( | std::vector< BigInt > & | workspace | ) |
Point doubling
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 388 of file ec_point.cpp.
References EC_Point(), is_zero(), Botan::BigInt::mod_add(), Botan::BigInt::mod_sub(), and Botan::BigInt::swap().
Referenced by add(), add_affine(), double_of(), Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute(), mul(), and mult2i().
void Botan::EC_Point::mult2i | ( | size_t | i, |
std::vector< BigInt > & | workspace ) |
Repeated point doubling
i | number of doublings to perform |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 368 of file ec_point.cpp.
References EC_Point(), and mult2().
Referenced by Botan::EC_Point_Var_Point_Precompute::mul(), and Botan::EC_Point_Multi_Point_Precompute::multi_exp().
|
inline |
Negate this point
Definition at line 134 of file ec_point.h.
References EC_Point(), is_zero(), and negate().
Referenced by mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), negate(), and Botan::operator-().
bool Botan::EC_Point::on_the_curve | ( | ) | const |
Checks whether the point is to be found on the underlying curve; used to prevent fault attacks.
Definition at line 675 of file ec_point.cpp.
References is_zero().
Referenced by Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute(), mul(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::OS2ECP(), and Botan::EC_Group::verify_group().
|
default |
References _is_x_eq_to_v_mod_order(), EC_Point(), and swap().
*= Operator
scalar | the EC_Point to multiply with *this |
Definition at line 492 of file ec_point.cpp.
References EC_Point().
+= Operator
rhs | the EC_Point to add to the local value |
Definition at line 474 of file ec_point.cpp.
References add(), EC_Point(), and WORKSPACE_SIZE.
-= Operator
rhs | the EC_Point to subtract from the local value |
Definition at line 480 of file ec_point.cpp.
References EC_Point(), and is_zero().
Standard Assignment
References EC_Point().
bool Botan::EC_Point::operator== | ( | const EC_Point & | other | ) | const |
Equality operator
Definition at line 788 of file ec_point.cpp.
References EC_Point(), get_affine_x(), get_affine_y(), and is_zero().
|
inline |
Point addition
other | the point to add to *this |
workspace | temp space, at least WORKSPACE_SIZE elements |
Definition at line 339 of file ec_point.h.
References add(), and EC_Point().
Referenced by Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), and Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute().
void Botan::EC_Point::randomize_repr | ( | RandomNumberGenerator & | rng | ) |
Randomize the point representation The actual value (get_affine_x, get_affine_y) does not change
Definition at line 131 of file ec_point.cpp.
References randomize_repr().
Referenced by Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), and randomize_repr().
void Botan::EC_Point::randomize_repr | ( | RandomNumberGenerator & | rng, |
secure_vector< word > & | ws ) |
Randomize the point representation The actual value (get_affine_x, get_affine_y) does not change
Definition at line 137 of file ec_point.cpp.
References Botan::BigInt::from_s32(), Botan::RandomNumberGenerator::is_seeded(), and Botan::BigInt::random_integer().
|
noexcept |
swaps the states of *this and other
other | the object to swap values with |
Definition at line 781 of file ec_point.cpp.
References EC_Point().
Referenced by EC_Point(), Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), operator!=(), and operator=().
Definition at line 257 of file ec_point.h.
References swap_coords().
Referenced by swap_coords().
secure_vector< uint8_t > Botan::EC_Point::x_bytes | ( | ) | const |
Return the fixed length big endian encoding of x coordinate
Definition at line 606 of file ec_point.cpp.
References Botan::BigInt::encode_1363().
secure_vector< uint8_t > Botan::EC_Point::xy_bytes | ( | ) | const |
Return the fixed length concatenation of the x and y coordinates
Definition at line 622 of file ec_point.cpp.
References Botan::BigInt::encode_1363(), get_affine_x(), and get_affine_y().
secure_vector< uint8_t > Botan::EC_Point::y_bytes | ( | ) | const |
Return the fixed length big endian encoding of y coordinate
Definition at line 614 of file ec_point.cpp.
References Botan::BigInt::encode_1363().
EC_Point Botan::EC_Point::zero | ( | ) | const |
Return the zero (aka infinite) point associated with this curve
Definition at line 110 of file ec_point.cpp.
References EC_Point().
Referenced by Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute(), mul(), Botan::EC_Point_Base_Point_Precompute::mul(), and Botan::EC_Point_Multi_Point_Precompute::multi_exp().
|
friend |
Definition at line 37 of file ec_point.h.
References EC_Point_Base_Point_Precompute.
Referenced by EC_Point_Base_Point_Precompute.
|
friend |
Definition at line 36 of file ec_point.h.
References EC_Point_Multi_Point_Precompute.
Referenced by EC_Point_Multi_Point_Precompute.
|
friend |
Definition at line 35 of file ec_point.h.
References EC_Point_Var_Point_Precompute.
Referenced by EC_Point_Var_Point_Precompute.