Botan 3.6.1
Crypto and TLS for C&
Botan::EC_AffinePoint_Data_PC Class Referencefinal

#include <ec_inner_pc.h>

Inheritance diagram for Botan::EC_AffinePoint_Data_PC:
Botan::EC_AffinePoint_Data

Public Member Functions

std::unique_ptr< EC_AffinePoint_Dataclone () const override
 
 EC_AffinePoint_Data_PC (std::shared_ptr< const EC_Group_Data > group, PCurve::PrimeOrderCurve::AffinePoint pt)
 
 EC_AffinePoint_Data_PC (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
 
const PCurve::PrimeOrderCurve::AffinePointvalue () const
 

Static Public Member Functions

static const EC_AffinePoint_Data_PCchecked_ref (const EC_AffinePoint_Data &data)
 

Detailed Description

Definition at line 56 of file ec_inner_pc.h.

Constructor & Destructor Documentation

◆ EC_AffinePoint_Data_PC() [1/2]

Botan::EC_AffinePoint_Data_PC::EC_AffinePoint_Data_PC ( std::shared_ptr< const EC_Group_Data > group,
PCurve::PrimeOrderCurve::AffinePoint pt )

Definition at line 86 of file ec_inner_pc.cpp.

87 :
88 m_group(std::move(group)), m_pt(std::move(pt)) {
89 if(!m_pt.is_identity()) {
90 m_xy = m_pt.serialize<secure_vector<uint8_t>>();
91 BOTAN_ASSERT_NOMSG(m_xy.size() == 1 + 2 * field_element_bytes());
92 }
93}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
size_t field_element_bytes() const override
const std::shared_ptr< const EC_Group_Data > & group() const override
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References Botan::PCurve::PrimeOrderCurve::AffinePoint::is_identity().

◆ EC_AffinePoint_Data_PC() [2/2]

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

Definition at line 95 of file ec_inner_pc.cpp.

96 :
97 m_group(std::move(group)), m_pt(deserialize_pcurve_pt(m_group->pcurve(), bytes)) {
98 if(!m_pt.is_identity()) {
99 m_xy = m_pt.serialize<secure_vector<uint8_t>>();
100 BOTAN_ASSERT_NOMSG(m_xy.size() == 1 + 2 * field_element_bytes());
101 }
102}

References Botan::PCurve::PrimeOrderCurve::AffinePoint::is_identity().

Member Function Documentation

◆ checked_ref()

const EC_AffinePoint_Data_PC & Botan::EC_AffinePoint_Data_PC::checked_ref ( const EC_AffinePoint_Data & data)
static

Definition at line 104 of file ec_inner_pc.cpp.

104 {
105 const auto* p = dynamic_cast<const EC_AffinePoint_Data_PC*>(&data);
106 if(!p) {
107 throw Invalid_State("Failed conversion to EC_AffinePoint_Data_PC");
108 }
109 return *p;
110}
EC_AffinePoint_Data_PC(std::shared_ptr< const EC_Group_Data > group, PCurve::PrimeOrderCurve::AffinePoint pt)

Referenced by Botan::EC_Mul2Table_Data_PC::EC_Mul2Table_Data_PC().

◆ clone()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 112 of file ec_inner_pc.cpp.

112 {
113 return std::make_unique<EC_AffinePoint_Data_PC>(m_group, m_pt);
114}

◆ field_element_bytes()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 131 of file ec_inner_pc.cpp.

131 {
132 return m_group->pcurve().field_element_bytes();
133}

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

◆ group()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 116 of file ec_inner_pc.cpp.

116 {
117 return m_group;
118}

◆ is_identity()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 135 of file ec_inner_pc.cpp.

135 {
136 return m_xy.empty();
137}

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

◆ mul()

std::unique_ptr< EC_AffinePoint_Data > Botan::EC_AffinePoint_Data_PC::mul ( const EC_Scalar_Data & scalar,
RandomNumberGenerator & rng,
std::vector< BigInt > & ws ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 120 of file ec_inner_pc.cpp.

122 {
123 BOTAN_UNUSED(ws);
124
125 BOTAN_ARG_CHECK(scalar.group() == m_group, "Curve mismatch");
126 const auto& k = EC_Scalar_Data_PC::checked_ref(scalar).value();
127 auto pt = m_group->pcurve().mul(m_pt, k, rng).to_affine();
128 return std::make_unique<EC_AffinePoint_Data_PC>(m_group, std::move(pt));
129}
#define BOTAN_UNUSED
Definition assert.h:118
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
static const EC_Scalar_Data_PC & checked_ref(const EC_Scalar_Data &data)
const auto & value() const
Definition ec_inner_pc.h:49

References BOTAN_ARG_CHECK, BOTAN_UNUSED, Botan::EC_Scalar_Data_PC::checked_ref(), Botan::EC_Scalar_Data::group(), and Botan::EC_Scalar_Data_PC::value().

◆ serialize_compressed_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 160 of file ec_inner_pc.cpp.

160 {
162 const size_t fe_bytes = this->field_element_bytes();
163 BOTAN_ARG_CHECK(bytes.size() == 1 + fe_bytes, "Invalid output size");
164 const bool y_is_odd = (m_xy.back() & 0x01) == 0x01;
165
166 BufferStuffer stuffer(bytes);
167 stuffer.append(y_is_odd ? 0x03 : 0x02);
168 this->serialize_x_to(stuffer.next(fe_bytes));
169}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
bool is_identity() const override
void serialize_x_to(std::span< uint8_t > bytes) 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_PC::serialize_uncompressed_to ( std::span< uint8_t > bytes) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 171 of file ec_inner_pc.cpp.

171 {
173 const size_t fe_bytes = this->field_element_bytes();
174 BOTAN_ARG_CHECK(bytes.size() == 1 + 2 * fe_bytes, "Invalid output size");
175 copy_mem(bytes, m_xy);
176}
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().

◆ serialize_x_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 139 of file ec_inner_pc.cpp.

139 {
141 const size_t fe_bytes = this->field_element_bytes();
142 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
143 copy_mem(bytes, std::span{m_xy}.subspan(1, fe_bytes));
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_PC::serialize_xy_to ( std::span< uint8_t > bytes) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 153 of file ec_inner_pc.cpp.

153 {
155 const size_t fe_bytes = this->field_element_bytes();
156 BOTAN_ARG_CHECK(bytes.size() == 2 * fe_bytes, "Invalid output size");
157 copy_mem(bytes, std::span{m_xy}.last(2 * fe_bytes));
158}

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

◆ serialize_y_to()

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

Implements Botan::EC_AffinePoint_Data.

Definition at line 146 of file ec_inner_pc.cpp.

146 {
148 const size_t fe_bytes = this->field_element_bytes();
149 BOTAN_ARG_CHECK(bytes.size() == fe_bytes, "Invalid output size");
150 copy_mem(bytes, std::span{m_xy}.subspan(1 + fe_bytes, fe_bytes));
151}

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_PC::to_legacy_point ( ) const
overridevirtual

Implements Botan::EC_AffinePoint_Data.

Definition at line 178 of file ec_inner_pc.cpp.

178 {
179 if(this->is_identity()) {
180 return EC_Point(m_group->curve());
181 } else {
182 const size_t fe_bytes = this->field_element_bytes();
183 return EC_Point(m_group->curve(),
184 BigInt::from_bytes(std::span{m_xy}.subspan(1, fe_bytes)),
185 BigInt::from_bytes(std::span{m_xy}.last(fe_bytes)));
186 }
187}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:95

References field_element_bytes(), Botan::BigInt::from_bytes(), and is_identity().

◆ value()

const PCurve::PrimeOrderCurve::AffinePoint & Botan::EC_AffinePoint_Data_PC::value ( ) const
inline

Definition at line 86 of file ec_inner_pc.h.

86{ return m_pt; }

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