Botan 3.14.1
Crypto and TLS for C&
Botan::EC_AffinePoint Class Referencefinal

#include <ec_apoint.h>

Public Member Functions

void _const_time_poison () const
void _const_time_unpoison () const
const std::shared_ptr< const EC_Group_Data > & _group () const
const EC_AffinePoint_Data & _inner () const
EC_AffinePoint add (const EC_AffinePoint &q) const
 EC_AffinePoint (const EC_AffinePoint &other)
 EC_AffinePoint (const EC_Group &group, std::span< const uint8_t > bytes)
 EC_AffinePoint (EC_AffinePoint &&other) noexcept
size_t field_element_bytes () const
EC_Group group () const
 Return the elliptic curve group this point is associated with.
bool is_identity () const
 Return true if this point is the identity element.
EC_AffinePoint mul (const EC_Scalar &scalar, RandomNumberGenerator &rng) const
 Multiply a point by a scalar returning a complete point.
EC_AffinePoint mul (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &) const
secure_vector< uint8_t > mul_x_only (const EC_Scalar &scalar, RandomNumberGenerator &rng) const
 Multiply a point by a scalar, returning the byte encoding of the x coordinate only.
secure_vector< uint8_t > mul_x_only (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &) const
 Multiply a point by a scalar, returning the byte encoding of the x coordinate only.
EC_AffinePoint negate () const
 Point negation.
bool operator!= (const EC_AffinePoint &other) const
EC_AffinePoint & operator= (const EC_AffinePoint &other)
EC_AffinePoint & operator= (EC_AffinePoint &&other) noexcept
bool operator== (const EC_AffinePoint &other) const
std::vector< uint8_t > serialize (EC_Point_Format format) const
 Return an encoding depending on the requested format.
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>>
T serialize_compressed () const
void serialize_compressed_to (std::span< uint8_t > bytes) const
template<concepts::resizable_byte_buffer T = std::vector<uint8_t>>
T serialize_uncompressed () const
void serialize_uncompressed_to (std::span< uint8_t > bytes) const
void serialize_x_to (std::span< uint8_t > bytes) const
void serialize_xy_to (std::span< uint8_t > bytes) const
void serialize_y_to (std::span< uint8_t > bytes) const
std::pair< BigInt, BigInt > to_bigint_xy () const
 Convert *this to two BigInts (x, y).
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T x_bytes () const
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T xy_bytes () const
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T y_bytes () const
 ~EC_AffinePoint ()

Static Public Member Functions

