7#include <botan/ec_scalar.h>
9#include <botan/ec_group.h>
10#include <botan/internal/ec_inner_data.h>
34 BOTAN_ARG_CHECK(_inner().group() == other._inner().group(),
"Curve mismatch");
35 std::swap(m_scalar, other.m_scalar);
42 return m_scalar->bytes();
50 if(
auto s = group.
_data()->scalar_from_bytes_mod_order(
bytes)) {
53 throw Decoding_Error(
"EC_Scalar::from_bytes_mod_order input invalid");
66 if(
auto data = group.
_data()->scalar_from_bigint(bn)) {
75 m_scalar->serialize_to(
bytes);
81 return EC_Scalar(group->gk_x_mod_order(scalar.inner(), rng, ws));
90 const size_t scalar_bytes = r.
bytes();
97 std::span<const uint8_t> bytes) {
98 if(
bytes.size() % 2 != 0) {
102 const size_t half =
bytes.size() / 2;
108 return std::make_pair(r.value(), s.value());
115 if(
auto v = group.
_data()->scalar_deserialize(
bytes)) {
123 m_scalar = group.
_data()->scalar_deserialize(
bytes);
125 throw Decoding_Error(
"EC_Scalar::from_bytes is not a valid scalar value");
142 m_scalar->square_self();
158 m_scalar->assign(x.inner());
162 return inner().
is_eq(x.inner());
#define BOTAN_ASSERT_NONNULL(ptr)
#define BOTAN_ARG_CHECK(expr, msg)
static BigInt from_bytes(std::span< const uint8_t > bytes)
const std::shared_ptr< EC_Group_Data > & _data() const
virtual const std::shared_ptr< const EC_Group_Data > & group() const =0
virtual void serialize_to(std::span< uint8_t > bytes) const =0
virtual bool is_eq(const EC_Scalar_Data &y) const =0
virtual bool is_zero() const =0
static EC_Scalar one(const EC_Group &group)
const EC_Scalar_Data & _inner() const
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
void serialize_to(std::span< uint8_t > bytes) const
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
EC_Scalar & operator=(const EC_Scalar &other)
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 gk_x_mod_order(const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws)
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::vector< T, secure_allocator< T > > secure_vector