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

#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_iso (const FieldElement &a) const
constexpr Self dbl_n (size_t n) const
constexpr Self dbl_n_iso (const FieldElement &a, size_t n) const
constexpr CT::Choice is_identity () const
constexpr Self negate () const
constexpr Self & operator+= (const AffinePoint &other)
constexpr Self & operator+= (const Self &other)
ProjectiveCurvePoint & operator= (const Self &other)=default
ProjectiveCurvePoint & operator= (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 (const FieldElement &r)
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 std::pair< Self, FieldElement > add_mixed_h (const Self &a, const AffinePoint &b)
static constexpr Self add_mixed_iso (const Self &a, const AffinePoint &b, const FieldElement &curve_a)
static constexpr Self add_or_sub (const Self &a, const AffinePoint &b, CT::Choice sub)
static constexpr Self add_or_sub_iso (const Self &a, const AffinePoint &b, CT::Choice sub, const FieldElement &curve_a)
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 1011 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 1022 of file pcurves_impl.h.

◆ Self

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

Definition at line 1021 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 1054 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 1060 of file pcurves_impl.h.

1060 :
1061 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 1066 of file pcurves_impl.h.

1066 :
1067 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 1226 of file pcurves_impl.h.

1226{ 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 1228 of file pcurves_impl.h.

1228{ 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 1138 of file pcurves_impl.h.

1138{ 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 1102 of file pcurves_impl.h.

1102 {
1104 }
static constexpr FieldElement A
constexpr ProjectivePoint point_add_mixed(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)

References A, and Botan::point_add_mixed().

Referenced by operator+, and operator+.

◆ add_mixed_h()

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

Mixed point addition, additionally returning H (the sum has Z = a.z * H)

Definition at line 1116 of file pcurves_impl.h.

1116 {
1118 }
constexpr std::pair< ProjectivePoint, FieldElement > point_add_mixed_h(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)

References A, and Botan::point_add_mixed_h().

◆ add_mixed_iso()

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

Mixed point addition on an isomorphic curve with the given a coefficient

Definition at line 1109 of file pcurves_impl.h.

References Botan::point_add_mixed().

◆ 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 1121 of file pcurves_impl.h.

1121 {
1123 }
constexpr ProjectivePoint point_add_or_sub_mixed(const ProjectivePoint &a, const AffinePoint &b, CT::Choice sub, const FieldElement &one, const FieldElement &curve_a)

References A, and Botan::point_add_or_sub_mixed().

◆ add_or_sub_iso()

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

Either add or subtract, on an isomorphic curve with the given a coefficient

Definition at line 1128 of file pcurves_impl.h.

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 1095 of file pcurves_impl.h.

1095 {
1096 FieldElement::conditional_assign(m_x, m_y, m_z, cond, pt.x(), pt.y(), pt.z());
1097 }

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

◆ dbl()

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

Point doubling

Definition at line 1181 of file pcurves_impl.h.

1181 {
1182 if constexpr(Self::A_is_minus_3) {
1183 return dbl_a_minus_3(*this);
1184 } else if constexpr(Self::A_is_zero) {
1185 return dbl_a_zero(*this);
1186 } else {
1187 return dbl_generic(*this, A);
1188 }
1189 }
static constexpr bool A_is_zero
static constexpr bool A_is_minus_3
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_iso()

template<typename FieldElement, typename Params>
Self Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_iso ( const FieldElement & a) const
inlineconstexpr

Point doubling on an isomorphic curve with the given a coefficient

Definition at line 1170 of file pcurves_impl.h.

1170 {
1171 if constexpr(Self::A_is_zero) {
1172 return dbl_a_zero(*this);
1173 } else {
1174 return dbl_generic(*this, a);
1175 }
1176 }

References A_is_zero, 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 1143 of file pcurves_impl.h.

1143 {
1144 if constexpr(Self::A_is_minus_3) {
1145 return dbl_n_a_minus_3(*this, n);
1146 } else if constexpr(Self::A_is_zero) {
1147 return dbl_n_a_zero(*this, n);
1148 } else {
1149 return dbl_n_generic(*this, A, n);
1150 }
1151 }
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().

◆ dbl_n_iso()

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

Iterated point doubling on an isomorphic curve with the given a coefficient

If a is zero on this curve it is zero on any isomorphic curve, so the argument is ignored in that case.

Definition at line 1159 of file pcurves_impl.h.

1159 {
1160 if constexpr(Self::A_is_zero) {
1161 return dbl_n_a_zero(*this, n);
1162 } else {
1163 return dbl_n_generic(*this, a, n);
1164 }
1165 }

References A_is_zero, 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 1027 of file pcurves_impl.h.

1027 {
1028 /*
1029 * If the point is the identity element (x=0, y=0) then instead of
1030 * creating (x, y, 1) = (0, 0, 1) we want our projective identity
1031 * encoding of (0, 1, 0)
1032 *
1033 * Which we can achieve by a conditional swap of y and z if the
1034 * affine point is the identity.
1035 */
1036
1037 const auto x = pt.x();
1038 auto y = pt.y();
1039 auto z = FieldElement::one();
1040
1042
1043 return ProjectiveCurvePoint(x, y, z);
1044 }
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 1049 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 1093 of file pcurves_impl.h.

1093{ 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 1194 of file pcurves_impl.h.

1194{ 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 1086 of file pcurves_impl.h.

1086 {
1087 (*this) = (*this) + other;
1088 return (*this);
1089 }

◆ operator+=() [2/2]

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

Definition at line 1081 of file pcurves_impl.h.

1081 {
1082 (*this) = (*this) + other;
1083 return (*this);
1084 }

◆ 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 ( const FieldElement & r)
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 1202 of file pcurves_impl.h.

1202 {
1203 const auto r2 = r.square();
1204 const auto r3 = r2 * r;
1205
1206 m_x *= r2;
1207 m_y *= r3;
1208 m_z *= r;
1209 }

◆ x()

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

Return the projective x coordinate

Definition at line 1214 of file pcurves_impl.h.

1214{ 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 1219 of file pcurves_impl.h.

1219{ 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 1224 of file pcurves_impl.h.

1224{ 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 1079 of file pcurves_impl.h.

1079{ 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 1077 of file pcurves_impl.h.

1077{ 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 1075 of file pcurves_impl.h.

1075{ 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 1091 of file pcurves_impl.h.

1091{ 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 1016 of file pcurves_impl.h.

Referenced by add_mixed(), add_mixed_h(), add_or_sub(), 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 1019 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 1018 of file pcurves_impl.h.

Referenced by dbl(), dbl_iso(), dbl_n(), and dbl_n_iso().


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