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

#include <ec_apoint.h>

Public Member Functions

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
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_AffinePointoperator= (const EC_AffinePoint &other)
EC_AffinePointoperator= (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>>
serialize_compressed () const
void serialize_compressed_to (std::span< uint8_t > bytes) const
template<concepts::resizable_byte_buffer T = std::vector<uint8_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
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
x_bytes () const
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
xy_bytes () const
template<concepts::resizable_byte_buffer T = secure_vector<uint8_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_AffinePointdeserialize (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePointdeserialize_compressed (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePointdeserialize_uncompressed (const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePointfrom_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_AffinePointmul_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}
static std::optional< EC_AffinePoint > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)

References deserialize().

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

◆ _from_inner()

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

For internal use only

Definition at line 283 of file ec_apoint.cpp.

283 {
284 return EC_AffinePoint(std::move(inner));
285}
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 287 of file ec_apoint.cpp.

287 {
288 return inner().group();
289}

Referenced by operator==().

◆ _inner()

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

For internal use only

Definition at line 337 of file ec_apoint.h.

337{ 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 233 of file ec_apoint.cpp.

233 {
234 auto pt = _inner().group()->affine_add(_inner(), q._inner());
235 return EC_AffinePoint(std::move(pt));
236}
virtual const std::shared_ptr< const EC_Group_Data > & group() const =0
const EC_AffinePoint_Data & _inner() const
Definition ec_apoint.h:337

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 150 of file ec_apoint.cpp.

150 {
151 if(bytes.empty()) {
152 return {};
153 }
154
155 switch(bytes[0]) {
156 case 0x00:
157 // The identity element (see SEC1 section 2.3.4)
158 // TODO(Botan4) remove this - we should reject the identity encoding
159 if(bytes.size() == 1) {
160 return EC_AffinePoint::identity(group);
161 } else {
162 return {};
163 }
164 case 0x02:
165 case 0x03:
166 return EC_AffinePoint::deserialize_compressed(group, bytes);
167 case 0x04:
168 return EC_AffinePoint::deserialize_uncompressed(group, bytes);
169 case 0x06:
170 case 0x07: {
171 // The deprecated "hybrid" point format
172 // TODO(Botan4) remove this
173 const bool hdr_y_is_even = bytes[0] == 0x06;
174 const bool y_is_even = (bytes.back() & 0x01) == 0;
175
176 if(hdr_y_is_even == y_is_even) {
177 std::vector<uint8_t> sec1(bytes.begin(), bytes.end());
178 sec1[0] = 0x04;
180 } else {
181 return {};
182 }
183 }
184 default:
185 return {};
186 }
187}
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(), 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 189 of file ec_apoint.cpp.

190 {
191 if(auto pt = group._data()->point_deserialize_compressed(bytes)) {
192 return EC_AffinePoint(std::move(pt));
193 } else {
194 return {};
195 }
196}

References Botan::EC_Group::_data(), and EC_AffinePoint().

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 198 of file ec_apoint.cpp.

199 {
200 if(auto pt = group._data()->point_deserialize_uncompressed(bytes)) {
201 return EC_AffinePoint(std::move(pt));
202 } else {
203 return {};
204 }
205}

References Botan::EC_Group::_data(), and EC_AffinePoint().

Referenced by deserialize(), Botan::SPAKE2p::RegistrationRecord::deserialize(), 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 110 of file ec_apoint.cpp.

110 {
111 return inner().field_element_bytes();
112}

◆ 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(), Botan::EC_Group::get_p(), Botan::EC_Group::get_p_bytes(), Botan::BigInt::serialize_to(), and Botan::BigInt::signum().

Referenced by botan_ec_point_from_xy(), generator(), and Botan::EC_Group::verify_group().

◆ 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 207 of file ec_apoint.cpp.

207 {
208 auto pt = scalar._inner().group()->point_g_mul(scalar.inner(), rng);
209 return EC_AffinePoint(std::move(pt));
210}

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

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

◆ 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 310 of file ec_apoint.h.

310 {
311 return EC_AffinePoint::g_mul(scalar, rng);
312 }
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(), Botan::EC_Group::get_g_x(), and Botan::EC_Group::get_g_y().

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

◆ 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 133 of file ec_apoint.cpp.

136 {
137 auto pt = group._data()->point_hash_to_curve_nu(hash_fn, input, domain_sep);
138 return EC_AffinePoint(std::move(pt));
139}

References Botan::EC_Group::_data(), and EC_AffinePoint().

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 141 of file ec_apoint.cpp.

144 {
145 return EC_AffinePoint::hash_to_curve_nu(group, hash_fn, input, as_span_of_bytes(domain_sep));
146}
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(), 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 118 of file ec_apoint.cpp.

121 {
122 auto pt = group._data()->point_hash_to_curve_ro(hash_fn, input, domain_sep);
123 return EC_AffinePoint(std::move(pt));
124}

References Botan::EC_Group::_data(), and EC_AffinePoint().

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 126 of file ec_apoint.cpp.

129 {
130 return EC_AffinePoint::hash_to_curve_ro(group, hash_fn, input, as_span_of_bytes(domain_sep));
131}
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(), 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 Botan::EC_Group::_data(), and EC_AffinePoint().

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 114 of file ec_apoint.cpp.

114 {
115 return inner().is_identity();
116}

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 212 of file ec_apoint.cpp.

212 {
213 return EC_AffinePoint(inner().mul(scalar._inner(), rng));
214}
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 321 of file ec_apoint.h.

321 {
322 return this->mul(scalar, rng);
323 }

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 220 of file ec_apoint.cpp.

224 {
225 auto pt = p._inner().group()->mul_px_qy(p._inner(), x._inner(), q._inner(), y._inner(), rng);
226 if(pt) {
227 return EC_AffinePoint(std::move(pt));
228 } else {
229 return {};
230 }
231}

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 216 of file ec_apoint.cpp.

216 {
217 return inner().mul_x_only(scalar._inner(), rng);
218}

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 326 of file ec_apoint.h.

328 {
329 return this->mul_x_only(scalar, rng);
330 }
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 238 of file ec_apoint.cpp.

238 {
239 auto pt = this->_inner().group()->affine_neg(this->_inner());
240 return EC_AffinePoint(std::move(pt));
241}

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 260 of file ec_apoint.h.

260{ 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 auto a_is_id = this->is_identity();
67 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:75
bool is_identity() const
Return true if this point is the identity element.
T serialize_uncompressed() const
Definition ec_apoint.h:232
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:798

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 243 of file ec_apoint.cpp.

243 {
244 if(format == EC_Point_Format::Compressed) {
245 return this->serialize_compressed();
246 } else if(format == EC_Point_Format::Uncompressed) {
247 return this->serialize_uncompressed();
248 } else {
249 // The deprecated "hybrid" point encoding
250 // TODO(Botan4) Remove this
251 auto enc = this->serialize_uncompressed();
252 const bool y_is_odd = (enc[enc.size() - 1] & 0x01) == 0x01;
253 enc.front() = y_is_odd ? 0x07 : 0x06;
254 return enc;
255 }
256}
T serialize_compressed() const
Definition ec_apoint.h:242

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 242 of file ec_apoint.h.

242 {
243 T bytes(1 + this->field_element_bytes());
244 this->serialize_compressed_to(bytes);
245 return bytes;
246 }
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 273 of file ec_apoint.cpp.

273 {
275 m_point->serialize_compressed_to(bytes);
276}
#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 232 of file ec_apoint.h.

232 {
233 T bytes(1 + 2 * this->field_element_bytes());
234 this->serialize_uncompressed_to(bytes);
235 return bytes;
236 }
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 278 of file ec_apoint.cpp.

278 {
280 m_point->serialize_uncompressed_to(bytes);
281}

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 258 of file ec_apoint.cpp.

258 {
260 m_point->serialize_x_to(bytes);
261}

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 268 of file ec_apoint.cpp.

268 {
270 m_point->serialize_xy_to(bytes);
271}

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 263 of file ec_apoint.cpp.

263 {
265 m_point->serialize_y_to(bytes);
266}

References BOTAN_STATE_CHECK, and is_identity().

◆ 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 202 of file ec_apoint.h.

202 {
203 T bytes(this->field_element_bytes());
204 this->serialize_x_to(bytes);
205 return bytes;
206 }
void serialize_x_to(std::span< uint8_t > bytes) const

◆ 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 222 of file ec_apoint.h.

222 {
223 T bytes(2 * this->field_element_bytes());
224 this->serialize_xy_to(bytes);
225 return bytes;
226 }
void serialize_xy_to(std::span< uint8_t > bytes) const

Referenced by Botan::GOST_3410_PublicKey::public_key_bits(), and Botan::sm2_compute_za().

◆ 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 212 of file ec_apoint.h.

212 {
213 T bytes(this->field_element_bytes());
214 this->serialize_y_to(bytes);
215 return bytes;
216 }
void serialize_y_to(std::span< uint8_t > bytes) const

◆ EC_Mul2Table

friend class EC_Mul2Table
friend

Definition at line 350 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: