Botan 3.14.1
Crypto and TLS for C&
Botan::PCurve::PrimeOrderCurveImpl< C > Class Template Referencefinal

#include <pcurves_wrap.h>

Inheritance diagram for Botan::PCurve::PrimeOrderCurveImpl< C >:
Botan::PCurve::PrimeOrderCurve

Classes

class  PrecomputedMul2TableC

Public Types

typedef std::shared_ptr< const PrimeOrderCurve > CurvePtr
typedef std::array< word, StorageWords > StorageUnit

Public Member Functions

bool affine_point_is_identity (const AffinePoint &pt) const override
Scalar base_point_mul_x_mod_order (const Scalar &scalar, RandomNumberGenerator &rng) const override
std::optional< AffinePoint > deserialize_point_compressed (std::span< const uint8_t > bytes) const override
std::optional< AffinePoint > deserialize_point_uncompressed (std::span< const uint8_t > bytes) const override
std::optional< Scalar > deserialize_scalar (std::span< const uint8_t > bytes) const override
size_t field_element_bytes () const override
AffinePoint generator () const override
 Return the standard generator.
AffinePoint hash_to_curve_nu (std::function< void(std::span< uint8_t >)> expand_message) const override
ProjectivePoint hash_to_curve_ro (std::function< void(std::span< uint8_t >)> expand_message) const override
ProjectivePoint mul (const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const override
std::unique_ptr< const PrecomputedMul2Table > mul2_setup_g (const AffinePoint &q) const override
 Setup a table for 2-ary multiplication where the first point is the generator.
std::optional< ProjectivePoint > mul2_vartime (const PrecomputedMul2Table &tableb, const Scalar &x, const Scalar &y) const override
bool mul2_vartime_x_mod_order_eq (const PrecomputedMul2Table &tableb, const Scalar &v, const Scalar &x, const Scalar &y) const override
ProjectivePoint mul_by_g (const Scalar &scalar, RandomNumberGenerator &rng) const override
std::optional< ProjectivePoint > mul_px_qy (const AffinePoint &p, const Scalar &x, const AffinePoint &q, const Scalar &y, RandomNumberGenerator &rng) const override
secure_vector< uint8_t > mul_x_only (const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const override
size_t order_bits () const override
 Return the bit length of the group order.
ProjectivePoint point_add (const AffinePoint &a, const AffinePoint &b) const override
AffinePoint point_identity () const override
 Return the identity element (aka the point at infinity).
AffinePoint point_negate (const AffinePoint &pt) const override
AffinePoint point_to_affine (const ProjectivePoint &pt) const override
 PrimeOrderCurveImpl ()
Scalar random_scalar (RandomNumberGenerator &rng) const override
Scalar scalar_add (const Scalar &a, const Scalar &b) const override
 Scalar addition.
size_t scalar_bytes () const override
 Return the byte length of the scalar element.
bool scalar_equal (const Scalar &a, const Scalar &b) const override
 Test if two scalars are equal.
std::optional< Scalar > scalar_from_wide_bytes (std::span< const uint8_t > bytes) const override
Scalar scalar_invert (const Scalar &ss) const override
 Scalar inversion.
Scalar scalar_invert_vartime (const Scalar &ss) const override
 Scalar inversion (variable time).
bool scalar_is_zero (const Scalar &s) const override
 Test if scalar is zero.
Scalar scalar_mul (const Scalar &a, const Scalar &b) const override
 Scalar multiplication.
Scalar scalar_negate (const Scalar &s) const override
 Scalar negation.
Scalar scalar_one () const override
Scalar scalar_square (const Scalar &s) const override
 Scalar squaring.
Scalar scalar_sub (const Scalar &a, const Scalar &b) const override
 Scalar subtraction.
void serialize_point (std::span< uint8_t > bytes, const AffinePoint &pt) const override
void serialize_scalar (std::span< uint8_t > bytes, const Scalar &scalar) const override
bool supports_hash_to_curve () const override

Static Public Member Functions

static std::shared_ptr< const PrimeOrderCurve > for_named_curve (std::string_view name)
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 > instance ()

Static Public Attributes

static constexpr size_t MaximumBitLength = 521
static constexpr size_t MaximumByteLength = (MaximumBitLength + 7) / 8
static constexpr size_t StorageWords = (MaximumByteLength + sizeof(word) - 1) / sizeof(word)
 Number of words used to store MaximumByteLength.

Detailed Description

template<typename C>
class Botan::PCurve::PrimeOrderCurveImpl< C >

This class provides a bridge between the "public" (actually still internal) PrimeOrderCurve type, and the inner templates which are subclasses of EllipticCurve from pcurves_impl.h

Definition at line 27 of file pcurves_wrap.h.

Member Typedef Documentation

◆ CurvePtr

typedef std::shared_ptr<const PrimeOrderCurve> Botan::PCurve::PrimeOrderCurve::CurvePtr
inherited

Definition at line 60 of file pcurves.h.

◆ StorageUnit

Definition at line 59 of file pcurves.h.

Constructor & Destructor Documentation

◆ PrimeOrderCurveImpl()

template<typename C>
Botan::PCurve::PrimeOrderCurveImpl< C >::PrimeOrderCurveImpl ( )
inline

Definition at line 339 of file pcurves_wrap.h.

Member Function Documentation

◆ affine_point_is_identity()

template<typename C>
bool Botan::PCurve::PrimeOrderCurveImpl< C >::affine_point_is_identity ( const AffinePoint & pt) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 207 of file pcurves_wrap.h.

207 {
208 return from_stash(pt).is_identity().as_bool();
209 }

◆ base_point_mul_x_mod_order()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::base_point_mul_x_mod_order ( const Scalar & scalar,
RandomNumberGenerator & rng ) const
inlineoverridevirtual

Base point multiplication, returning only the x coordinate modulo the group order

Multiply by the standard generator point g, then extract the x coordinate as an integer, then reduce the x coordinate modulo the group order

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 178 of file pcurves_wrap.h.

178 {
179 const auto pt = m_mul_by_g.mul(from_stash(scalar), rng);
180 BOTAN_STATE_CHECK(!pt.is_identity().as_bool());
182 to_affine_x<C>(pt).serialize_to(std::span{x_bytes});
183 // Reduction might be required (if unlikely)
185 }
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
ProjectivePoint mul(const AffinePoint &pt, const Scalar &scalar, RandomNumberGenerator &rng) const override
auto to_affine_x(const typename C::ProjectivePoint &pt)

References BOTAN_STATE_CHECK, and Botan::to_affine_x().

◆ deserialize_point_compressed()

template<typename C>
std::optional< AffinePoint > Botan::PCurve::PrimeOrderCurveImpl< C >::deserialize_point_compressed ( std::span< const uint8_t > bytes) const
inlineoverridevirtual

Deserialize a point in the SEC1 compressed format

The input must be exactly 1 + field_element_bytes long and have a header byte of 0x02 or 0x03. All other encodings are rejected, as are inputs where x is not the affine x coordinate of a point on the curve.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 264 of file pcurves_wrap.h.

264 {
265 constexpr size_t FieldElementBytes = C::FieldElement::BYTES;
266 constexpr size_t CompressedBytes = C::FieldElement::BYTES + 1;
267
268 if(bytes.size() == CompressedBytes && (bytes[0] == 0x02 || bytes[0] == 0x03)) {
269 const CT::Choice y_is_even = CT::Mask<uint8_t>::is_equal(bytes[0], 0x02).as_choice();
270
271 if(auto x = C::FieldElement::deserialize(bytes.subspan(1, FieldElementBytes))) {
273 return stash(typename C::AffinePoint(*x, y->correct_sign(y_is_even)));
274 }
275 }
276 }
277
278 return {};
279 }
static constexpr Mask< T > is_equal(T x, T y)
Definition ct_utils.h:447

References Botan::CT::Mask< T >::is_equal(), and Botan::sqrt_field_element().

◆ deserialize_point_uncompressed()

template<typename C>
std::optional< AffinePoint > Botan::PCurve::PrimeOrderCurveImpl< C >::deserialize_point_uncompressed ( std::span< const uint8_t > bytes) const
inlineoverridevirtual

Deserialize a point in the SEC1 uncompressed format

The input must be exactly 1 + 2*field_element_bytes long and have a header byte of 0x04. All other encodings are rejected, as are inputs where (x,y) is not a point on the curve.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 241 of file pcurves_wrap.h.

241 {
242 constexpr size_t FieldElementBytes = C::FieldElement::BYTES;
243 constexpr size_t UncompressedBytes = 2 * C::FieldElement::BYTES + 1;
244
245 if(bytes.size() == UncompressedBytes && bytes[0] == 0x04) {
246 const auto encoded_point = bytes.subspan(1);
249
250 if(x && y) {
251 // Check that y^2 = x^3 + ax + b
252 const auto lhs = (*y).square();
253 const auto rhs = C::x3_ax_b(*x);
254 const auto valid = (lhs == rhs);
255 if(valid.as_bool()) {
256 return stash(typename C::AffinePoint(*x, *y));
257 }
258 }
259 }
260
261 return {};
262 }

◆ deserialize_scalar()

template<typename C>
std::optional< Scalar > Botan::PCurve::PrimeOrderCurveImpl< C >::deserialize_scalar ( std::span< const uint8_t > bytes) const
inlineoverridevirtual

Deserialize a scalar in [1,p)

This function requires the input length be exactly scalar_bytes long; it does not accept inputs that are shorter, or with excess leading zero padding bytes.

This function also rejects zero as an input, since in normal usage scalars are integers in Z_p*

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 221 of file pcurves_wrap.h.

221 {
223 if(!scalar->is_zero().as_bool()) {
224 return stash(*scalar);
225 }
226 }
227
228 return {};
229 }

