Botan 3.5.0
Crypto and TLS for C&
Botan::AffineCurvePoint< FieldElement, Params > Class Template Reference

#include <pcurves_impl.h>

Public Types

using Self = AffineCurvePoint<FieldElement, Params>
 

Public Member Functions

constexpr AffineCurvePoint ()
 
constexpr AffineCurvePoint (const FieldElement &x, const FieldElement &y)
 
 AffineCurvePoint (const Self &other)=default
 
 AffineCurvePoint (Self &&other)=default
 
constexpr void conditional_assign (CT::Choice cond, const Self &pt)
 
constexpr void ct_poison () const
 
constexpr void ct_unpoison () const
 
constexpr CT::Choice is_identity () const
 
constexpr Self negate () const
 
AffineCurvePointoperator= (const Self &other)=default
 
AffineCurvePointoperator= (Self &&other)=default
 
constexpr void serialize_compressed_to (std::span< uint8_t, Self::COMPRESSED_BYTES > bytes) const
 
constexpr void serialize_to (std::span< uint8_t, Self::BYTES > bytes) const
 
constexpr const FieldElement & x () const
 
constexpr const FieldElement & y () const
 

Static Public Member Functions

static constexpr auto ct_select (std::span< const Self > pts, size_t idx)
 
static constexpr std::optional< Selfdeserialize (std::span< const uint8_t > bytes)
 
static constexpr Self identity ()
 
static constexpr FieldElement x3_ax_b (const FieldElement &x)
 

Static Public Attributes

static constexpr FieldElement A = FieldElement::from_words(Params::AW)
 
static constexpr FieldElement B = FieldElement::from_words(Params::BW)
 
static constexpr size_t BYTES = 1 + 2 * FieldElement::BYTES
 
static constexpr size_t COMPRESSED_BYTES = 1 + FieldElement::BYTES
 

Detailed Description

template<typename FieldElement, typename Params>
class Botan::AffineCurvePoint< FieldElement, Params >

Definition at line 416 of file pcurves_impl.h.

Member Typedef Documentation

◆ Self

template<typename FieldElement , typename Params >
using Botan::AffineCurvePoint< FieldElement, Params >::Self = AffineCurvePoint<FieldElement, Params>

Definition at line 427 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ AffineCurvePoint() [1/4]

template<typename FieldElement , typename Params >
Botan::AffineCurvePoint< FieldElement, Params >::AffineCurvePoint ( const FieldElement & x,
const FieldElement & y )
inlineconstexpr

Definition at line 429 of file pcurves_impl.h.

429: m_x(x), m_y(y) {}
constexpr const FieldElement & y() const
constexpr const FieldElement & x() const

◆ AffineCurvePoint() [2/4]

template<typename FieldElement , typename Params >
Botan::AffineCurvePoint< FieldElement, Params >::AffineCurvePoint ( )
inlineconstexpr

Definition at line 431 of file pcurves_impl.h.

431: m_x(FieldElement::zero()), m_y(FieldElement::zero()) {}

◆ AffineCurvePoint() [3/4]

template<typename FieldElement , typename Params >
Botan::AffineCurvePoint< FieldElement, Params >::AffineCurvePoint ( const Self & other)
default

◆ AffineCurvePoint() [4/4]

template<typename FieldElement , typename Params >
Botan::AffineCurvePoint< FieldElement, Params >::AffineCurvePoint ( Self && other)
default

Member Function Documentation

◆ conditional_assign()

template<typename FieldElement , typename Params >
void Botan::AffineCurvePoint< FieldElement, Params >::conditional_assign ( CT::Choice cond,
const Self & pt )
inlineconstexpr

Definition at line 520 of file pcurves_impl.h.

520 {
521 m_x.conditional_assign(cond, pt.x());
522 m_y.conditional_assign(cond, pt.y());
523 }

