Botan 3.6.1
Crypto and TLS for C&
|
#include <ec_scalar.h>
Public Member Functions | |
const EC_Scalar_Data & | _inner () const |
EC_Scalar | add (const EC_Scalar &x) const |
void | assign (const EC_Scalar &x) |
size_t | bytes () const |
EC_Scalar (const EC_Group &group, std::span< const uint8_t > bytes) | |
EC_Scalar (const EC_Scalar &other) | |
EC_Scalar (EC_Scalar &&other) noexcept | |
EC_Scalar | invert () const |
bool | is_eq (const EC_Scalar &x) const |
bool | is_nonzero () const |
bool | is_zero () const |
EC_Scalar | mul (const EC_Scalar &x) const |
EC_Scalar | negate () const |
EC_Scalar & | operator= (const EC_Scalar &other) |
EC_Scalar & | operator= (EC_Scalar &&other) noexcept |
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>> | |
T | serialize () const |
void | serialize_to (std::span< uint8_t > bytes) const |
void | square_self () |
EC_Scalar | sub (const EC_Scalar &x) const |
BigInt | to_bigint () const |
~EC_Scalar () | |
Static Public Member Functions | |
static EC_Scalar | _from_inner (std::unique_ptr< EC_Scalar_Data > inner) |
static std::optional< EC_Scalar > | deserialize (const EC_Group &group, std::span< const uint8_t > bytes) |
static std::optional< std::pair< EC_Scalar, EC_Scalar > > | deserialize_pair (const EC_Group &group, std::span< const uint8_t > bytes) |
static EC_Scalar | from_bigint (const EC_Group &group, const BigInt &bn) |
static EC_Scalar | from_bytes_mod_order (const EC_Group &group, std::span< const uint8_t > bytes) |
static EC_Scalar | from_bytes_with_trunc (const EC_Group &group, std::span< const uint8_t > bytes) |
static EC_Scalar | gk_x_mod_order (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws) |
static EC_Scalar | one (const EC_Group &group) |
static EC_Scalar | random (const EC_Group &group, RandomNumberGenerator &rng) |
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>> | |
static T | serialize_pair (const EC_Scalar &r, const EC_Scalar &s) |
static void | serialize_pair_to (std::span< uint8_t > bytes, const EC_Scalar &r, const EC_Scalar &s) |
Friends | |
class | EC_AffinePoint |
EC_Scalar | operator* (const EC_Scalar &x, const EC_Scalar &y) |
EC_Scalar | operator+ (const EC_Scalar &x, const EC_Scalar &y) |
EC_Scalar | operator- (const EC_Scalar &x, const EC_Scalar &y) |
bool | operator== (const EC_Scalar &x, const EC_Scalar &y) |
Represents an integer modulo the prime group order of an elliptic curve
Definition at line 28 of file ec_scalar.h.
Botan::EC_Scalar::EC_Scalar | ( | const EC_Group & | group, |
std::span< const uint8_t > | bytes ) |
Convert a bytestring to an EC_Scalar
This is similar to deserialize but instead of returning nullopt if the input is invalid, it will throw an exception.
Definition at line 122 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), and bytes().
Referenced by _from_inner(), add(), deserialize(), from_bigint(), from_bytes_mod_order(), from_bytes_with_trunc(), gk_x_mod_order(), invert(), mul(), negate(), one(), random(), and sub().
Botan::EC_Scalar::EC_Scalar | ( | const EC_Scalar & | other | ) |
Definition at line 22 of file ec_scalar.cpp.
|
noexcept |
Definition at line 24 of file ec_scalar.cpp.
|
default |
|
static |
Definition at line 14 of file ec_scalar.cpp.
References EC_Scalar().
|
inline |
Definition at line 211 of file ec_scalar.h.
Referenced by Botan::EC_AffinePoint::g_mul(), gk_x_mod_order(), Botan::EC_AffinePoint::mul(), Botan::EC_Group::Mul2Table::mul2_vartime(), Botan::EC_Group::Mul2Table::mul2_vartime_x_mod_order_eq(), and serialize_pair_to().
Scalar addition (modulo p)
Definition at line 145 of file ec_scalar.cpp.
References add(), and EC_Scalar().
Referenced by add().
void Botan::EC_Scalar::assign | ( | const EC_Scalar & | x | ) |
Assign a scalar
Definition at line 157 of file ec_scalar.cpp.
Referenced by operator=().
size_t Botan::EC_Scalar::bytes | ( | ) | const |
Return the byte size of this scalar
Definition at line 41 of file ec_scalar.cpp.
Referenced by deserialize(), deserialize_pair(), EC_Scalar(), from_bytes_mod_order(), from_bytes_with_trunc(), serialize_pair(), serialize_pair_to(), serialize_to(), and to_bigint().
|
static |
Deserialize a scalar
The span must be exactly bytes() long; this function does not accept either short inputs (eg [1] to encode the integer 1) or inputs with excess leading zero bytes.
Returns nullopt if the length is incorrect or if the integer is not within the range [0,n) where n is the group order.
Definition at line 114 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), bytes(), and EC_Scalar().
Referenced by deserialize_pair().
|
static |
Deserialize a pair of scalars
Returns nullopt if the length is not 2*bytes(), or if either scalar is out of range or zero
Definition at line 96 of file ec_scalar.cpp.
References bytes(), and deserialize().
Convert from the argument BigInt to a EC_Scalar
Throws an exception if the provided bn is negative or too large
Definition at line 65 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), and EC_Scalar().
|
static |
Convert a bytestring to an EC_Scalar
This reduces the bytes modulo the group order. The input can be at most 2*bytes() long
Definition at line 49 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), bytes(), and EC_Scalar().
|
static |
Convert a bytestring to an EC_Scalar
This uses the truncation rules from ECDSA
Definition at line 45 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), bytes(), and EC_Scalar().
|
static |
Compute the elliptic curve scalar multiplication (g*k) where g is the standard base point on the curve. Then extract the x coordinate of the resulting point, and reduce it modulo the group order.
Workspace argument is transitional
Definition at line 79 of file ec_scalar.cpp.
References _inner(), EC_Scalar(), and Botan::EC_Scalar_Data::group().
EC_Scalar Botan::EC_Scalar::invert | ( | ) | const |
Return the modular inverse of this EC_Scalar
If *this is zero, then invert() returns zero
Definition at line 133 of file ec_scalar.cpp.
References EC_Scalar(), and invert().
Referenced by invert(), and Botan::EC_PrivateKey_Data::public_key().
bool Botan::EC_Scalar::is_eq | ( | const EC_Scalar & | x | ) | const |
Test for equality
Definition at line 161 of file ec_scalar.cpp.
References Botan::EC_Scalar_Data::is_eq().
|
inline |
bool Botan::EC_Scalar::is_zero | ( | ) | const |
Return true if this EC_Scalar is zero
Definition at line 129 of file ec_scalar.cpp.
References Botan::EC_Scalar_Data::is_zero().
Scalar multiplication (modulo p)
Definition at line 153 of file ec_scalar.cpp.
References EC_Scalar(), and mul().
Referenced by mul().
EC_Scalar Botan::EC_Scalar::negate | ( | ) | const |
Definition at line 137 of file ec_scalar.cpp.
References EC_Scalar(), and negate().
Referenced by negate().
Return the scalar value 1
Definition at line 61 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), and EC_Scalar().
Definition at line 26 of file ec_scalar.cpp.
References assign().
Definition at line 33 of file ec_scalar.cpp.
References BOTAN_ARG_CHECK.
|
static |
Return a new random scalar value
Definition at line 57 of file ec_scalar.cpp.
References Botan::EC_Group::_data(), and EC_Scalar().
|
inline |
Return the bytes of the encoded scalar in a container
Definition at line 116 of file ec_scalar.h.
References T.
|
inlinestatic |
Return the bytes of the encoded scalar in a container
Definition at line 133 of file ec_scalar.h.
|
static |
Write the fixed length serialization to bytes
The provided span must be exactly bytes() long
Definition at line 88 of file ec_scalar.cpp.
References _inner(), BOTAN_ARG_CHECK, bytes(), Botan::EC_Scalar_Data::group(), and serialize_to().
void Botan::EC_Scalar::serialize_to | ( | std::span< uint8_t > | bytes | ) | const |
Write the fixed length serialization to bytes
The provided span must be exactly bytes() long
Definition at line 84 of file ec_scalar.cpp.
References bytes(), and Botan::EC_Scalar_Data::serialize_to().
Referenced by serialize_pair_to(), and Botan::EC_PrivateKey_Data::serialize_to().
void Botan::EC_Scalar::square_self | ( | ) |
Set *this to its own square modulo p
Definition at line 141 of file ec_scalar.cpp.
Scalar subtraction (modulo p)
Definition at line 149 of file ec_scalar.cpp.
References EC_Scalar(), and sub().
Referenced by sub().
BigInt Botan::EC_Scalar::to_bigint | ( | ) | const |
Convert *this to a BigInt
Definition at line 73 of file ec_scalar.cpp.
References bytes(), and Botan::BigInt::from_bytes().
|
friend |
Definition at line 216 of file ec_scalar.h.
Definition at line 199 of file ec_scalar.h.
Definition at line 195 of file ec_scalar.h.
Definition at line 197 of file ec_scalar.h.
Definition at line 201 of file ec_scalar.h.