◆ field_element_bytes()

template<typename C>
size_t Botan::PCurve::PrimeOrderCurveImpl< C >::field_element_bytes ( ) const
inlineoverridevirtual

Return the byte length of a field element

Each point consists of two field elements

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 36 of file pcurves_wrap.h.

36{ return C::FieldElement::BYTES; }

◆ for_named_curve()

std::shared_ptr< const PrimeOrderCurve > Botan::PCurve::PrimeOrderCurve::for_named_curve ( std::string_view name)
staticinherited
Returns
nullptr if the curve specified is not available

Definition at line 32 of file pcurves.cpp.

32 {
33#if defined(BOTAN_HAS_PCURVES_SECP256R1)
34 if(name == "secp256r1") {
35 return PCurveInstance::secp256r1();
36 }
37#endif
38
39#if defined(BOTAN_HAS_PCURVES_SECP384R1)
40 if(name == "secp384r1") {
41 return PCurveInstance::secp384r1();
42 }
43#endif
44
45#if defined(BOTAN_HAS_PCURVES_SECP521R1)
46 if(name == "secp521r1") {
47 return PCurveInstance::secp521r1();
48 }
49#endif
50
51#if defined(BOTAN_HAS_PCURVES_BRAINPOOL256R1)
52 if(name == "brainpool256r1") {
53 return PCurveInstance::brainpool256r1();
54 }
55#endif
56
57#if defined(BOTAN_HAS_PCURVES_BRAINPOOL384R1)
58 if(name == "brainpool384r1") {
59 return PCurveInstance::brainpool384r1();
60 }
61#endif
62
63#if defined(BOTAN_HAS_PCURVES_BRAINPOOL512R1)
64 if(name == "brainpool512r1") {
65 return PCurveInstance::brainpool512r1();
66 }
67#endif
68
69#if defined(BOTAN_HAS_PCURVES_FRP256V1)
70 if(name == "frp256v1") {
71 return PCurveInstance::frp256v1();
72 }
73#endif
74
75#if defined(BOTAN_HAS_PCURVES_SECP192R1)
76 if(name == "secp192r1") {
77 return PCurveInstance::secp192r1();
78 }
79#endif
80
81#if defined(BOTAN_HAS_PCURVES_SECP224R1)
82 if(name == "secp224r1") {
83 return PCurveInstance::secp224r1();
84 }
85#endif
86
87#if defined(BOTAN_HAS_PCURVES_SECP256K1)
88 if(name == "secp256k1") {
89 return PCurveInstance::secp256k1();
90 }
91#endif
92
93#if defined(BOTAN_HAS_PCURVES_SM2P256V1)
94 if(name == "sm2p256v1") {
95 return PCurveInstance::sm2p256v1();
96 }
97#endif
98
99#if defined(BOTAN_HAS_PCURVES_NUMSP512D1)
100 if(name == "numsp512d1") {
101 return PCurveInstance::numsp512d1();
102 }
103#endif
104
106 return {};
107}
#define BOTAN_UNUSED
Definition assert.h:151
const char * name
Definition ffi_tls.h:59