References Botan::AffineCurvePoint< FieldElement, Params >::x(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ ct_poison()

template<typename FieldElement , typename Params >
void Botan::AffineCurvePoint< FieldElement, Params >::ct_poison ( ) const
inlineconstexpr

Definition at line 525 of file pcurves_impl.h.

525 {
526 x().ct_poison();
527 y().ct_poison();
528 }

References Botan::AffineCurvePoint< FieldElement, Params >::x(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ ct_select()

template<typename FieldElement , typename Params >
static constexpr auto Botan::AffineCurvePoint< FieldElement, Params >::ct_select ( std::span< const Self > pts,
size_t idx )
inlinestaticconstexpr

If idx is zero then return the identity element. Otherwise return pts[idx - 1]

Returns the identity element also if idx is out of range

Definition at line 466 of file pcurves_impl.h.

466 {
467 auto result = Self::identity();
468
469 // Intentionally wrapping; set to maximum size_t if idx == 0
470 const size_t idx1 = static_cast<size_t>(idx - 1);
471 for(size_t i = 0; i != pts.size(); ++i) {
472 const auto found = CT::Mask<size_t>::is_equal(idx1, i).as_choice();
473 result.conditional_assign(found, pts[i]);
474 }
475
476 return result;
477 }
static constexpr Self identity()
static constexpr Mask< T > is_equal(T x, T y)
Definition ct_utils.h:250

References Botan::AffineCurvePoint< FieldElement, Params >::identity(), and Botan::CT::Mask< T >::is_equal().

◆ ct_unpoison()

template<typename FieldElement , typename Params >
void Botan::AffineCurvePoint< FieldElement, Params >::ct_unpoison ( ) const
inlineconstexpr

Definition at line 530 of file pcurves_impl.h.

530 {
531 x().ct_unpoison();
532 y().ct_unpoison();
533 }

References Botan::AffineCurvePoint< FieldElement, Params >::x(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ deserialize()

template<typename FieldElement , typename Params >
static constexpr std::optional< Self > Botan::AffineCurvePoint< FieldElement, Params >::deserialize ( std::span< const uint8_t > bytes)
inlinestaticconstexpr

Definition at line 481 of file pcurves_impl.h.

481 {
482 if(bytes.size() == Self::BYTES) {
483 if(bytes[0] != 0x04) {
484 return {};
485 }
486 auto x = FieldElement::deserialize(bytes.subspan(1, FieldElement::BYTES));
487 auto y = FieldElement::deserialize(bytes.subspan(1 + FieldElement::BYTES, FieldElement::BYTES));
488
489 if(x && y) {
490 const auto lhs = (*y).square();
491 const auto rhs = Self::x3_ax_b(*x);
492 if((lhs == rhs).as_bool()) {
493 return Self(*x, *y);
494 }
495 }
496
497 return {};
498 } else if(bytes.size() == Self::COMPRESSED_BYTES) {
499 if(bytes[0] != 0x02 && bytes[0] != 0x03) {
500 return {};
501 }
502 const CT::Choice y_is_even = CT::Mask<uint8_t>::is_equal(bytes[0], 0x02).as_choice();
503
504 if(auto x = FieldElement::deserialize(bytes.subspan(1, FieldElement::BYTES))) {
505 auto y = x3_ax_b(*x).sqrt();
506 y.conditional_assign(y_is_even && !y.is_even(), y.negate());
507 return Self(*x, y);
508 }
509
510 return {};
511 } else {
512 return {};
513 }
514 }
static constexpr size_t BYTES
static constexpr FieldElement x3_ax_b(const FieldElement &x)
static constexpr size_t COMPRESSED_BYTES
AffineCurvePoint< FieldElement, Params > Self

References Botan::AffineCurvePoint< FieldElement, Params >::BYTES, Botan::AffineCurvePoint< FieldElement, Params >::COMPRESSED_BYTES, Botan::CT::Mask< T >::is_equal(), Botan::AffineCurvePoint< FieldElement, Params >::x(), Botan::AffineCurvePoint< FieldElement, Params >::x3_ax_b(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ identity()

template<typename FieldElement , typename Params >
static constexpr Self Botan::AffineCurvePoint< FieldElement, Params >::identity ( )
inlinestaticconstexpr

◆ is_identity()

template<typename FieldElement , typename Params >
CT::Choice Botan::AffineCurvePoint< FieldElement, Params >::is_identity ( ) const
inlineconstexpr

◆ negate()

template<typename FieldElement , typename Params >
Self Botan::AffineCurvePoint< FieldElement, Params >::negate ( ) const
inlineconstexpr

◆ operator=() [1/2]

template<typename FieldElement , typename Params >
AffineCurvePoint & Botan::AffineCurvePoint< FieldElement, Params >::operator= ( const Self & other)
default

◆ operator=() [2/2]

template<typename FieldElement , typename Params >
AffineCurvePoint & Botan::AffineCurvePoint< FieldElement, Params >::operator= ( Self && other)
default

◆ serialize_compressed_to()

template<typename FieldElement , typename Params >
void Botan::AffineCurvePoint< FieldElement, Params >::serialize_compressed_to ( std::span< uint8_t, Self::COMPRESSED_BYTES > bytes) const
inlineconstexpr

Definition at line 452 of file pcurves_impl.h.

452 {
453 const uint8_t hdr = CT::Mask<uint8_t>::from_choice(y().is_even()).select(0x02, 0x03);
454
455 BufferStuffer pack(bytes);
456 pack.append(hdr);
457 x().serialize_to(pack.next<FieldElement::BYTES>());
458 BOTAN_DEBUG_ASSERT(pack.full());
459 }
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98
static constexpr Mask< T > from_choice(Choice c)
Definition ct_utils.h:218

References Botan::BufferStuffer::append(), BOTAN_DEBUG_ASSERT, Botan::CT::Mask< T >::from_choice(), Botan::BufferStuffer::full(), Botan::BufferStuffer::next(), Botan::AffineCurvePoint< FieldElement, Params >::x(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ serialize_to()

template<typename FieldElement , typename Params >
void Botan::AffineCurvePoint< FieldElement, Params >::serialize_to ( std::span< uint8_t, Self::BYTES > bytes) const
inlineconstexpr

Definition at line 444 of file pcurves_impl.h.

444 {
445 BufferStuffer pack(bytes);
446 pack.append(0x04);
447 x().serialize_to(pack.next<FieldElement::BYTES>());
448 y().serialize_to(pack.next<FieldElement::BYTES>());
449 BOTAN_DEBUG_ASSERT(pack.full());
450 }

References Botan::BufferStuffer::append(), BOTAN_DEBUG_ASSERT, Botan::BufferStuffer::full(), Botan::BufferStuffer::next(), Botan::AffineCurvePoint< FieldElement, Params >::x(), and Botan::AffineCurvePoint< FieldElement, Params >::y().

◆ x()

◆ x3_ax_b()

template<typename FieldElement , typename Params >
static constexpr FieldElement Botan::AffineCurvePoint< FieldElement, Params >::x3_ax_b ( const FieldElement & x)
inlinestaticconstexpr

◆ y()

Member Data Documentation

◆ A

template<typename FieldElement , typename Params >
FieldElement Botan::AffineCurvePoint< FieldElement, Params >::A = FieldElement::from_words(Params::AW)
staticconstexpr

◆ B

template<typename FieldElement , typename Params >
FieldElement Botan::AffineCurvePoint< FieldElement, Params >::B = FieldElement::from_words(Params::BW)
staticconstexpr

◆ BYTES

template<typename FieldElement , typename Params >
size_t Botan::AffineCurvePoint< FieldElement, Params >::BYTES = 1 + 2 * FieldElement::BYTES
staticconstexpr

◆ COMPRESSED_BYTES

template<typename FieldElement , typename Params >
size_t Botan::AffineCurvePoint< FieldElement, Params >::COMPRESSED_BYTES = 1 + FieldElement::BYTES
staticconstexpr

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