7#ifndef BOTAN_PCURVES_H_
8#define BOTAN_PCURVES_H_
10#include <botan/concepts.h>
11#include <botan/secmem.h>
12#include <botan/types.h>
45 static std::shared_ptr<const PrimeOrderCurve>
for_named_curve(std::string_view name);
60 typedef std::shared_ptr<const PrimeOrderCurve>
CurvePtr;
74 const auto&
_curve()
const {
return m_curve; }
76 const auto&
_value()
const {
return m_value; }
102 const auto&
_curve()
const {
return m_curve; }
104 const auto&
_x()
const {
return m_x; }
106 const auto&
_y()
const {
return m_y; }
134 const auto&
_curve()
const {
return m_curve; }
136 const auto&
_x()
const {
return m_x; }
138 const auto&
_y()
const {
return m_y; }
140 const auto&
_z()
const {
return m_z; }
148 m_curve(std::move(curve)), m_x(x), m_y(y), m_z(z) {}
208 const Scalar& y)
const = 0;
230 const Scalar& y)
const = 0;
AffinePoint & operator=(const AffinePoint &other)=default
static AffinePoint generator(CurvePtr curve)
static AffinePoint _create(CurvePtr curve, StorageUnit x, StorageUnit y)
AffinePoint(AffinePoint &&other)=default
const auto & _curve() const
AffinePoint & operator=(AffinePoint &&other)=default
AffinePoint(const AffinePoint &other)=default
virtual ~PrecomputedMul2Table()=default
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)
~ProjectivePoint()=default
const auto & _curve() const
Scalar(const Scalar &other)=default
const auto & _curve() const
const auto & _value() const
Scalar & operator=(Scalar &&other)=default
Scalar(Scalar &&other)=default
Scalar & operator=(const Scalar &other)=default
static Scalar _create(CurvePtr curve, StorageUnit v)
virtual ~PrimeOrderCurve()=default
virtual Scalar scalar_add(const Scalar &a, const Scalar &b) const =0
Scalar addition.
virtual AffinePoint point_negate(const AffinePoint &pt) 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 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 ProjectivePoint hash_to_curve_ro(std::function< void(std::span< uint8_t >)> expand_message) const =0
virtual size_t field_element_bytes() const =0
static constexpr size_t StorageWords
Number of words used to store MaximumByteLength.
virtual size_t order_bits() const =0
Return the bit length of the group order.
std::shared_ptr< const PrimeOrderCurve > CurvePtr
virtual size_t scalar_bytes() const =0
Return the byte length of the scalar element.
virtual ProjectivePoint point_add(const AffinePoint &a, const AffinePoint &b) const =0
std::array< word, StorageWords > StorageUnit
virtual bool scalar_is_zero(const Scalar &s) const =0
Test if scalar is zero.
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
Scalar inversion.
virtual Scalar scalar_mul(const Scalar &a, const Scalar &b) const =0
Scalar multiplication.
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
Scalar negation.
static constexpr size_t MaximumByteLength
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 mul(const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const =0
virtual Scalar scalar_invert_vartime(const Scalar &s) const =0
Scalar inversion (variable time)
virtual Scalar scalar_square(const Scalar &s) const =0
Scalar squaring.
virtual bool scalar_equal(const Scalar &a, const Scalar &b) const =0
Test if two scalars are equal.
virtual AffinePoint hash_to_curve_nu(std::function< void(std::span< uint8_t >)> expand_message) 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
static constexpr size_t MaximumBitLength
virtual bool affine_point_is_identity(const AffinePoint &pt) const =0
static std::shared_ptr< const PrimeOrderCurve > from_params(const BigInt &p, const BigInt &a, const BigInt &b, const BigInt &base_x, const BigInt &base_y, const BigInt &order)
static std::shared_ptr< const PrimeOrderCurve > for_named_curve(std::string_view name)
virtual Scalar base_point_mul_x_mod_order(const Scalar &scalar, RandomNumberGenerator &rng) 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
Scalar subtraction.
std::vector< T, secure_allocator< T > > secure_vector
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word