References BOTAN_UNUSED, and name.

Referenced by Botan::EC_Group_Data::EC_Group_Data().

◆ from_params()

std::shared_ptr< const PrimeOrderCurve > Botan::PCurve::PrimeOrderCurve::from_params ( const BigInt & p,
const BigInt & a,
const BigInt & b,
const BigInt & base_x,
const BigInt & base_y,
const BigInt & order )
staticinherited
Returns
nullptr if the parameters seem unsuitable for pcurves for example if the prime is too large

This function should accept the same subset of curves as the EC_Group constructor that accepts BigInts.

Definition at line 21 of file pcurves.cpp.

22 {
23#if defined(BOTAN_HAS_PCURVES_GENERIC)
24 return PCurveInstance::from_params(p, a, b, base_x, base_y, order);
25#endif
26
27 BOTAN_UNUSED(p, a, b, base_x, base_y, order);
28 return {};
29}

References BOTAN_UNUSED.

Referenced by Botan::EC_Group_Data::EC_Group_Data().

◆ generator()

template<typename C>
AffinePoint Botan::PCurve::PrimeOrderCurveImpl< C >::generator ( ) const
inlineoverridevirtual

Return the standard generator.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 187 of file pcurves_wrap.h.

187{ return stash(C::G); }

◆ hash_to_curve_nu()

