5 #ifndef CRYPTOPP_IMPORTS 20 return P.identity ? P :
ECP::Point(mr.ConvertIn(P.x), mr.ConvertIn(P.y));
29 ECP::ECP(
const ECP &ecp,
bool convertToMontgomeryRepresentation)
75 if (encodedPointLen < 1 || !bt.
Get(type))
100 if ((type & 1) != P.
y.
GetBit(0))
185 && !(((x*x+
m_a)*x+
m_b-y*y)%p));
254 size_t n = end-begin;
259 std::vector<T> vec((n+1)/2);
263 for (i=0, it=begin; i<n/2; i++, it+=2)
264 vec[i] = ring.
Multiply(*it, *(it+1));
270 for (i=0, it=begin; i<n/2; i++, it+=2)
281 *(it+1) = ring.
Multiply(*(it+1), vec[i]);
293 : x(x), y(y), z(z) {}
302 : mr(m_mr), firstDoubling(true), negated(false)
333 sixteenY4 = mr.
Square(fourY2);
346 ZIterator(std::vector<ProjectivePoint>::iterator it) : it(it) {}
351 std::vector<ProjectivePoint>::iterator
it;
366 if (!
GetField().IsMontgomeryRepresentation())
368 ECP ecpmr(*
this,
true);
371 for (
unsigned int i=0; i<expCount; i++)
372 results[i] = FromMontgomery(mr, results[i]);
377 std::vector<ProjectivePoint> bases;
378 std::vector<WindowSlider> exponents;
379 exponents.reserve(expCount);
380 std::vector<std::vector<word32> > baseIndices(expCount);
381 std::vector<std::vector<bool> > negateBase(expCount);
382 std::vector<std::vector<word32> > exponentWindows(expCount);
385 for (i=0; i<expCount; i++)
389 exponents[i].FindNextWindow();
392 unsigned int expBitPosition = 0;
398 bool baseAdded =
false;
399 for (i=0; i<expCount; i++)
401 if (!exponents[i].finished && expBitPosition == exponents[i].windowBegin)
405 bases.push_back(rd.
P);
409 exponentWindows[i].push_back(exponents[i].expWindow);
410 baseIndices[i].push_back((
word32)bases.size()-1);
411 negateBase[i].push_back(exponents[i].negateNext);
413 exponents[i].FindNextWindow();
415 notDone = notDone || !exponents[i].finished;
427 for (i=0; i<bases.size(); i++)
429 if (bases[i].
z.NotZero())
438 std::vector<BaseAndExponent<Point, Integer> > finalCascade;
439 for (i=0; i<expCount; i++)
441 finalCascade.resize(baseIndices[i].
size());
442 for (
unsigned int j=0; j<baseIndices[i].size(); j++)
446 finalCascade[j].base.identity =
true;
449 finalCascade[j].base.identity =
false;
450 finalCascade[j].base.
x = base.
x;
451 if (negateBase[i][j])
454 finalCascade[j].base.y = base.
y;
464 if (!
GetField().IsMontgomeryRepresentation())
466 ECP ecpmr(*
this,
true);
468 return FromMontgomery(mr, ecpmr.
CascadeScalarMultiply(ToMontgomery(mr, P), k1, ToMontgomery(mr, Q), k2));
const Point & Identity() const
Provides the Identity element.
void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const
DER Encodes an elliptic curve point.
int Jacobi(const Integer &aIn, const Integer &bIn)
bool Equal(const Point &P, const Point &Q) const
Compare two elements for equality.
void DEREncode(BufferedTransformation &bt) const
Encodes in DER format.
void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const
Encodes an elliptic curve point.
std::vector< ProjectivePoint >::iterator it
const Integer & GetModulus() const
Retrieves the modulus.
Restricts the instantiation of a class to one static object without locks.
Elliptical Curve Point over GF(p), where p is prime.
bool GetBit(size_t i) const
Provides the i-th bit of the Integer.
size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
Integer & Reduce(Integer &a, const Integer &b) const
TODO.
bool IsOdd() const
Determines if the Integer is odd parity.
virtual const Element & Multiply(const Element &a, const Element &b) const =0
Multiplies elements in the group.
virtual const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
bool ValidateParameters(RandomNumberGenerator &rng, unsigned int level=3) const
const Integer & Subtract(const Integer &a, const Integer &b) const
Subtracts elements in the ring.
Classes for Elliptic Curves over prime fields.
bool InversionIsFast() const
Determine if inversion is fast.
Elliptic Curve over GF(p), where p is prime.
#define NAMESPACE_BEGIN(x)
const Integer & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
size_type size() const
Provides the count of elements in the SecBlock.
Element GeneralCascadeMultiplication(const AbstractGroup< Element > &group, Iterator begin, Iterator end)
bool VerifyPoint(const Point &P) const
Verifies points on elliptic curve.
const Integer & Square(const Integer &a) const
Square an element in the ring.
unsigned int EncodedPointSize(bool compressed=false) const
Determines encoded point size.
ProjectiveDoubling(const ModularArithmetic &m_mr, const Integer &m_a, const Integer &m_b, const ECPPoint &Q)
Ring of congruence classes modulo n.
Interface for random number generators.
size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
void DEREncode(BufferedTransformation &bt) const
Encode the fields fieldID and curve of the sequence ECParameters.
void SimultaneousMultiply(Point *results, const Point &base, const Integer *exponents, unsigned int exponentsCount) const
Multiplies a base to multiple exponents in a group.
if(a.IndicesBefore(b, len, lenIndices))
bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level)
Verifies a prime number.
const Integer & Add(const Integer &a, const Integer &b) const
Adds elements in the ring.
void ParallelInvert(const AbstractRing< T > &ring, Iterator begin, Iterator end)
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
void BERDecodeElement(BufferedTransformation &in, Element &a) const
Decodes element in DER format.
virtual Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
Copy input to a memory buffer.
size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
ASN Strings.
virtual Integer ConvertOut(const Integer &a) const
Reduces an element in the congruence class.
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
const ModularArithmetic & mr
bool IsPositive() const
Determines if the Integer is positive.
ZIterator operator+(int i)
bool IsNegative() const
Determines if the Integer is negative.
void swap(Integer &a)
Swaps this Integer with another Integer.
const Point & Add(const Point &P, const Point &Q) const
Adds elements in the group.
const Point & Double(const Point &P) const
Doubles an element in the group.
virtual const Element & MultiplicativeInverse(const Element &a) const =0
Calculate the multiplicative inverse of an element in the group.
Multiple precision integer with arithmetic operations.
clonable_ptr< Field > m_fieldPtr
const Point & Inverse(const Point &P) const
Inverts the element in the group.
const Integer & Double(const Integer &a) const
Doubles an element in the ring.
Point ScalarMultiply(const Point &P, const Integer &k) const
Performs a scalar multiplication.
const Integer & Inverse(const Integer &a) const
Inverts the element in the ring.
String-based implementation of Store interface.
#define CRYPTOPP_ASSERT(exp)
bool IsZero() const
Determines if the Integer is 0.
void BERDecodeError()
Raises a BERDecodeErr.
const Integer & Divide(const Integer &a, const Integer &b) const
Divides elements in the ring.
Classes and functions for working with ANS.1 objects.
Integer FieldSize() const
#define ANONYMOUS_NAMESPACE_BEGIN
Implementation of BufferedTransformation's attachment interface.
Classes and functions for number theoretic operations.
const Integer & Half(const Integer &a) const
Divides an element by 2.
Integer ModularSquareRoot(const Integer &a, const Integer &p)
#define pass(a, b, c, mul, X)
PlatformStyle::TableColorType type
Performs modular arithmetic in Montgomery representation for increased speed.
uint8_t const size_t const size
#define CRYPTOPP_UNUSED(x)
void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED)
Decode from big-endian byte array.
ZIterator(std::vector< ProjectivePoint >::iterator it)
Multiple precision integer with arithmetic operations.
void DEREncodeElement(BufferedTransformation &out, const Element &a) const
Encodes element in DER format.
void Square(word *R, word *T, const word *A, size_t N)
ProjectivePoint(const Integer &x, const Integer &y, const Integer &z)
Class file for performing modular arithmetic.
int operator-(ZIterator it2)
const Field & GetField() const
virtual bool IsMontgomeryRepresentation() const
Retrieves the representation.
const Integer & Identity() const
Provides the Identity element.
bool Equal(const Integer &a, const Integer &b) const
Compare two elements for equality.
unsigned int MaxElementByteLength() const
Provides the maximum byte size of an element in the ring.
virtual Element CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
Point CascadeScalarMultiply(const Point &P, const Integer &k1, const Point &Q, const Integer &k2) const
TODO.
Point BERDecodePoint(BufferedTransformation &bt) const
BER Decodes an elliptic curve point.
ZIterator & operator+=(int i)
lword TotalPutLength()
Provides the number of bytes written to the Sink.
bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const
Decodes an elliptic curve point.
the value is positive or 0
Point Multiply(const Integer &k, const Point &P) const
bool NotNegative() const
Determines if the Integer is non-negative.