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

#include <pcurves_impl.h>

Public Types

using AffinePoint = AffineCurvePoint<FieldElement>
using Self = ProjectiveCurvePoint<FieldElement, Params>

Public Member Functions

constexpr void _const_time_poison () const
constexpr void _const_time_unpoison () const
constexpr void conditional_assign (CT::Choice cond, const Self &pt)
constexpr Self dbl () const
constexpr Self dbl_n (size_t n) const
constexpr CT::Choice is_identity () const
constexpr Self negate () const
constexpr Selfoperator+= (const AffinePoint &other)
constexpr Selfoperator+= (const Self &other)
ProjectiveCurvePointoperator= (const Self &other)=default
ProjectiveCurvePointoperator= (Self &&other)=default
constexpr ProjectiveCurvePoint ()
constexpr ProjectiveCurvePoint (const FieldElement &x, const FieldElement &y)
constexpr ProjectiveCurvePoint (const FieldElement &x, const FieldElement &y, const FieldElement &z)
 ProjectiveCurvePoint (const Self &other)=default
 ProjectiveCurvePoint (Self &&other)=default
void randomize_rep (RandomNumberGenerator &rng)
constexpr const FieldElement & x () const
constexpr const FieldElement & y () const
constexpr const FieldElement & z () const
 ~ProjectiveCurvePoint ()=default

Static Public Member Functions

static constexpr Self add (const Self &a, const Self &b)
static constexpr Self add_mixed (const Self &a, const AffinePoint &b)
static constexpr Self add_or_sub (const Self &a, const AffinePoint &b, CT::Choice sub)
static constexpr Self from_affine (const AffinePoint &pt)
static constexpr Self identity ()

Static Public Attributes

static constexpr FieldElement A = FieldElement::from_words(Params::AW)
static constexpr bool A_is_minus_3 = (A == FieldElement::constant(-3)).as_bool()
static constexpr bool A_is_zero = A.is_zero().as_bool()

Friends

constexpr Self operator+ (const AffinePoint &a, const Self &b)
constexpr Self operator+ (const Self &a, const AffinePoint &b)
constexpr Self operator+ (const Self &a, const Self &b)
constexpr Self operator- (const Self &a, const Self &b)

Detailed Description

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

Projective curve point

This uses Jacobian coordinates

Definition at line 1000 of file pcurves_impl.h.

Member Typedef Documentation

◆ AffinePoint

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

Definition at line 1011 of file pcurves_impl.h.

◆ Self

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

Definition at line 1010 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ ProjectiveCurvePoint() [1/5]

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

Default constructor: the identity element

Definition at line 1043 of file pcurves_impl.h.

Referenced by from_affine(), operator=(), and operator=().

◆ ProjectiveCurvePoint() [2/5]

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

Affine constructor: take x/y coordinates

Definition at line 1049 of file pcurves_impl.h.

1049 :
1050 m_x(x), m_y(y), m_z(FieldElement::one()) {}
constexpr const FieldElement & x() const
constexpr const FieldElement & y() const

References x(), and y().

◆ ProjectiveCurvePoint() [3/5]

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

Projective constructor: take x/y/z coordinates

Definition at line 1055 of file pcurves_impl.h.

1055 :
1056 m_x(x), m_y(y), m_z(z) {}
constexpr const FieldElement & z() const

References x(), y(), and z().

◆ ProjectiveCurvePoint() [4/5]

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

◆ ProjectiveCurvePoint() [5/5]

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

◆ ~ProjectiveCurvePoint()

template<typename FieldElement, typename Params>
Botan::ProjectiveCurvePoint< FieldElement, Params >::~ProjectiveCurvePoint ( )
default

Member Function Documentation

◆ _const_time_poison()

template<typename FieldElement, typename Params>
void Botan::ProjectiveCurvePoint< FieldElement, Params >::_const_time_poison ( ) const
inlineconstexpr

Definition at line 1174 of file pcurves_impl.h.

1174{ CT::poison_all(m_x, m_y, m_z); }
constexpr void poison_all(const Ts &... ts)
Definition ct_utils.h:201

References Botan::CT::poison_all().

◆ _const_time_unpoison()

template<typename FieldElement, typename Params>
void Botan::ProjectiveCurvePoint< FieldElement, Params >::_const_time_unpoison ( ) const
inlineconstexpr

Definition at line 1176 of file pcurves_impl.h.

1176{ CT::unpoison_all(m_x, m_y, m_z); }
constexpr void unpoison_all(const Ts &... ts)
Definition ct_utils.h:207

References Botan::CT::unpoison_all().

◆ add()

template<typename FieldElement, typename Params>
constexpr Self Botan::ProjectiveCurvePoint< FieldElement, Params >::add ( const Self & a,
const Self & b )
inlinestaticconstexpr

Projective point addition

Definition at line 1103 of file pcurves_impl.h.

1103{ return point_add<Self, FieldElement>(a, b); }
constexpr ProjectivePoint point_add(const ProjectivePoint &a, const ProjectivePoint &b)

References Botan::point_add().

Referenced by operator+.

◆ add_mixed()

template<typename FieldElement, typename Params>
constexpr Self Botan::ProjectiveCurvePoint< FieldElement, Params >::add_mixed ( const Self & a,
const AffinePoint & b )
inlinestaticconstexpr

Mixed (projective + affine) point addition

Definition at line 1091 of file pcurves_impl.h.

1091 {
1093 }
constexpr ProjectivePoint point_add_mixed(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one)

References Botan::point_add_mixed().

Referenced by operator+, and operator+.

◆ add_or_sub()

template<typename FieldElement, typename Params>
constexpr Self Botan::ProjectiveCurvePoint< FieldElement, Params >::add_or_sub ( const Self & a,
const AffinePoint & b,
CT::Choice sub )
inlinestaticconstexpr

Definition at line 1096 of file pcurves_impl.h.

1096 {
1098 }
constexpr ProjectivePoint point_add_or_sub_mixed(const ProjectivePoint &a, const AffinePoint &b, CT::Choice sub, const FieldElement &one)

References Botan::point_add_or_sub_mixed().

◆ conditional_assign()

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

Definition at line 1084 of file pcurves_impl.h.

1084 {
1085 FieldElement::conditional_assign(m_x, m_y, m_z, cond, pt.x(), pt.y(), pt.z());
1086 }

References x(), y(), and z().

◆ dbl()

template<typename FieldElement, typename Params>
Self Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl ( ) const
inlineconstexpr

Point doubling

Definition at line 1121 of file pcurves_impl.h.

1121 {
1122 if constexpr(Self::A_is_minus_3) {
1123 return dbl_a_minus_3(*this);
1124 } else if constexpr(Self::A_is_zero) {
1125 return dbl_a_zero(*this);
1126 } else {
1127 return dbl_generic(*this, A);
1128 }
1129 }
static constexpr bool A_is_zero
static constexpr bool A_is_minus_3
static constexpr FieldElement A
constexpr ProjectivePoint dbl_a_minus_3(const ProjectivePoint &pt)
constexpr ProjectivePoint dbl_a_zero(const ProjectivePoint &pt)
constexpr ProjectivePoint dbl_generic(const ProjectivePoint &pt, const FieldElement &A)

References A, A_is_minus_3, A_is_zero, Botan::dbl_a_minus_3(), Botan::dbl_a_zero(), and Botan::dbl_generic().

◆ dbl_n()

template<typename FieldElement, typename Params>
Self Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n ( size_t n) const
inlineconstexpr

Iterated point doubling

Definition at line 1108 of file pcurves_impl.h.

1108 {
1109 if constexpr(Self::A_is_minus_3) {
1110 return dbl_n_a_minus_3(*this, n);
1111 } else if constexpr(Self::A_is_zero) {
1112 return dbl_n_a_zero(*this, n);
1113 } else {
1114 return dbl_n_generic(*this, A, n);
1115 }
1116 }
constexpr ProjectivePoint dbl_n_generic(const ProjectivePoint &pt, const FieldElement &A, size_t n)
constexpr ProjectivePoint dbl_n_a_zero(const ProjectivePoint &pt, size_t n)
constexpr ProjectivePoint dbl_n_a_minus_3(const ProjectivePoint &pt, size_t n)

References A, A_is_minus_3, A_is_zero, Botan::dbl_n_a_minus_3(), Botan::dbl_n_a_zero(), and Botan::dbl_n_generic().

◆ from_affine()

template<typename FieldElement, typename Params>
constexpr Self Botan::ProjectiveCurvePoint< FieldElement, Params >::from_affine ( const AffinePoint & pt)
inlinestaticconstexpr

Convert a point from affine to projective form

Definition at line 1016 of file pcurves_impl.h.

1016 {
1017 /*
1018 * If the point is the identity element (x=0, y=0) then instead of
1019 * creating (x, y, 1) = (0, 0, 1) we want our projective identity
1020 * encoding of (0, 1, 0)
1021 *
1022 * Which we can achieve by a conditional swap of y and z if the
1023 * affine point is the identity.
1024 */
1025
1026 auto x = pt.x();
1027 auto y = pt.y();
1028 auto z = FieldElement::one();
1029
1031
1032 return ProjectiveCurvePoint(x, y, z);
1033 }
constexpr CT::Choice is_identity() const

References Botan::AffineCurvePoint< FieldElement >::is_identity(), ProjectiveCurvePoint(), Botan::AffineCurvePoint< FieldElement >::x(), x(), Botan::AffineCurvePoint< FieldElement >::y(), y(), and z().

◆ identity()

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

Return the identity element

Definition at line 1038 of file pcurves_impl.h.

ProjectiveCurvePoint< FieldElement, Params > Self

◆ is_identity()

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

Definition at line 1082 of file pcurves_impl.h.

1082{ return z().is_zero(); }

References z().

◆ negate()

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

Point negation

Definition at line 1134 of file pcurves_impl.h.

1134{ return Self(x(), y().negate(), z()); }
constexpr Self negate() const

References negate(), x(), y(), and z().

Referenced by negate(), and operator-.

◆ operator+=() [1/2]

template<typename FieldElement, typename Params>
Self & Botan::ProjectiveCurvePoint< FieldElement, Params >::operator+= ( const AffinePoint & other)
inlineconstexpr

Definition at line 1075 of file pcurves_impl.h.

1075 {
1076 (*this) = (*this) + other;
1077 return (*this);
1078 }

◆ operator+=() [2/2]

template<typename FieldElement, typename Params>
Self & Botan::ProjectiveCurvePoint< FieldElement, Params >::operator+= ( const Self & other)
inlineconstexpr

Definition at line 1070 of file pcurves_impl.h.

1070 {
1071 (*this) = (*this) + other;
1072 return (*this);
1073 }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ randomize_rep()

template<typename FieldElement, typename Params>
void Botan::ProjectiveCurvePoint< FieldElement, Params >::randomize_rep ( RandomNumberGenerator & rng)
inline

Randomize the point representation

Projective coordinates are redundant; if (x,y,z) is a projective point then so is (x*r^2,y*r^3,z*r) for any non-zero r.

Definition at line 1142 of file pcurves_impl.h.

1142 {
1143 // In certain contexts we may be called with a Null_RNG; in that case the
1144 // caller is accepting that randomization will not occur
1145
1146 // Conditional ok: caller's RNG state (seeded vs not) is presumed public
1147 if(rng.is_seeded()) {
1148 auto r = FieldElement::random(rng);
1149
1150 auto r2 = r.square();
1151 auto r3 = r2 * r;
1152
1153 m_x *= r2;
1154 m_y *= r3;
1155 m_z *= r;
1156 }
1157 }

References Botan::RandomNumberGenerator::is_seeded().

◆ x()

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

Return the projective x coordinate

Definition at line 1162 of file pcurves_impl.h.

1162{ return m_x; }

Referenced by conditional_assign(), from_affine(), negate(), ProjectiveCurvePoint(), and ProjectiveCurvePoint().

◆ y()

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

Return the projective y coordinate

Definition at line 1167 of file pcurves_impl.h.

1167{ return m_y; }

Referenced by conditional_assign(), from_affine(), negate(), ProjectiveCurvePoint(), and ProjectiveCurvePoint().

◆ z()

template<typename FieldElement, typename Params>
const FieldElement & Botan::ProjectiveCurvePoint< FieldElement, Params >::z ( ) const
inlineconstexpr

Return the projective z coordinate

Definition at line 1172 of file pcurves_impl.h.

1172{ return m_z; }

Referenced by conditional_assign(), from_affine(), is_identity(), negate(), and ProjectiveCurvePoint().

◆ operator+ [1/3]

template<typename FieldElement, typename Params>
Self operator+ ( const AffinePoint & a,
const Self & b )
friend

Definition at line 1068 of file pcurves_impl.h.

1068{ return Self::add_mixed(b, a); }
static constexpr Self add_mixed(const Self &a, const AffinePoint &b)

References add_mixed().

◆ operator+ [2/3]

template<typename FieldElement, typename Params>
Self operator+ ( const Self & a,
const AffinePoint & b )
friend

Definition at line 1066 of file pcurves_impl.h.

1066{ return Self::add_mixed(a, b); }

References add_mixed().

◆ operator+ [3/3]

template<typename FieldElement, typename Params>
Self operator+ ( const Self & a,
const Self & b )
friend

Definition at line 1064 of file pcurves_impl.h.

1064{ return Self::add(a, b); }
static constexpr Self add(const Self &a, const Self &b)

References add().

◆ operator-

template<typename FieldElement, typename Params>
Self operator- ( const Self & a,
const Self & b )
friend

Definition at line 1080 of file pcurves_impl.h.

1080{ return a + b.negate(); }

References negate().

Member Data Documentation

◆ A

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

Definition at line 1005 of file pcurves_impl.h.

Referenced by dbl(), and dbl_n().

◆ A_is_minus_3

template<typename FieldElement, typename Params>
bool Botan::ProjectiveCurvePoint< FieldElement, Params >::A_is_minus_3 = (A == FieldElement::constant(-3)).as_bool()
staticconstexpr

Definition at line 1008 of file pcurves_impl.h.

Referenced by dbl(), and dbl_n().

◆ A_is_zero

template<typename FieldElement, typename Params>
bool Botan::ProjectiveCurvePoint< FieldElement, Params >::A_is_zero = A.is_zero().as_bool()
staticconstexpr

Definition at line 1007 of file pcurves_impl.h.

Referenced by dbl(), and dbl_n().


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