template<typename C>
AffinePoint Botan::PCurve::PrimeOrderCurveImpl< C >::hash_to_curve_nu ( std::function< void(std::span< uint8_t >)> expand_message) const
inlineoverridevirtual

RFC 9380 hash to curve (NU variant)

This is currently only supported for a few specific curves

Parameters
expand_messageis a callback which must fill the provided output span with a sequence of uniform bytes, or if this is not possible due to length limitations or some other issue, throw an exception. It is invoked to produce the uniform_bytes value; see RFC 9380 section 5.2

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 283 of file pcurves_wrap.h.

283 {
284 if constexpr(C::ValidForSswuHash) {
286 } else {
287 throw Not_Implemented("Hash to curve is not implemented for this curve");
288 }
289 }

References Botan::hash_to_curve_sswu().

◆ hash_to_curve_ro()

template<typename C>
ProjectivePoint Botan::PCurve::PrimeOrderCurveImpl< C >::hash_to_curve_ro ( std::function< void(std::span< uint8_t >)> expand_message) const
inlineoverridevirtual

RFC 9380 hash to curve (RO variant)

This is currently only supported for a few specific curves

Parameters
expand_messageis a callback which must fill the provided output span with a sequence of uniform bytes, or if this is not possible due to length limitations or some other issue, throw an exception. It is invoked to produce the uniform_bytes value; see RFC 9380 section 5.2

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 291 of file pcurves_wrap.h.

291 {
292 if constexpr(C::ValidForSswuHash) {
294 } else {
295 throw Not_Implemented("Hash to curve is not implemented for this curve");
296 }
297 }

References Botan::hash_to_curve_sswu().

◆ instance()

template<typename C>
std::shared_ptr< const PrimeOrderCurve > Botan::PCurve::PrimeOrderCurveImpl< C >::instance ( )
inlinestatic

Definition at line 341 of file pcurves_wrap.h.

341 {
343 return g_curve;
344 }