static EC_AffinePoint _from_inner (std::unique_ptr< EC_AffinePoint_Data > inner)
static std::optional< EC_AffinePoint > deserialize (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePoint > deserialize_compressed (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePoint > deserialize_uncompressed (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePoint > from_bigint_xy (const EC_Group &group, const BigInt &x, const BigInt &y)
static EC_AffinePoint g_mul (const EC_Scalar &scalar, RandomNumberGenerator &rng)
 Multiply by the group generator returning a complete point.
static EC_AffinePoint g_mul (const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &)
static EC_AffinePoint generator (const EC_Group &group)
 Return the standard group generator.
static EC_AffinePoint hash_to_curve_nu (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
static EC_AffinePoint hash_to_curve_nu (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::string_view domain_sep)
static EC_AffinePoint hash_to_curve_ro (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
static EC_AffinePoint hash_to_curve_ro (const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::string_view domain_sep)
static EC_AffinePoint identity (const EC_Group &group)
 Return the identity element.
static std::optional< EC_AffinePoint > mul_px_qy (const EC_AffinePoint &p, const EC_Scalar &x, const EC_AffinePoint &q, const EC_Scalar &y, RandomNumberGenerator &rng)

Friends

class EC_Mul2Table

Detailed Description

Elliptic Curve Point in Affine Representation

Definition at line 37 of file ec_apoint.h.

Constructor & Destructor Documentation

◆ EC_AffinePoint() [1/3]

Botan::EC_AffinePoint::EC_AffinePoint ( const EC_Group & group,
std::span< const uint8_t > bytes )

Point deserialization. Throws if wrong length or not a valid point

This accepts SEC1 compressed or uncompressed formats. It also (for backward compatibility) accepts the deprecated hybrid format, and the encoding of the identity element as a single zero byte. Prefer deserialize_compressed or deserialize_uncompressed, which accept exactly one well-defined encoding.

Definition at line 36 of file ec_apoint.cpp.

36 {
37 if(auto pt = EC_AffinePoint::deserialize(group, bytes)) {
38 m_point = std::move(pt->m_point);
39 } else {
40 throw Decoding_Error("Failed to deserialize elliptic curve point");
41 }
42}
EC_Group group() const
Return the elliptic curve group this point is associated with.
static std::optional< EC_AffinePoint > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)

References deserialize(), and group().

Referenced by _from_inner(), add(), deserialize_compressed(), deserialize_uncompressed(), EC_AffinePoint(), EC_AffinePoint(), EC_Mul2Table, g_mul(), g_mul(), generator(), hash_to_curve_nu(), hash_to_curve_nu(), hash_to_curve_ro(), hash_to_curve_ro(), identity(), mul(), mul(), mul_px_qy(), negate(), operator!=(), operator=(), operator=(), and operator==().

◆ EC_AffinePoint() [2/3]

Botan::EC_AffinePoint::EC_AffinePoint ( const EC_AffinePoint & other)

Copy constructor

Parameters
otherthe point to copy

Definition at line 20 of file ec_apoint.cpp.

20: m_point(other.inner().clone()) {}

References EC_AffinePoint().

◆ EC_AffinePoint() [3/3]

Botan::EC_AffinePoint::EC_AffinePoint ( EC_AffinePoint && other)
noexcept

Move constructor

Parameters
otherthe point to move from

Definition at line 22 of file ec_apoint.cpp.

22: m_point(std::move(other.m_point)) {}

References EC_AffinePoint().

◆ ~EC_AffinePoint()

Botan::EC_AffinePoint::~EC_AffinePoint ( )
default

Member Function Documentation

◆ _const_time_poison()

void Botan::EC_AffinePoint::_const_time_poison ( ) const

Mark this point as holding secret data

Warning
this is an implementation detail which is not for public use and not covered by SemVer.

Definition at line 304 of file ec_apoint.cpp.

304 {
305 inner()._const_time_poison();
306}

◆ _const_time_unpoison()

void Botan::EC_AffinePoint::_const_time_unpoison ( ) const

Mark this point as no longer holding secret data

Warning
this is an implementation detail which is not for public use and not covered by SemVer.

Definition at line 308 of file ec_apoint.cpp.

308 {
309 inner()._const_time_unpoison();
310}

◆ _from_inner()

EC_AffinePoint Botan::EC_AffinePoint::_from_inner ( std::unique_ptr< EC_AffinePoint_Data > inner)
static

For internal use only

Definition at line 296 of file ec_apoint.cpp.

296 {
297 return EC_AffinePoint(std::move(inner));
298}
EC_AffinePoint(const EC_Group &group, std::span< const uint8_t > bytes)
Definition ec_apoint.cpp:36

References EC_AffinePoint().

Referenced by Botan::EC_Group::Mul2Table::mul2_vartime().

◆ _group()

const std::shared_ptr< const EC_Group_Data > & Botan::EC_AffinePoint::_group ( ) const

For internal use only

Definition at line 300 of file ec_apoint.cpp.

300 {
301 return inner().group();
302}

Referenced by operator==().

◆ _inner()

const EC_AffinePoint_Data & Botan::EC_AffinePoint::_inner ( ) const
inline

For internal use only

Definition at line 343 of file ec_apoint.h.

343{ return inner(); }

Referenced by add(), mul_px_qy(), and negate().

◆ add()

EC_AffinePoint Botan::EC_AffinePoint::add ( const EC_AffinePoint & q) const

Point addition

Note that this is quite slow since it converts the resulting projective point immediately to affine coordinates, which requires a field inversion. This can be sufficient when implementing protocols that just need to perform a few additions.

In the future a corresponding EC_ProjectivePoint type may be added which would avoid the expensive affine conversions

Definition at line 246 of file ec_apoint.cpp.

246 {
247 auto pt = _inner().group()->affine_add(_inner(), q._inner());
248 return EC_AffinePoint(std::move(pt));
249}
virtual const std::shared_ptr< const EC_Group_Data > & group() const =0
const EC_AffinePoint_Data & _inner() const
Definition ec_apoint.h:343

References _inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().

Referenced by botan_ec_point_add().

◆ deserialize()

std::optional< EC_AffinePoint > Botan::EC_AffinePoint::deserialize ( const EC_Group & group,
std::span< const uint8_t > bytes )
static

Point deserialization. Returns nullopt if wrong length or not a valid point

This accepts SEC1 compressed or uncompressed formats. It also (for backward compatibility) accepts the deprecated hybrid format, and the encoding of the identity element as a single zero byte. Prefer deserialize_compressed or deserialize_uncompressed, which accept exactly one well-defined encoding.

Definition at line 162 of file ec_apoint.cpp.

162 {
163 if(bytes.empty()) {
164 return {};
165 }
166
167 switch(bytes[0]) {
168 case 0x00:
169 // The identity element (see SEC1 section 2.3.4)
170 // TODO(Botan4) remove this - we should reject the identity encoding
171 if(bytes.size() == 1) {
173 } else {
174 return {};
175 }
176 case 0x02:
177 case 0x03:
179 case 0x04:
181 case 0x06:
182 case 0x07: {
183 // The deprecated "hybrid" point format
184 // TODO(Botan4) remove this
185 const bool hdr_y_is_even = bytes[0] == 0x06;
186 const bool y_is_even = (bytes.back() & 0x01) == 0;
187 const size_t expected_len = 1 + 2 * group.get_p_bytes();
188
189 if(hdr_y_is_even == y_is_even && bytes.size() == expected_len) {
190 std::vector<uint8_t> sec1(bytes.begin(), bytes.end());
191 sec1[0] = 0x04;
193 } else {
194 return {};
195 }
196 }
197 default:
198 return {};
199 }
200}
static std::optional< EC_AffinePoint > deserialize_uncompressed(const EC_Group &group, std::span< const uint8_t > bytes)
static EC_AffinePoint identity(const EC_Group &group)
Return the identity element.
Definition ec_apoint.cpp:80
static std::optional< EC_AffinePoint > deserialize_compressed(const EC_Group &group, std::span< const uint8_t > bytes)

References deserialize_compressed(), deserialize_uncompressed(), group(), and identity().

Referenced by EC_AffinePoint().

◆ deserialize_compressed()

std::optional< EC_AffinePoint > Botan::EC_AffinePoint::deserialize_compressed ( const EC_Group & group,
std::span< const uint8_t > bytes )
static

Point deserialization, accepting only the SEC1 compressed format

The encoding must be exactly 1 + field_element_bytes long, with a header byte of either 0x02 or 0x03. All other encodings (including the uncompressed, hybrid, and identity encodings) are rejected.

Returns nullopt if the encoding was rejected or not a valid point

Definition at line 202 of file ec_apoint.cpp.

203 {
204 if(auto pt = group._data()->point_deserialize_compressed(bytes)) {
205 return EC_AffinePoint(std::move(pt));
206 } else {
207 return {};
208 }
209}

References EC_AffinePoint(), and group().

Referenced by deserialize(), and Botan::TLS::Callbacks::tls_deserialize_peer_public_key().

◆ deserialize_uncompressed()

std::optional< EC_AffinePoint > Botan::EC_AffinePoint::deserialize_uncompressed ( const EC_Group & group,
std::span< const uint8_t > bytes )
static

Point deserialization, accepting only the SEC1 uncompressed format

The encoding must be exactly 1 + 2*field_element_bytes long, with a header byte of 0x04. All other encodings (including the compressed, hybrid, and identity encodings) are rejected.

Returns nullopt if the encoding was rejected or not a valid point

Definition at line 211 of file ec_apoint.cpp.

212 {
213 if(auto pt = group._data()->point_deserialize_uncompressed(bytes)) {
214 return EC_AffinePoint(std::move(pt));
215 } else {
216 return {};
217 }
218}

References EC_AffinePoint(), and group().

Referenced by deserialize(), Botan::SPAKE2p::RegistrationRecord::deserialize(), Botan::EC_PublicKey_Data::EC_PublicKey_Data(), from_bigint_xy(), Botan::SPAKE2p::ProverContext::process_message(), Botan::SPAKE2p::VerifierContext::process_message(), and Botan::TLS::Callbacks::tls_deserialize_peer_public_key().

◆ field_element_bytes()

size_t Botan::EC_AffinePoint::field_element_bytes ( ) const

Return the number of bytes of a field element

A point consists of two field elements, plus possibly a header

Definition at line 122 of file ec_apoint.cpp.

122 {
123 return inner().field_element_bytes();
124}

◆ from_bigint_xy()

std::optional< EC_AffinePoint > Botan::EC_AffinePoint::from_bigint_xy ( const EC_Group & group,
const BigInt & x,
const BigInt & y )
static

Create a point from a pair (x,y) of integers

The integers must be within the field - in the range [0,p) and must satisfy the curve equation

Definition at line 93 of file ec_apoint.cpp.

93 {
94 if(x.signum() < 0 || x >= group.get_p()) {
95 return {};
96 }
97 if(y.signum() < 0 || y >= group.get_p()) {
98 return {};
99 }
100
101 const size_t fe_bytes = group.get_p_bytes();
102 std::vector<uint8_t> sec1(1 + 2 * fe_bytes);
103 sec1[0] = 0x04;
104 x.serialize_to(std::span{sec1}.subspan(1, fe_bytes));
105 y.serialize_to(std::span{sec1}.last(fe_bytes));
106
108}

References deserialize_uncompressed(), group(), Botan::BigInt::serialize_to(), and Botan::BigInt::signum().

Referenced by botan_ec_point_from_xy(), and generator().

◆ g_mul() [1/2]

EC_AffinePoint Botan::EC_AffinePoint::g_mul ( const EC_Scalar & scalar,
RandomNumberGenerator & rng )
static

Multiply by the group generator returning a complete point.

Definition at line 220 of file ec_apoint.cpp.

220 {
221 auto pt = scalar._inner().group()->point_g_mul(scalar.inner(), rng);
222 return EC_AffinePoint(std::move(pt));
223}

References Botan::EC_Scalar::_inner(), EC_AffinePoint(), and Botan::EC_Scalar_Data::group().

Referenced by g_mul(), Botan::EC_PrivateKey_Data::public_key(), and Botan::SPAKE2p::ProverSecret::registration_record().

◆ g_mul() [2/2]

EC_AffinePoint Botan::EC_AffinePoint::g_mul ( const EC_Scalar & scalar,
RandomNumberGenerator & rng,
std::vector< BigInt > &  )
inlinestatic

Multiply by the group generator returning a complete point

Parameters
scalarthe scalar to multiply the generator by
Random Number Generatorsa random number generator, used for blinding
Returns
the resulting point

Definition at line 316 of file ec_apoint.h.

316 {
317 return EC_AffinePoint::g_mul(scalar, rng);
318 }
static EC_AffinePoint g_mul(const EC_Scalar &scalar, RandomNumberGenerator &rng)
Multiply by the group generator returning a complete point.

References EC_AffinePoint(), and g_mul().

◆ generator()

EC_AffinePoint Botan::EC_AffinePoint::generator ( const EC_Group & group)
static

Return the standard group generator.

Definition at line 84 of file ec_apoint.cpp.

84 {
85 // TODO it would be nice to improve this (pcurves supports returning generator directly)
86 if(auto g = EC_AffinePoint::from_bigint_xy(group, group.get_g_x(), group.get_g_y())) {
87 return *g;
88 } else {
89 throw Internal_Error("EC_AffinePoint::generator curve rejected generator");
90 }
91}
static std::optional< EC_AffinePoint > from_bigint_xy(const EC_Group &group, const BigInt &x, const BigInt &y)
Definition ec_apoint.cpp:93

References EC_AffinePoint(), from_bigint_xy(), and group().

Referenced by botan_ec_point_generator(), Botan::EC_Group::DER_encode(), Botan::SPAKE2p::ProverContext::generate_message(), and Botan::SPAKE2p::VerifierContext::process_message().

◆ group()

EC_Group Botan::EC_AffinePoint::group ( ) const

Return the elliptic curve group this point is associated with.

Definition at line 118 of file ec_apoint.cpp.

118 {
119 return EC_Group(inner().group());
120}

References group().

Referenced by Botan::ECIES_KA_Operation::derive_secret(), deserialize(), deserialize_compressed(), deserialize_uncompressed(), EC_AffinePoint(), from_bigint_xy(), generator(), group(), hash_to_curve_nu(), hash_to_curve_nu(), hash_to_curve_ro(), hash_to_curve_ro(), and identity().

◆ hash_to_curve_nu() [1/2]

EC_AffinePoint Botan::EC_AffinePoint::hash_to_curve_nu ( const EC_Group & group,
std::string_view hash_fn,
std::span< const uint8_t > input,
std::span< const uint8_t > domain_sep )
static

Hash to curve (RFC 9380), non uniform variant

Only supported for specific groups

Definition at line 145 of file ec_apoint.cpp.

148 {
149 auto pt = group._data()->point_hash_to_curve_nu(hash_fn, input, domain_sep);
150 return EC_AffinePoint(std::move(pt));
151}

References EC_AffinePoint(), and group().

Referenced by hash_to_curve_nu().

◆ hash_to_curve_nu() [2/2]

EC_AffinePoint Botan::EC_AffinePoint::hash_to_curve_nu ( const EC_Group & group,
std::string_view hash_fn,
std::span< const uint8_t > input,
std::string_view domain_sep )
static

Hash to curve (RFC 9380), non uniform variant

Only supported for specific groups

Definition at line 153 of file ec_apoint.cpp.

156 {
157 return EC_AffinePoint::hash_to_curve_nu(group, hash_fn, input, as_span_of_bytes(domain_sep));
158}
static EC_AffinePoint hash_to_curve_nu(const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59

References Botan::as_span_of_bytes(), EC_AffinePoint(), group(), and hash_to_curve_nu().

◆ hash_to_curve_ro() [1/2]

EC_AffinePoint Botan::EC_AffinePoint::hash_to_curve_ro ( const EC_Group & group,
std::string_view hash_fn,
std::span< const uint8_t > input,
std::span< const uint8_t > domain_sep )
static

Hash to curve (RFC 9380), random oracle variant

Only supported for specific groups

Definition at line 130 of file ec_apoint.cpp.

133 {
134 auto pt = group._data()->point_hash_to_curve_ro(hash_fn, input, domain_sep);
135 return EC_AffinePoint(std::move(pt));
136}

References EC_AffinePoint(), and group().

Referenced by Botan::SPAKE2p::SystemParameters::custom(), and hash_to_curve_ro().

◆ hash_to_curve_ro() [2/2]

EC_AffinePoint Botan::EC_AffinePoint::hash_to_curve_ro ( const EC_Group & group,
std::string_view hash_fn,
std::span< const uint8_t > input,
std::string_view domain_sep )
static

Hash to curve (RFC 9380), random oracle variant

Only supported for specific groups

Definition at line 138 of file ec_apoint.cpp.

141 {
142 return EC_AffinePoint::hash_to_curve_ro(group, hash_fn, input, as_span_of_bytes(domain_sep));
143}
static EC_AffinePoint hash_to_curve_ro(const EC_Group &group, std::string_view hash_fn, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)

References Botan::as_span_of_bytes(), EC_AffinePoint(), group(), and hash_to_curve_ro().

◆ identity()

EC_AffinePoint Botan::EC_AffinePoint::identity ( const EC_Group & group)
static

Return the identity element.

Definition at line 80 of file ec_apoint.cpp.

80 {
81 return EC_AffinePoint(group._data()->point_identity());
82}

References EC_AffinePoint(), and group().

Referenced by botan_ec_point_identity(), and deserialize().

◆ is_identity()

bool Botan::EC_AffinePoint::is_identity ( ) const

Return true if this point is the identity element.

Definition at line 126 of file ec_apoint.cpp.

126 {
127 return inner().is_identity();
128}

Referenced by Botan::EC_PublicKey::check_key(), Botan::ECIES_KA_Operation::derive_secret(), operator==(), serialize_compressed_to(), serialize_uncompressed_to(), serialize_x_to(), serialize_xy_to(), and serialize_y_to().

◆ mul() [1/2]

EC_AffinePoint Botan::EC_AffinePoint::mul ( const EC_Scalar & scalar,
RandomNumberGenerator & rng ) const

Multiply a point by a scalar returning a complete point.

Definition at line 225 of file ec_apoint.cpp.

225 {
226 return EC_AffinePoint(inner().mul(scalar._inner(), rng));
227}
EC_AffinePoint mul(const EC_Scalar &scalar, RandomNumberGenerator &rng) const
Multiply a point by a scalar returning a complete point.

References Botan::EC_Scalar::_inner(), EC_AffinePoint(), and mul().

Referenced by botan_ec_point_mul(), mul(), and mul().

◆ mul() [2/2]

EC_AffinePoint Botan::EC_AffinePoint::mul ( const EC_Scalar & scalar,
RandomNumberGenerator & rng,
std::vector< BigInt > &  ) const
inline

Multiply a point by a scalar returning a complete point

Parameters
scalarthe scalar to multiply this point by
Random Number Generatorsa random number generator, used for blinding
Returns
the resulting point

Definition at line 327 of file ec_apoint.h.

327 {
328 return this->mul(scalar, rng);
329 }

References EC_AffinePoint(), and mul().

◆ mul_px_qy()

std::optional< EC_AffinePoint > Botan::EC_AffinePoint::mul_px_qy ( const EC_AffinePoint & p,
const EC_Scalar & x,
const EC_AffinePoint & q,
const EC_Scalar & y,
RandomNumberGenerator & rng )
static

Compute 2-ary multiscalar multiplication - p*x + q*y

This operation runs in constant time with respect to p, x, q, and y

Returns
p*x+q*y, or nullopt if the result was the point at infinity

Definition at line 233 of file ec_apoint.cpp.

237 {
238 auto pt = p._inner().group()->mul_px_qy(p._inner(), x._inner(), q._inner(), y._inner(), rng);
239 if(pt) {
240 return EC_AffinePoint(std::move(pt));
241 } else {
242 return {};
243 }
244}

References _inner(), Botan::EC_Scalar::_inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().

Referenced by Botan::SPAKE2p::ProverContext::generate_message(), Botan::SPAKE2p::ProverContext::process_message(), and Botan::SPAKE2p::VerifierContext::process_message().

◆ mul_x_only() [1/2]

secure_vector< uint8_t > Botan::EC_AffinePoint::mul_x_only ( const EC_Scalar & scalar,
RandomNumberGenerator & rng ) const

Multiply a point by a scalar, returning the byte encoding of the x coordinate only.

Definition at line 229 of file ec_apoint.cpp.

229 {
230 return inner().mul_x_only(scalar._inner(), rng);
231}

References Botan::EC_Scalar::_inner().

◆ mul_x_only() [2/2]

secure_vector< uint8_t > Botan::EC_AffinePoint::mul_x_only ( const EC_Scalar & scalar,
RandomNumberGenerator & rng,
std::vector< BigInt > &  ) const
inline

Multiply a point by a scalar, returning the byte encoding of the x coordinate only.

Definition at line 332 of file ec_apoint.h.

334 {
335 return this->mul_x_only(scalar, rng);
336 }
secure_vector< uint8_t > mul_x_only(const EC_Scalar &scalar, RandomNumberGenerator &rng) const
Multiply a point by a scalar, returning the byte encoding of the x coordinate only.

◆ negate()

EC_AffinePoint Botan::EC_AffinePoint::negate ( ) const

Point negation.

Definition at line 251 of file ec_apoint.cpp.

251 {
252 auto pt = this->_inner().group()->affine_neg(this->_inner());
253 return EC_AffinePoint(std::move(pt));
254}

References _inner(), EC_AffinePoint(), and Botan::EC_AffinePoint_Data::group().

Referenced by botan_ec_point_negate().

◆ operator!=()

bool Botan::EC_AffinePoint::operator!= ( const EC_AffinePoint & other) const
inline

Test if two points are unequal

Parameters
otherthe point to compare against
Returns
true if the two points are not equal

Definition at line 266 of file ec_apoint.h.

266{ return !(*this == other); }

References EC_AffinePoint().

◆ operator=() [1/2]

EC_AffinePoint & Botan::EC_AffinePoint::operator= ( const EC_AffinePoint & other)

Copy assignment

Parameters
otherthe point to copy
Returns
reference to this

Definition at line 24 of file ec_apoint.cpp.

24 {
25 if(this != &other) {
26 m_point = other.inner().clone();
27 }
28 return (*this);
29}

References Botan::EC_AffinePoint_Data::clone(), and EC_AffinePoint().

◆ operator=() [2/2]

EC_AffinePoint & Botan::EC_AffinePoint::operator= ( EC_AffinePoint && other)
noexcept

Move assignment

Parameters
otherthe point to move from
Returns
reference to this

Definition at line 31 of file ec_apoint.cpp.

31 {
32 m_point.swap(other.m_point);
33 return (*this);
34}

References EC_AffinePoint().

◆ operator==()

bool Botan::EC_AffinePoint::operator== ( const EC_AffinePoint & other) const

Test if two points are equal

Parameters
otherthe point to compare against
Returns
true if the two points are equal

Definition at line 55 of file ec_apoint.cpp.

55 {
56 if(this == &other) {
57 return true;
58 }
59
60 // We are relying on EC_Group to ensure there is just a single shared_ptr
61 // for any set of group params
62 if(this->_group() != other._group()) {
63 return false;
64 }
65
66 const auto a_is_id = this->is_identity();
67 const auto b_is_id = other.is_identity();
68
69 if(a_is_id || b_is_id) {
70 return (a_is_id == b_is_id);
71 }
72
73 auto a_xy = this->serialize_uncompressed();
74 auto b_xy = other.serialize_uncompressed();
75 BOTAN_ASSERT_NOMSG(a_xy.size() == b_xy.size());
76
77 return CT::is_equal(a_xy.data(), b_xy.data(), a_xy.size()).as_bool();
78}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
bool is_identity() const
Return true if this point is the identity element.
T serialize_uncompressed() const
Definition ec_apoint.h:238
const std::shared_ptr< const EC_Group_Data > & _group() const
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:803

References _group(), BOTAN_ASSERT_NOMSG, EC_AffinePoint(), Botan::CT::is_equal(), is_identity(), and serialize_uncompressed().

◆ serialize()

std::vector< uint8_t > Botan::EC_AffinePoint::serialize ( EC_Point_Format format) const

Return an encoding depending on the requested format.

Definition at line 256 of file ec_apoint.cpp.

256 {
257 if(format == EC_Point_Format::Compressed) {
258 return this->serialize_compressed();
259 } else if(format == EC_Point_Format::Uncompressed) {
260 return this->serialize_uncompressed();
261 } else {
262 // The deprecated "hybrid" point encoding
263 // TODO(Botan4) Remove this
264 auto enc = this->serialize_uncompressed();
265 const bool y_is_odd = (enc[enc.size() - 1] & 0x01) == 0x01;
266 enc.front() = y_is_odd ? 0x07 : 0x06;
267 return enc;
268 }
269}
T serialize_compressed() const
Definition ec_apoint.h:248

References Botan::Compressed, serialize_compressed(), serialize_uncompressed(), and Botan::Uncompressed.

Referenced by Botan::ECDH_PublicKey::public_value(), and Botan::EC_PublicKey::raw_public_key_bits().

◆ serialize_compressed()

template<concepts::resizable_byte_buffer T = std::vector<uint8_t>>
T Botan::EC_AffinePoint::serialize_compressed ( ) const
inline

Return the bytes of the affine x and y coordinates in a container

This function will fail if this point is the identity element

Definition at line 248 of file ec_apoint.h.

248 {
249 T bytes(1 + this->field_element_bytes());
250 this->serialize_compressed_to(bytes);
251 return bytes;
252 }
size_t field_element_bytes() const
void serialize_compressed_to(std::span< uint8_t > bytes) const

Referenced by Botan::ECDSA_PublicKey::recovery_param(), and serialize().

◆ serialize_compressed_to()

void Botan::EC_AffinePoint::serialize_compressed_to ( std::span< uint8_t > bytes) const

Write the fixed length SEC1 compressed encoding

The output span must be exactly 1 + field_element_bytes long

This function will fail if this point is the identity element

Definition at line 286 of file ec_apoint.cpp.

286 {
288 m_point->serialize_compressed_to(bytes);
289}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK, and is_identity().

◆ serialize_uncompressed()

template<concepts::resizable_byte_buffer T = std::vector<uint8_t>>
T Botan::EC_AffinePoint::serialize_uncompressed ( ) const
inline

Return the bytes of the affine x and y coordinates in a container

This function will fail if this point is the identity element

Definition at line 238 of file ec_apoint.h.

238 {
239 T bytes(1 + 2 * this->field_element_bytes());
240 this->serialize_uncompressed_to(bytes);
241 return bytes;
242 }
void serialize_uncompressed_to(std::span< uint8_t > bytes) const

Referenced by Botan::EC_Group::DER_encode(), operator==(), and serialize().

◆ serialize_uncompressed_to()

void Botan::EC_AffinePoint::serialize_uncompressed_to ( std::span< uint8_t > bytes) const

Return the fixed length encoding of SEC1 uncompressed encoding

The output span must be exactly 1 + 2*field_element_bytes long

This function will fail if this point is the identity element

Definition at line 291 of file ec_apoint.cpp.

291 {
293 m_point->serialize_uncompressed_to(bytes);
294}

References BOTAN_STATE_CHECK, and is_identity().

◆ serialize_x_to()

void Botan::EC_AffinePoint::serialize_x_to ( std::span< uint8_t > bytes) const

Write the fixed length encoding of affine x coordinate

The output span must be exactly field_element_bytes long

This function will fail if this point is the identity element

Definition at line 271 of file ec_apoint.cpp.

271 {
273 m_point->serialize_x_to(bytes);
274}

References BOTAN_STATE_CHECK, and is_identity().

◆ serialize_xy_to()

void Botan::EC_AffinePoint::serialize_xy_to ( std::span< uint8_t > bytes) const

Write the fixed length encoding of affine x and y coordinates

The output span must be exactly 2*field_element_bytes long

This function will fail if this point is the identity element

Definition at line 281 of file ec_apoint.cpp.

281 {
283 m_point->serialize_xy_to(bytes);
284}

References BOTAN_STATE_CHECK, and is_identity().

◆ serialize_y_to()

void Botan::EC_AffinePoint::serialize_y_to ( std::span< uint8_t > bytes) const

Write the fixed length encoding of affine y coordinate

The output span must be exactly field_element_bytes long

This function will fail if this point is the identity element

Definition at line 276 of file ec_apoint.cpp.

276 {
278 m_point->serialize_y_to(bytes);
279}

References BOTAN_STATE_CHECK, and is_identity().

◆ to_bigint_xy()

std::pair< BigInt, BigInt > Botan::EC_AffinePoint::to_bigint_xy ( ) const

Convert *this to two BigInts (x, y).

Definition at line 110 of file ec_apoint.cpp.

110 {
111 std::vector<uint8_t> x_bytes(m_point->field_element_bytes());
112 std::vector<uint8_t> y_bytes(m_point->field_element_bytes());
113 m_point->serialize_x_to(x_bytes);
114 m_point->serialize_y_to(y_bytes);
115 return std::make_pair(BigInt::from_bytes(x_bytes), BigInt::from_bytes(y_bytes));
116}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:84

References Botan::BigInt::from_bytes(), x_bytes(), and y_bytes().

◆ x_bytes()

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::EC_AffinePoint::x_bytes ( ) const
inline

Return the bytes of the affine x coordinate in a container

This function will fail if this point is the identity element

Definition at line 208 of file ec_apoint.h.

208 {
209 T bytes(this->field_element_bytes());
210 this->serialize_x_to(bytes);
211 return bytes;
212 }
void serialize_x_to(std::span< uint8_t > bytes) const

Referenced by to_bigint_xy().

◆ xy_bytes()

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::EC_AffinePoint::xy_bytes ( ) const
inline

Return the bytes of the affine x and y coordinates in a container

This function will fail if this point is the identity element

Definition at line 228 of file ec_apoint.h.

228 {
229 T bytes(2 * this->field_element_bytes());
230 this->serialize_xy_to(bytes);
231 return bytes;
232 }
void serialize_xy_to(std::span< uint8_t > bytes) const

Referenced by Botan::GOST_3410_PublicKey::public_key_bits().

◆ y_bytes()

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::EC_AffinePoint::y_bytes ( ) const
inline

Return the bytes of the affine y coordinate in a container

This function will fail if this point is the identity element

Definition at line 218 of file ec_apoint.h.

218 {
219 T bytes(this->field_element_bytes());
220 this->serialize_y_to(bytes);
221 return bytes;
222 }
void serialize_y_to(std::span< uint8_t > bytes) const

Referenced by to_bigint_xy().

◆ EC_Mul2Table

friend class EC_Mul2Table
friend

Definition at line 372 of file ec_apoint.h.

References EC_AffinePoint(), and EC_Mul2Table.

Referenced by EC_Mul2Table.


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