7#include <botan/ec_scalar.h>
9#include <botan/ec_group.h>
10#include <botan/internal/ec_inner_data.h>
20 m_scalar->_const_time_poison();
24 m_scalar->_const_time_unpoison();
37 if(m_scalar ==
nullptr || m_scalar->group() != other.inner().
group()) {
38 m_scalar = other.inner().
clone();
49 std::swap(m_scalar, other.m_scalar);
61 return m_scalar->bytes();
69 if(
auto s =
group._data()->scalar_from_bytes_mod_order(
bytes)) {
72 throw Decoding_Error(
"EC_Scalar::from_bytes_mod_order input invalid");
85 if(
auto data =
group._data()->scalar_from_bigint(bn)) {
94 m_scalar->serialize_to(
bytes);
105 inner().serialize_to(
bytes);
110 const size_t scalar_bytes = r.
bytes();
117 std::span<const uint8_t>
bytes) {
118 if(
bytes.size() % 2 != 0) {
122 const size_t half =
bytes.size() / 2;
128 return std::make_pair(r.value(), s.value());
135 if(
auto v =
group._data()->scalar_deserialize(
bytes)) {
143 m_scalar =
group._data()->scalar_deserialize(
bytes);
145 throw Decoding_Error(
"EC_Scalar::from_bytes is not a valid scalar value");
150 return inner().is_zero();
166 m_scalar->square_self();
186 if(m_scalar ==
nullptr || m_scalar->group() != x.inner().
group()) {
187 m_scalar = x.inner().
clone();
189 m_scalar->assign(x.inner());
203 return inner().is_eq(x.inner());
208 std::string_view hash_fn,
209 std::span<const uint8_t> input,
210 std::span<const uint8_t> domain_sep) {
216 const size_t scalar_bits =
group.get_order_bits();
217 const size_t security_level = std::min<size_t>((scalar_bits + 1) / 2, 256);
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ARG_CHECK(expr, msg)
static BigInt from_bytes(std::span< const uint8_t > bytes)
virtual const std::shared_ptr< const EC_Group_Data > & group() const =0
virtual std::unique_ptr< EC_Scalar_Data > clone() const =0
static EC_Scalar one(const EC_Group &group)
const EC_Scalar_Data & _inner() const
static EC_Scalar hash(const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
void assign(const EC_Scalar &x)
bool is_eq(const EC_Scalar &x) const
static std::optional< EC_Scalar > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)
EC_Scalar mul(const EC_Scalar &x) const
EC_Scalar add(const EC_Scalar &x) const
static EC_Scalar gk_x_mod_order(const EC_Scalar &scalar, RandomNumberGenerator &rng)
void _const_time_unpoison() const
void serialize_to(std::span< uint8_t > bytes) const
void _const_time_poison() const
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
EC_Scalar & operator=(const EC_Scalar &other)
EC_Scalar invert_vartime() const
static void serialize_pair_to(std::span< uint8_t > bytes, const EC_Scalar &r, const EC_Scalar &s)
EC_Scalar(const EC_Group &group, std::span< const uint8_t > bytes)
static EC_Scalar from_bytes_mod_order(const EC_Group &group, std::span< const uint8_t > bytes)
static EC_Scalar random(const EC_Group &group, RandomNumberGenerator &rng)
static EC_Scalar _from_inner(std::unique_ptr< EC_Scalar_Data > inner)
EC_Scalar sub(const EC_Scalar &x) const
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_bytes_with_trunc(const EC_Group &group, std::span< const uint8_t > bytes)
std::function< void(std::span< uint8_t >)> h2c_expand_message(std::string_view hash_fn, size_t order_bits, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
std::vector< T, secure_allocator< T > > secure_vector