◆ mul()

template<typename C>
ProjectivePoint Botan::PCurve::PrimeOrderCurveImpl< C >::mul ( const AffinePoint & pt,
const Scalar & scalar,
RandomNumberGenerator & rng ) const
inlineoverridevirtual

Generic point multiplication

Multiply an arbitrary point by a scalar

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 42 of file pcurves_wrap.h.

42 {
43 return stash(varpoint_mul<C, VarPointWindowBits>(from_stash(pt), from_stash(scalar), rng));
44 }

References Botan::varpoint_mul().

◆ mul2_setup_g()

template<typename C>
std::unique_ptr< const PrecomputedMul2Table > Botan::PCurve::PrimeOrderCurveImpl< C >::mul2_setup_g ( const AffinePoint & q) const
inlineoverridevirtual

Setup a table for 2-ary multiplication where the first point is the generator.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 67 of file pcurves_wrap.h.

67 {
69 }

◆ mul2_vartime()

template<typename C>
std::optional< ProjectivePoint > Botan::PCurve::PrimeOrderCurveImpl< C >::mul2_vartime ( const PrecomputedMul2Table & table,
const Scalar & x,
const Scalar & y ) const
inlineoverridevirtual

Perform 2-ary multiplication (variable time)

Compute p*x + q*y in variable time

Returns nullopt if the produced point is the point at infinity

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 71 of file pcurves_wrap.h.

73 {
74 try {
75 const auto& table = dynamic_cast<const PrecomputedMul2TableC&>(tableb);
76 const auto pt = table.table().mul2_vartime(m_mul_by_g, from_stash(x), from_stash(y));
77 if(pt.is_identity().as_bool()) {
78 return {};
79 } else {
80 return stash(pt);
81 }
82 } catch(std::bad_cast&) {
83 throw Invalid_Argument("Curve mismatch");
84 }
85 }
std::optional< ProjectivePoint > mul2_vartime(const PrecomputedMul2Table &tableb, const Scalar &x, const Scalar &y) const override

References Botan::PCurve::PrimeOrderCurveImpl< C >::PrecomputedMul2TableC::table().

◆ mul2_vartime_x_mod_order_eq()

template<typename C>
bool Botan::PCurve::PrimeOrderCurveImpl< C >::mul2_vartime_x_mod_order_eq ( const PrecomputedMul2Table & table,
const Scalar & v,
const Scalar & x,
const Scalar & y ) const
inlineoverridevirtual

Perform 2-ary multiplication (variable time), reducing x modulo order

Compute p*x + q*y in variable time, then extract the x coordinate of the result, and reduce x modulo the group order. Compare that value with v. If equal, returns true. Otherwise returns false, including if the produced point is the point at infinity

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 101 of file pcurves_wrap.h.

