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

#include <pcurves_impl.h>

Public Types

using AffinePoint = AffineCurvePoint<FieldElement, Params>
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 966 of file pcurves_impl.h.

Member Typedef Documentation

◆ AffinePoint

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

Definition at line 977 of file pcurves_impl.h.

◆ Self

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

Definition at line 976 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 1009 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 1015 of file pcurves_impl.h.

1015 :
1016 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 1021 of file pcurves_impl.h.

1021 :
1022 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 1140 of file pcurves_impl.h.

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

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

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

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

1069{ 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 1057 of file pcurves_impl.h.

1057 {
1059 }
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 1062 of file pcurves_impl.h.

1062 {
1064 }
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 1050 of file pcurves_impl.h.

1050 {
1051 FieldElement::conditional_assign(m_x, m_y, m_z, cond, pt.x(), pt.y(), pt.z());
1052 }

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

◆ dbl()

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

Point doubling

Definition at line 1087 of file pcurves_impl.h.

1087 {
1088 if constexpr(Self::A_is_minus_3) {
1089 return dbl_a_minus_3(*this);
1090 } else if constexpr(Self::A_is_zero) {
1091 return dbl_a_zero(*this);
1092 } else {
1093 return dbl_generic(*this, A);
1094 }
1095 }
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 1074 of file pcurves_impl.h.

1074 {
1075 if constexpr(Self::A_is_minus_3) {
1076 return dbl_n_a_minus_3(*this, n);
1077 } else if constexpr(Self::A_is_zero) {
1078 return dbl_n_a_zero(*this, n);
1079 } else {
1080 return dbl_n_generic(*this, A, n);
1081 }
1082 }
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 982 of file pcurves_impl.h.

982 {
983 /*
984 * If the point is the identity element (x=0, y=0) then instead of
985 * creating (x, y, 1) = (0, 0, 1) we want our projective identity
986 * encoding of (0, 1, 0)
987 *
988 * Which we can achieve by a conditional swap of y and z if the
989 * affine point is the identity.
990 */
991
992 auto x = pt.x();
993 auto y = pt.y();
994 auto z = FieldElement::one();
995
997
998 return ProjectiveCurvePoint(x, y, z);
999 }
constexpr CT::Choice is_identity() const

References Botan::AffineCurvePoint< FieldElement, Params >::is_identity(), ProjectiveCurvePoint(), Botan::AffineCurvePoint< FieldElement, Params >::x(), x(), Botan::AffineCurvePoint< FieldElement, Params >::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 1004 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 1048 of file pcurves_impl.h.

1048{ 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 1100 of file pcurves_impl.h.

1100{ 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 1041 of file pcurves_impl.h.

1041 {
1042 (*this) = (*this) + other;
1043 return (*this);
1044 }

◆ operator+=() [2/2]

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

Definition at line 1036 of file pcurves_impl.h.

1036 {
1037 (*this) = (*this) + other;
1038 return (*this);
1039 }

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

1108 {
1109 // In certain contexts we may be called with a Null_RNG; in that case the
1110 // caller is accepting that randomization will not occur
1111
1112 // Conditional ok: caller's RNG state (seeded vs not) is presumed public
1113 if(rng.is_seeded()) {
1114 auto r = FieldElement::random(rng);
1115
1116 auto r2 = r.square();
1117 auto r3 = r2 * r;
1118
1119 m_x *= r2;
1120 m_y *= r3;
1121 m_z *= r;
1122 }
1123 }

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

1128{ 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 1133 of file pcurves_impl.h.

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

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

1034{ 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 1032 of file pcurves_impl.h.

1032{ 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 1030 of file pcurves_impl.h.

1030{ 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 1046 of file pcurves_impl.h.

1046{ 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 971 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 974 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 973 of file pcurves_impl.h.

Referenced by dbl(), and dbl_n().


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