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

#include <ec_inner_bn.h>

Inheritance diagram for Botan::EC_AffinePoint_Data_BN:
Botan::EC_AffinePoint_Data

Public Member Functions

std::unique_ptr< EC_AffinePoint_Dataclone () const override
 EC_AffinePoint_Data_BN (std::shared_ptr< const EC_Group_Data > group, EC_Point pt)
size_t field_element_bytes () const override
const std::shared_ptr< const EC_Group_Data > & group () const override
bool is_identity () const override
std::unique_ptr< EC_AffinePoint_Datamul (const EC_Scalar_Data &scalar, RandomNumberGenerator &rng) const override
secure_vector< uint8_t > mul_x_only (const EC_Scalar_Data &scalar, RandomNumberGenerator &rng) const override
void serialize_compressed_to (std::span< uint8_t > bytes) const override
void serialize_uncompressed_to (std::span< uint8_t > bytes) const override
void serialize_x_to (std::span< uint8_t > bytes) const override
void serialize_xy_to (std::span< uint8_t > bytes) const override
void serialize_y_to (std::span< uint8_t > bytes) const override
EC_Point to_legacy_point () const override

Detailed Description

Definition at line 59 of file ec_inner_bn.h.

Constructor & Destructor Documentation

◆ EC_AffinePoint_Data_BN()

Botan::EC_AffinePoint_Data_BN::EC_AffinePoint_Data_BN ( std::shared_ptr< const EC_Group_Data > group,
EC_Point pt )

Definition at line 97 of file ec_inner_bn.cpp.

97 :
98 m_group(std::move(group)), m_pt(std::move(pt)) {
99 if(!m_pt.is_zero()) {
100 m_pt.force_affine();
101 m_xy = m_pt.xy_bytes();
102 }
103}
const std::shared_ptr< const EC_Group_Data > & group() const override

References group().

Member Function Documentation

◆ clone()

std::unique_ptr< EC_AffinePoint_Data > Botan::EC_AffinePoint_Data_BN::clone ( ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 105 of file ec_inner_bn.cpp.

105 {
106 return std::make_unique<EC_AffinePoint_Data_BN>(m_group, m_pt);
107}

◆ field_element_bytes()

size_t Botan::EC_AffinePoint_Data_BN::field_element_bytes ( ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 149 of file ec_inner_bn.cpp.

149 {
150 return m_group->p_bytes();
151}

Referenced by serialize_compressed_to(), serialize_uncompressed_to(), serialize_x_to(), serialize_xy_to(), and serialize_y_to().

◆ group()

const std::shared_ptr< const EC_Group_Data > & Botan::EC_AffinePoint_Data_BN::group ( ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 109 of file ec_inner_bn.cpp.

109 {
110 return m_group;
111}

Referenced by EC_AffinePoint_Data_BN().

◆ is_identity()

bool Botan::EC_AffinePoint_Data_BN::is_identity ( ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 153 of file ec_inner_bn.cpp.

153 {
154 return m_xy.empty();
155}

Referenced by serialize_compressed_to(), serialize_uncompressed_to(), serialize_x_to(), serialize_xy_to(), and serialize_y_to().

◆ mul()

std::unique_ptr< EC_AffinePoint_Data > Botan::EC_AffinePoint_Data_BN::mul ( const EC_Scalar_Data & scalar,
RandomNumberGenerator & rng ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 113 of file ec_inner_bn.cpp.

114 {
115 BOTAN_ARG_CHECK(scalar.group() == m_group, "Curve mismatch");
116 const auto& bn = EC_Scalar_Data_BN::checked_ref(scalar);
117
118 std::vector<BigInt> ws;
119 const EC_Point_Var_Point_Precompute mul(m_pt, rng, ws);
120
121 // We pass order*cofactor here to "correctly" handle the case where the
122 // point is on the curve but not in the prime order subgroup. This only
123 // matters for groups with cofactor > 1
124 // See https://github.com/randombit/botan/issues/3800
125
126 const auto order = m_group->order() * m_group->cofactor();
127 auto pt = mul.mul(bn.value(), rng, order, ws);
128 return std::make_unique<EC_AffinePoint_Data_BN>(m_group, std::move(pt));
129}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
std::unique_ptr< EC_AffinePoint_Data > mul(const EC_Scalar_Data &scalar, RandomNumberGenerator &rng) const override
static const EC_Scalar_Data_BN & checked_ref(const EC_Scalar_Data &data)

References BOTAN_ARG_CHECK, Botan::EC_Scalar_Data_BN::checked_ref(), Botan::EC_Scalar_Data::group(), and mul().

Referenced by mul(), and mul_x_only().

◆ mul_x_only()

secure_vector< uint8_t > Botan::EC_AffinePoint_Data_BN::mul_x_only ( const EC_Scalar_Data & scalar,
RandomNumberGenerator & rng ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 131 of file ec_inner_bn.cpp.

132 {
133 BOTAN_ARG_CHECK(scalar.group() == m_group, "Curve mismatch");
134 const auto& bn = EC_Scalar_Data_BN::checked_ref(scalar);
135
136 std::vector<BigInt> ws;
137 const EC_Point_Var_Point_Precompute mul(m_pt, rng, ws);
138
139 // We pass order*cofactor here to "correctly" handle the case where the
140 // point is on the curve but not in the prime order subgroup. This only
141 // matters for groups with cofactor > 1
142 // See https://github.com/randombit/botan/issues/3800
143
144 const auto order = m_group->order() * m_group->cofactor();
145 auto pt = mul.mul(bn.value(), rng, order, ws);
146 return pt.x_bytes();
147}

References BOTAN_ARG_CHECK, Botan::EC_Scalar_Data_BN::checked_ref(), Botan::EC_Scalar_Data::group(), and mul().

◆ serialize_compressed_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 178 of file ec_inner_bn.cpp.

178 {
180 const size_t fe_bytes = this->field_element_bytes();
181 BOTAN_ARG_CHECK(bytes.size() == 1 + fe_bytes, "Invalid output size");
182 const bool y_is_odd = (m_xy[m_xy.size() - 1] & 0x01) == 0x01;
183
184 BufferStuffer stuffer(bytes);
185 stuffer.append(y_is_odd ? 0x03 : 0x02);
186 serialize_x_to(stuffer.next(fe_bytes));
187}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
void serialize_x_to(std::span< uint8_t > bytes) const override
size_t field_element_bytes() const override
bool is_identity() const override

References Botan::BufferStuffer::append(), BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, field_element_bytes(), is_identity(), Botan::BufferStuffer::next(), and serialize_x_to().

◆ serialize_uncompressed_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 189 of file ec_inner_bn.cpp.

189 {
191 const size_t fe_bytes = this->field_element_bytes();
192 BOTAN_ARG_CHECK(bytes.size() == 1 + 2 * fe_bytes, "Invalid output size");
193 BufferStuffer stuffer(bytes);
194 stuffer.append(0x04);
195 stuffer.append(m_xy);
196}

References Botan::BufferStuffer::append(), BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, field_element_bytes(), and is_identity().

◆ serialize_x_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 157 of file ec_inner_bn.cpp.

157 {
159 const size_t fe_bytes = this->field_element_bytes();
160 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
161 copy_mem(bytes, std::span{m_xy}.first(fe_bytes));
162}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144

References BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, Botan::copy_mem(), field_element_bytes(), and is_identity().

Referenced by serialize_compressed_to().

◆ serialize_xy_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 171 of file ec_inner_bn.cpp.

171 {
173 const size_t fe_bytes = this->field_element_bytes();
174 BOTAN_ARG_CHECK(bytes.size() == 2 * fe_bytes, "Invalid output size");
175 copy_mem(bytes, m_xy);
176}

References BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, Botan::copy_mem(), field_element_bytes(), and is_identity().

◆ serialize_y_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 164 of file ec_inner_bn.cpp.

164 {
166 const size_t fe_bytes = this->field_element_bytes();
167 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
168 copy_mem(bytes, std::span{m_xy}.last(fe_bytes));
169}

References BOTAN_ARG_CHECK, BOTAN_STATE_CHECK, Botan::copy_mem(), field_element_bytes(), and is_identity().

◆ to_legacy_point()

EC_Point Botan::EC_AffinePoint_Data_BN::to_legacy_point ( ) const
inlineoverride

Definition at line 85 of file ec_inner_bn.h.

85{ return m_pt; }

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