104 {
105 try {
106 const auto& table = dynamic_cast<const PrecomputedMul2TableC&>(tableb);
107 const auto pt = table.table().mul2_vartime(m_mul_by_g, from_stash(x), from_stash(y));
108 // Variable time here, so the early return is fine
109 if(pt.is_identity().as_bool()) {
110 return false;
111 }
112
113 /*
114 * Avoid the inversion by instead projecting v.
115 *
116 * Given (x*z2) and v we want to know if x % n == v
117 *
118 * Inverting z2 to extract x is expensive. Instead compute (v*z2) and
119 * compare it with (x*z2).
120 *
121 * With overwhelming probability, this conversion is correct. The
122 * only time it is not is in the extremely unlikely case where the
123 * signer actually reduced the x coordinate modulo the group order.
124 * That is handled separately in a second step.
125 */
126 const auto z2 = pt.z().square();
127
129 from_stash(v).serialize_to(v_bytes);
130
131 if(const auto fe_v = C::FieldElement::deserialize(v_bytes)) {
132 if((*fe_v * z2 == pt.x()).as_bool()) {
133 return true;
134 }
135
136 /*
137 * Possibly (if cryptographically unlikely) the signer
138 * reduced the value modulo the group order.
139 *
140 * If so we must check v + n similarly as before. However here
141 * we must be careful to not overflow since otherwise that
142 * would lead to us accepting an incorrect signature.
143 *
144 * If the order is > p then the reduction modulo p would not have
145 * had any effect and we don't need to consider the possibility
146 */
147 if constexpr(C::OrderIsLessThanField) {
148 /*
149 * We have to be careful to avoid overflow since this would
150 * lead to a forgery
151 *
152 * v < (p)-n => v + n < p
153 *
154 * The values n and neg_n could be precomputed but they are
155 * fast to compute and this codepath will ~never be taken
156 * unless when verifying an invalid signature. In any case
157 * it is many times cheaper than performing the modular inversion
158 * which this approach avoids.
159 */
160
161 // Create the group order as a field element, safe because n < p
162 const auto n = C::FieldElement::from_words(C::NW);
163 const auto neg_n = n.negate().to_words();
164
165 const auto vw = fe_v->to_words();
166 if(bigint_ct_is_lt(vw.data(), vw.size(), neg_n.data(), neg_n.size()).as_bool()) {
167 return (((*fe_v + n) * z2) == pt.x()).as_bool();
168 }
169 }
170 }
171
172 return false;
173 } catch(std::bad_cast&) {
174 throw Invalid_Argument("Curve mismatch");
175 }
176 }
constexpr auto bigint_ct_is_lt(const W x[], size_t x_size, const W y[], size_t y_size, bool lt_or_equal=false) -> CT::Mask< W >
Definition mp_core.h:510

References Botan::bigint_ct_is_lt(), and Botan::PCurve::PrimeOrderCurveImpl< C >::PrecomputedMul2TableC::table().

◆ mul_by_g()

template<typename C>
ProjectivePoint Botan::PCurve::PrimeOrderCurveImpl< C >::mul_by_g ( const Scalar & scalar,
RandomNumberGenerator & rng ) const
inlineoverridevirtual

Base point multiplication

Multiply by the standard generator point g

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 38 of file pcurves_wrap.h.

38 {
39 return stash(m_mul_by_g.mul(from_stash(scalar), rng));
40 }

◆ mul_px_qy()

template<typename C>
std::optional< ProjectivePoint > Botan::PCurve::PrimeOrderCurveImpl< C >::mul_px_qy ( const AffinePoint & p,
const Scalar & x,
const AffinePoint & q,
const Scalar & y,
RandomNumberGenerator & rng ) const
inlineoverridevirtual

Perform 2-ary multiplication (constant time)

Compute p*x + q*y

Returns nullopt if the produced point is the point at infinity

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 87 of file pcurves_wrap.h.

91 {
92 const auto pt =
93 varpoint_mul2<C, Mul2WindowBits>(from_stash(p), from_stash(x), from_stash(q), from_stash(y), rng);
94 if(pt.is_identity().as_bool()) {
95 return {};
96 } else {
97 return stash(pt);
98 }
99 }
C::ProjectivePoint varpoint_mul2(const typename C::AffinePoint &p, const typename C::Scalar &x, const typename C::AffinePoint &q, const typename C::Scalar &y, RandomNumberGenerator &rng)

References Botan::varpoint_mul2().

◆ mul_x_only()

template<typename C>
secure_vector< uint8_t > Botan::PCurve::PrimeOrderCurveImpl< C >::mul_x_only ( const AffinePoint & pt,
const Scalar & scalar,
RandomNumberGenerator & rng ) const
inlineoverridevirtual

Generic x-only point multiplication

Multiply an arbitrary point by a scalar, returning only the x coordinate

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 46 of file pcurves_wrap.h.

48 {
49 const auto result = varpoint_mul<C, VarPointWindowBits>(from_stash(pt), from_stash(scalar), rng);
50 BOTAN_STATE_CHECK(!result.is_identity().as_bool());
51 const auto pt_x = to_affine_x<C>(result);
54 return x_bytes;
55 }
C::ProjectivePoint varpoint_mul(const typename C::AffinePoint &p, const typename C::Scalar &s, RandomNumberGenerator &rng)

References BOTAN_STATE_CHECK, Botan::to_affine_x(), and Botan::varpoint_mul().

◆ order_bits()

template<typename C>
size_t Botan::PCurve::PrimeOrderCurveImpl< C >::order_bits ( ) const
inlineoverridevirtual

Return the bit length of the group order.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 32 of file pcurves_wrap.h.

32{ return C::OrderBits; }

◆ point_add()

template<typename C>
ProjectivePoint Botan::PCurve::PrimeOrderCurveImpl< C >::point_add ( const AffinePoint & a,
const AffinePoint & b ) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 201 of file pcurves_wrap.h.

201 {
202 return stash(C::ProjectivePoint::from_affine(from_stash(a)) + from_stash(b));
203 }

◆ point_identity()

template<typename C>
AffinePoint Botan::PCurve::PrimeOrderCurveImpl< C >::point_identity ( ) const
inlineoverridevirtual

Return the identity element (aka the point at infinity).

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 239 of file pcurves_wrap.h.

239{ return stash(C::AffinePoint::identity()); }

◆ point_negate()

template<typename C>
AffinePoint Botan::PCurve::PrimeOrderCurveImpl< C >::point_negate ( const AffinePoint & pt) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 205 of file pcurves_wrap.h.

205{ return stash(from_stash(pt).negate()); }

◆ point_to_affine()

template<typename C>
AffinePoint Botan::PCurve::PrimeOrderCurveImpl< C >::point_to_affine ( const ProjectivePoint & pt) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 189 of file pcurves_wrap.h.

189 {
190 const auto affine = to_affine<C>(from_stash(pt));
191
192 const auto y2 = affine.y().square();
193 const auto x3_ax_b = C::x3_ax_b(affine.x());
194 const auto valid_point = affine.is_identity() || (y2 == x3_ax_b);
195
196 BOTAN_ASSERT(valid_point.as_bool(), "Computed point is on the curve");
197
198 return stash(affine);
199 }
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:69
constexpr auto to_affine(const typename C::ProjectivePoint &pt)

References BOTAN_ASSERT, and Botan::to_affine().

◆ random_scalar()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::random_scalar ( RandomNumberGenerator & rng) const
inlineoverridevirtual

Return a new random scalar

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 337 of file pcurves_wrap.h.

337{ return stash(C::Scalar::random(rng)); }

◆ scalar_add()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_add ( const Scalar & a,
const Scalar & b ) const
inlineoverridevirtual

Scalar addition.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 299 of file pcurves_wrap.h.

299 {
300 return stash(from_stash(a) + from_stash(b));
301 }

◆ scalar_bytes()

template<typename C>
size_t Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_bytes ( ) const
inlineoverridevirtual

Return the byte length of the scalar element.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 34 of file pcurves_wrap.h.

34{ return C::Scalar::BYTES; }

◆ scalar_equal()

template<typename C>
bool Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_equal ( const Scalar & a,
const Scalar & b ) const
inlineoverridevirtual

Test if two scalars are equal.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 331 of file pcurves_wrap.h.

331 {
332 return (from_stash(a) == from_stash(b)).as_bool();
333 }

◆ scalar_from_wide_bytes()

template<typename C>
std::optional< Scalar > Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_from_wide_bytes ( std::span< const uint8_t > bytes) const
inlineoverridevirtual

Reduce an integer modulo the group order

The input can be at most twice the bit length of the order; if larger than this nullopt is returned

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 231 of file pcurves_wrap.h.

231 {
233 return stash(*s);
234 } else {
235 return {};
236 }
237 }

◆ scalar_invert()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_invert ( const Scalar & s) const
inlineoverridevirtual

Scalar inversion.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 313 of file pcurves_wrap.h.

313 {
314 const auto s = from_stash(ss);
315 if constexpr(curve_supports_scalar_invert<C>) {
316 return stash(C::scalar_invert(s));
317 } else {
318 return stash(s.invert());
319 }
320 }

◆ scalar_invert_vartime()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_invert_vartime ( const Scalar & s) const
inlineoverridevirtual

Scalar inversion (variable time).

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 322 of file pcurves_wrap.h.

322 {
323 const auto s = from_stash(ss);
324 return stash(s.invert_vartime());
325 }

◆ scalar_is_zero()

template<typename C>
bool Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_is_zero ( const Scalar & s) const
inlineoverridevirtual

Test if scalar is zero.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 329 of file pcurves_wrap.h.

329{ return from_stash(s).is_zero().as_bool(); }

◆ scalar_mul()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_mul ( const Scalar & a,
const Scalar & b ) const
inlineoverridevirtual

Scalar multiplication.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 307 of file pcurves_wrap.h.

307 {
308 return stash(from_stash(a) * from_stash(b));
309 }

◆ scalar_negate()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_negate ( const Scalar & s) const
inlineoverridevirtual

Scalar negation.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 327 of file pcurves_wrap.h.

327{ return stash(from_stash(s).negate()); }

◆ scalar_one()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_one ( ) const
inlineoverridevirtual

Return the scalar one

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 335 of file pcurves_wrap.h.

335{ return stash(C::Scalar::one()); }

◆ scalar_square()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_square ( const Scalar & s) const
inlineoverridevirtual

Scalar squaring.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 311 of file pcurves_wrap.h.

311{ return stash(from_stash(s).square()); }
BigInt square(const BigInt &x)
Definition numthry.cpp:184

References Botan::square().

◆ scalar_sub()

template<typename C>
Scalar Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_sub ( const Scalar & a,
const Scalar & b ) const
inlineoverridevirtual

Scalar subtraction.

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 303 of file pcurves_wrap.h.

303 {
304 return stash(from_stash(a) - from_stash(b));
305 }

◆ serialize_point()

template<typename C>
void Botan::PCurve::PrimeOrderCurveImpl< C >::serialize_point ( std::span< uint8_t > bytes,
const AffinePoint & pt ) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 211 of file pcurves_wrap.h.

211 {
212 BOTAN_ARG_CHECK(bytes.size() == C::AffinePoint::BYTES, "Invalid length for serialize_point");
213 from_stash(pt).serialize_to(bytes.subspan<0, C::AffinePoint::BYTES>());
214 }
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK.

◆ serialize_scalar()

template<typename C>
void Botan::PCurve::PrimeOrderCurveImpl< C >::serialize_scalar ( std::span< uint8_t > bytes,
const Scalar & scalar ) const
inlineoverridevirtual

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 216 of file pcurves_wrap.h.

216 {
217 BOTAN_ARG_CHECK(bytes.size() == C::Scalar::BYTES, "Invalid length to serialize_scalar");
218 return from_stash(scalar).serialize_to(bytes.subspan<0, C::Scalar::BYTES>());
219 }

References BOTAN_ARG_CHECK.

◆ supports_hash_to_curve()

template<typename C>
bool Botan::PCurve::PrimeOrderCurveImpl< C >::supports_hash_to_curve ( ) const
inlineoverridevirtual

Return true if this curve supports RFC 9380 hash to curve

If this returns false then hash_to_curve_nu and hash_to_curve_ro will throw Not_Implemented

Implements Botan::PCurve::PrimeOrderCurve.

Definition at line 281 of file pcurves_wrap.h.

281{ return C::ValidForSswuHash; }

Member Data Documentation

◆ MaximumBitLength

size_t Botan::PCurve::PrimeOrderCurve::MaximumBitLength = 521
staticconstexprinherited

Somewhat arbitrary maximum size for a field or scalar

Sized to fit at least P-521

Definition at line 37 of file pcurves.h.

◆ MaximumByteLength

size_t Botan::PCurve::PrimeOrderCurve::MaximumByteLength = (MaximumBitLength + 7) / 8
staticconstexprinherited

Definition at line 39 of file pcurves.h.

◆ StorageWords

size_t Botan::PCurve::PrimeOrderCurve::StorageWords = (MaximumByteLength + sizeof(word) - 1) / sizeof(word)
staticconstexprinherited

Number of words used to store MaximumByteLength.

Definition at line 42 of file pcurves.h.


The documentation for this class was generated from the following file: