Botan 3.6.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)
 
 EC_AffinePoint_Data_BN (std::shared_ptr< const EC_Group_Data > group, std::span< const uint8_t > 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, std::vector< BigInt > &ws) 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 55 of file ec_inner_bn.h.

Constructor & Destructor Documentation

◆ EC_AffinePoint_Data_BN() [1/2]

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

Definition at line 72 of file ec_inner_bn.cpp.

72 :
73 m_group(std::move(group)), m_pt(std::move(pt)) {
74 if(!m_pt.is_zero()) {
75 m_pt.force_affine();
76 m_xy = m_pt.xy_bytes();
77 }
78}
const std::shared_ptr< const EC_Group_Data > & group() const override
secure_vector< uint8_t > xy_bytes() const
Definition ec_point.cpp:482
bool is_zero() const
Definition ec_point.h:167
void force_affine()
Definition ec_point.cpp:449

References Botan::EC_Point::is_zero().

◆ EC_AffinePoint_Data_BN() [2/2]

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

Definition at line 80 of file ec_inner_bn.cpp.

81 :
82 m_group(std::move(group)) {
83 BOTAN_ASSERT_NONNULL(m_group);
84 m_pt = Botan::OS2ECP(pt.data(), pt.size(), m_group->curve());
85 if(!m_pt.is_zero()) {
86 m_xy = m_pt.xy_bytes();
87 }
88}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:86
EC_Point OS2ECP(const uint8_t data[], size_t data_len, const CurveGFp &curve)
Definition ec_point.cpp:648

References BOTAN_ASSERT_NONNULL, Botan::EC_Point::is_zero(), Botan::OS2ECP(), and Botan::EC_Point::xy_bytes().

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 90 of file ec_inner_bn.cpp.

90 {
91 return std::make_unique<EC_AffinePoint_Data_BN>(m_group, m_pt);
92}

◆ field_element_bytes()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 116 of file ec_inner_bn.cpp.

116 {
117 return m_group->p_bytes();
118}

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 94 of file ec_inner_bn.cpp.

94 {
95 return m_group;
96}

◆ is_identity()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 120 of file ec_inner_bn.cpp.

120 {
121 return m_xy.empty();
122}

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,
std::vector< BigInt > & ws ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 98 of file ec_inner_bn.cpp.

100 {
101 BOTAN_ARG_CHECK(scalar.group() == m_group, "Curve mismatch");
102 const auto& bn = EC_Scalar_Data_BN::checked_ref(scalar);
103
104 EC_Point_Var_Point_Precompute mul(m_pt, rng, ws);
105
106 // We pass order*cofactor here to "correctly" handle the case where the
107 // point is on the curve but not in the prime order subgroup. This only
108 // matters for groups with cofactor > 1
109 // See https://github.com/randombit/botan/issues/3800
110
111 const auto order = m_group->order() * m_group->cofactor();
112 auto pt = mul.mul(bn.value(), rng, order, ws);
113 return std::make_unique<EC_AffinePoint_Data_BN>(m_group, std::move(pt));
114}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
std::unique_ptr< EC_AffinePoint_Data > mul(const EC_Scalar_Data &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws) 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().

◆ 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 145 of file ec_inner_bn.cpp.

145 {
147 const size_t fe_bytes = this->field_element_bytes();
148 BOTAN_ARG_CHECK(bytes.size() == 1 + fe_bytes, "Invalid output size");
149 const bool y_is_odd = (m_xy[m_xy.size() - 1] & 0x01) == 0x01;
150
151 BufferStuffer stuffer(bytes);
152 stuffer.append(y_is_odd ? 0x03 : 0x02);
153 serialize_x_to(stuffer.next(fe_bytes));
154}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
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 156 of file ec_inner_bn.cpp.

156 {
158 const size_t fe_bytes = this->field_element_bytes();
159 BOTAN_ARG_CHECK(bytes.size() == 1 + 2 * fe_bytes, "Invalid output size");
160 BufferStuffer stuffer(bytes);
161 stuffer.append(0x04);
162 stuffer.append(m_xy);
163}

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 124 of file ec_inner_bn.cpp.

124 {
126 const size_t fe_bytes = this->field_element_bytes();
127 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
128 copy_mem(bytes, std::span{m_xy}.first(fe_bytes));
129}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146

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 138 of file ec_inner_bn.cpp.

138 {
140 const size_t fe_bytes = this->field_element_bytes();
141 BOTAN_ARG_CHECK(bytes.size() == 2 * fe_bytes, "Invalid output size");
142 copy_mem(bytes, m_xy);
143}

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 131 of file ec_inner_bn.cpp.

131 {
133 const size_t fe_bytes = this->field_element_bytes();
134 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
135 copy_mem(bytes, std::span{m_xy}.last(fe_bytes));
136}

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
inlineoverridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 83 of file ec_inner_bn.h.

83{ return m_pt; }

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