7#ifndef BOTAN_PCURVES_H_
8#define BOTAN_PCURVES_H_
10#include <botan/internal/pcurves_id.h>
12#include <botan/concepts.h>
13#include <botan/secmem.h>
14#include <botan/types.h>
23class RandomNumberGenerator;
44 static std::shared_ptr<const PrimeOrderCurve>
from_name(std::string_view
name) {
44 static std::shared_ptr<const PrimeOrderCurve>
from_name(std::string_view
name) {
…}
55 typedef std::shared_ptr<const PrimeOrderCurve>
CurvePtr;
72 size_t bytes()
const {
return m_curve->scalar_bytes(); }
77 template <concepts::resizable_
byte_buffer T = std::vector<u
int8_t>>
80 m_curve->serialize_scalar(
bytes, *
this);
131 bool is_zero()
const {
return m_curve->scalar_is_zero(*
this); }
133 const auto&
_curve()
const {
return m_curve; }
135 const auto&
_value()
const {
return m_value; }
164 size_t bytes()
const {
return 1 + 2 * m_curve->field_element_bytes(); }
174 template <concepts::resizable_
byte_buffer T = std::vector<u
int8_t>>
177 m_curve->serialize_point(
bytes, *
this);
184 template <concepts::resizable_
byte_buffer T = std::vector<u
int8_t>>
187 m_curve->serialize_point_compressed(
bytes, *
this);
194 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
197 m_curve->serialize_point_x(
bytes, *
this);
209 bool is_identity()
const {
return m_curve->affine_point_is_identity(*
this); }
211 const auto&
_curve()
const {
return m_curve; }
213 const auto&
_x()
const {
return m_x; }
215 const auto&
_y()
const {
return m_y; }
259 return x.m_curve->point_add(x, y);
263 return x.m_curve->point_add_mixed(x, y);
266 const auto&
_curve()
const {
return m_curve; }
268 const auto&
_x()
const {
return m_x; }
270 const auto&
_y()
const {
return m_y; }
272 const auto&
_z()
const {
return m_z; }
280 m_curve(std::move(curve)), m_x(x), m_y(y), m_z(z) {}
344 const Scalar& y)
const = 0;
366 const Scalar& y)
const = 0;
447 std::span<const uint8_t> input,
448 std::span<const uint8_t> domain_sep)
const = 0;
456 std::span<const uint8_t> input,
457 std::span<const uint8_t> domain_sep)
const = 0;
Identifier for a named prime order curve.
static std::optional< PrimeOrderCurveId > from_string(std::string_view name)
Map a string to a curve identifier.
T serialize_compressed() const
size_t compressed_bytes() const
AffinePoint & operator=(const AffinePoint &other)=default
static AffinePoint generator(CurvePtr curve)
static AffinePoint _create(CurvePtr curve, StorageUnit x, StorageUnit y)
AffinePoint(AffinePoint &&other)=default
AffinePoint negate() const
const auto & _curve() const
AffinePoint & operator=(AffinePoint &&other)=default
AffinePoint(const AffinePoint &other)=default
virtual ~PrecomputedMul2Table()=default
friend ProjectivePoint operator+(const ProjectivePoint &x, const AffinePoint &y)
AffinePoint to_affine() const
ProjectivePoint & operator=(const ProjectivePoint &other)=default
ProjectivePoint(const ProjectivePoint &other)=default
ProjectivePoint(ProjectivePoint &&other)=default
ProjectivePoint & operator=(ProjectivePoint &&other)=default
static ProjectivePoint _create(CurvePtr curve, StorageUnit x, StorageUnit y, StorageUnit z)
friend ProjectivePoint operator+(const ProjectivePoint &x, const ProjectivePoint &y)
ProjectivePoint dbl() const
~ProjectivePoint()=default
static ProjectivePoint from_affine(const AffinePoint &pt)
const auto & _curve() const
Scalar(const Scalar &other)=default
friend Scalar operator-(const Scalar &a, const Scalar &b)
const auto & _curve() const
const auto & _value() const
friend Scalar operator*(const Scalar &a, const Scalar &b)
Scalar & operator=(Scalar &&other)=default
Scalar(Scalar &&other)=default
Scalar invert_vartime() const
Scalar & operator=(const Scalar &other)=default
friend bool operator==(const Scalar &a, const Scalar &b)
static Scalar _create(CurvePtr curve, StorageUnit v)
friend Scalar operator+(const Scalar &a, const Scalar &b)
virtual ~PrimeOrderCurve()=default
virtual Scalar scalar_add(const Scalar &a, const Scalar &b) const =0
virtual std::unique_ptr< const PrecomputedMul2Table > mul2_setup(const AffinePoint &p, const AffinePoint &pq) const =0
Setup a table for 2-ary multiplication.
static const size_t MaximumByteLength
virtual AffinePoint point_negate(const AffinePoint &pt) const =0
virtual AffinePoint hash_to_curve_nu(std::string_view hash, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep) const =0
virtual void serialize_point(std::span< uint8_t > bytes, const AffinePoint &pt) const =0
virtual std::optional< AffinePoint > deserialize_point(std::span< const uint8_t > bytes) const =0
virtual Scalar scalar_zero() const =0
virtual std::unique_ptr< const PrecomputedMul2Table > mul2_setup_g(const AffinePoint &q) const =0
Setup a table for 2-ary multiplication where the first point is the generator.
virtual size_t field_element_bytes() const =0
virtual size_t order_bits() const =0
Return the bit length of the group order.
virtual size_t scalar_bytes() const =0
Return the byte length of the scalar element.
virtual bool scalar_is_zero(const Scalar &s) const =0
std::array< word, StorageWords > StorageUnit
virtual std::optional< ProjectivePoint > mul2_vartime(const PrecomputedMul2Table &table, const Scalar &x, const Scalar &y) const =0
virtual std::optional< Scalar > deserialize_scalar(std::span< const uint8_t > bytes) const =0
virtual Scalar scalar_invert(const Scalar &s) const =0
virtual Scalar scalar_mul(const Scalar &a, const Scalar &b) const =0
virtual void serialize_point_compressed(std::span< uint8_t > bytes, const AffinePoint &pt) const =0
virtual ProjectivePoint hash_to_curve_ro(std::string_view hash, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep) const =0
virtual Scalar random_scalar(RandomNumberGenerator &rng) const =0
virtual secure_vector< uint8_t > mul_x_only(const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const =0
virtual bool mul2_vartime_x_mod_order_eq(const PrecomputedMul2Table &table, const Scalar &v, const Scalar &x, const Scalar &y) const =0
virtual AffinePoint point_to_affine(const ProjectivePoint &pt) const =0
virtual AffinePoint generator() const =0
Return the standard generator.
virtual Scalar scalar_one() const =0
virtual Scalar scalar_negate(const Scalar &s) const =0
static std::shared_ptr< const PrimeOrderCurve > from_id(PrimeOrderCurveId id)
virtual void serialize_point_x(std::span< uint8_t > bytes, const AffinePoint &pt) const =0
virtual ProjectivePoint mul_by_g(const Scalar &scalar, RandomNumberGenerator &rng) const =0
virtual std::optional< Scalar > scalar_from_wide_bytes(std::span< const uint8_t > bytes) const =0
virtual ProjectivePoint point_to_projective(const AffinePoint &pt) const =0
static std::shared_ptr< const PrimeOrderCurve > from_name(std::string_view name)
virtual ProjectivePoint mul(const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const =0
static const size_t StorageWords
Number of words used to store MaximumByteLength.
virtual Scalar scalar_invert_vartime(const Scalar &s) const =0
virtual Scalar scalar_square(const Scalar &s) const =0
virtual bool scalar_equal(const Scalar &a, const Scalar &b) const =0
virtual std::optional< ProjectivePoint > mul_px_qy(const AffinePoint &p, const Scalar &x, const AffinePoint &q, const Scalar &y, RandomNumberGenerator &rng) const =0
virtual ProjectivePoint point_add_mixed(const ProjectivePoint &a, const AffinePoint &b) const =0
virtual bool affine_point_is_identity(const AffinePoint &pt) const =0
std::shared_ptr< const PrimeOrderCurve > CurvePtr
virtual Scalar base_point_mul_x_mod_order(const Scalar &scalar, RandomNumberGenerator &rng) const =0
virtual ProjectivePoint point_add(const ProjectivePoint &a, const ProjectivePoint &b) const =0
virtual void serialize_scalar(std::span< uint8_t > bytes, const Scalar &scalar) const =0
virtual Scalar scalar_sub(const Scalar &a, const Scalar &b) const =0
static const size_t MaximumBitLength
virtual ProjectivePoint point_double(const ProjectivePoint &pt) const =0
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector