9 NAMESPACE_BEGIN(CryptoPP)
14 ECPPoint() : identity(
true) {}
16 : identity(
false), x(x), y(y) {}
18 bool operator==(
const ECPPoint &t)
const
19 {
return (identity && t.identity) || (!identity && !t.identity && x==t.x && y==t.y);}
21 {
return identity ? !t.identity : (!t.identity && (x<t.x || (x==t.x && y<t.y)));}
38 ECP(
const ECP &ecp,
bool convertToMontgomeryRepresentation =
false);
39 ECP(
const Integer &modulus,
const FieldElement &a,
const FieldElement &b)
40 : m_fieldPtr(
new Field(modulus)), m_a(a.IsNegative() ? modulus+a : a), m_b(b) {}
48 bool Equal(
const Point &P,
const Point &Q)
const;
49 const Point& Identity()
const;
50 const Point& Inverse(
const Point &P)
const;
51 bool InversionIsFast()
const {
return true;}
52 const Point& Add(
const Point &P,
const Point &Q)
const;
53 const Point& Double(
const Point &P)
const;
54 Point ScalarMultiply(
const Point &P,
const Integer &k)
const;
55 Point CascadeScalarMultiply(
const Point &P,
const Integer &k1,
const Point &Q,
const Integer &k2)
const;
56 void SimultaneousMultiply(Point *results,
const Point &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
58 Point Multiply(
const Integer &k,
const Point &P)
const
59 {
return ScalarMultiply(P, k);}
60 Point CascadeMultiply(
const Integer &k1,
const Point &P,
const Integer &k2,
const Point &Q)
const
61 {
return CascadeScalarMultiply(P, k1, Q, k2);}
64 bool VerifyPoint(
const Point &P)
const;
66 unsigned int EncodedPointSize(
bool compressed =
false)
const
67 {
return 1 + (compressed?1:2)*GetField().MaxElementByteLength();}
70 bool DecodePoint(Point &P,
const byte *encodedPoint,
size_t len)
const;
71 void EncodePoint(byte *encodedPoint,
const Point &P,
bool compressed)
const;
77 Integer FieldSize()
const {
return GetField().GetModulus();}
78 const Field & GetField()
const {
return *m_fieldPtr;}
79 const FieldElement & GetA()
const {
return m_a;}
80 const FieldElement & GetB()
const {
return m_b;}
82 bool operator==(
const ECP &rhs)
const
83 {
return GetField() == rhs.GetField() && m_a == rhs.m_a && m_b == rhs.m_b;}
87 FieldElement m_a, m_b;
103 bool NeedConversions()
const {
return true;}
105 {
return P.identity ? P :
ECP::Point(m_ec->GetField().ConvertIn(P.x), m_ec->GetField().ConvertIn(P.y));};
107 {
return P.identity ? P :
ECP::Point(m_ec->GetField().ConvertOut(P.x), m_ec->GetField().ConvertOut(P.y));}
113 void SetCurve(
const ECP &ec)
115 m_ec.reset(
new ECP(ec,
true));
118 const ECP & GetCurve()
const {
return *m_ecOriginal;}
This file contains helper classes/functions for implementing public key algorithms.
Elliptic Curve over GF(p), where p is prime.
ring of congruence classes modulo n
interface for random number generators
multiple precision integer and basic arithmetics
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree