Crypto++ 8.7
Free C++ class library of cryptographic schemes
|
Performs modular arithmetic in Montgomery representation for increased speed. More...
#include <modarith.h>
Public Member Functions | |
MontgomeryRepresentation (const Integer &modulus) | |
Construct a MontgomeryRepresentation. More... | |
virtual ModularArithmetic * | Clone () const |
Clone a MontgomeryRepresentation. More... | |
bool | IsMontgomeryRepresentation () const |
Retrieves the representation. More... | |
Integer | ConvertIn (const Integer &a) const |
Reduces an element in the congruence class. More... | |
Integer | ConvertOut (const Integer &a) const |
Reduces an element in the congruence class. More... | |
const Integer & | MultiplicativeIdentity () const |
Retrieves the multiplicative identity. More... | |
const Integer & | Multiply (const Integer &a, const Integer &b) const |
Multiplies elements in the ring. More... | |
const Integer & | Square (const Integer &a) const |
Square an element in the ring. More... | |
const Integer & | MultiplicativeInverse (const Integer &a) const |
Calculate the multiplicative inverse of an element in the ring. More... | |
Integer | CascadeExponentiate (const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const |
TODO. More... | |
void | SimultaneousExponentiate (Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const |
Exponentiates a base to multiple exponents in the ring. More... | |
Public Member Functions inherited from ModularArithmetic | |
ModularArithmetic (const Integer &modulus=Integer::One()) | |
Construct a ModularArithmetic. More... | |
ModularArithmetic (const ModularArithmetic &ma) | |
Copy construct a ModularArithmetic. More... | |
ModularArithmetic & | operator= (const ModularArithmetic &ma) |
Assign a ModularArithmetic. More... | |
ModularArithmetic (BufferedTransformation &bt) | |
Construct a ModularArithmetic. More... | |
virtual ModularArithmetic * | Clone () const |
Clone a ModularArithmetic. More... | |
void | DEREncode (BufferedTransformation &bt) const |
Encodes in DER format. More... | |
void | DEREncodeElement (BufferedTransformation &out, const Element &a) const |
Encodes element in DER format. More... | |
void | BERDecodeElement (BufferedTransformation &in, Element &a) const |
Decodes element in DER format. More... | |
const Integer & | GetModulus () const |
Retrieves the modulus. More... | |
void | SetModulus (const Integer &newModulus) |
Sets the modulus. More... | |
virtual bool | IsMontgomeryRepresentation () const |
Retrieves the representation. More... | |
virtual Integer | ConvertIn (const Integer &a) const |
Reduces an element in the congruence class. More... | |
virtual Integer | ConvertOut (const Integer &a) const |
Reduces an element in the congruence class. More... | |
const Integer & | Half (const Integer &a) const |
Divides an element by 2. More... | |
bool | Equal (const Integer &a, const Integer &b) const |
Compare two elements for equality. More... | |
const Integer & | Identity () const |
Provides the Identity element. More... | |
const Integer & | Add (const Integer &a, const Integer &b) const |
Adds elements in the ring. More... | |
Integer & | Accumulate (Integer &a, const Integer &b) const |
TODO. More... | |
const Integer & | Inverse (const Integer &a) const |
Inverts the element in the ring. More... | |
const Integer & | Subtract (const Integer &a, const Integer &b) const |
Subtracts elements in the ring. More... | |
Integer & | Reduce (Integer &a, const Integer &b) const |
TODO. More... | |
const Integer & | Double (const Integer &a) const |
Doubles an element in the ring. More... | |
const Integer & | MultiplicativeIdentity () const |
Retrieves the multiplicative identity. More... | |
const Integer & | Multiply (const Integer &a, const Integer &b) const |
Multiplies elements in the ring. More... | |
const Integer & | Square (const Integer &a) const |
Square an element in the ring. More... | |
bool | IsUnit (const Integer &a) const |
Determines whether an element is a unit in the ring. More... | |
const Integer & | MultiplicativeInverse (const Integer &a) const |
Calculate the multiplicative inverse of an element in the ring. More... | |
const Integer & | Divide (const Integer &a, const Integer &b) const |
Divides elements in the ring. More... | |
Integer | CascadeExponentiate (const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const |
TODO. More... | |
void | SimultaneousExponentiate (Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const |
Exponentiates a base to multiple exponents in the ring. More... | |
unsigned int | MaxElementBitLength () const |
Provides the maximum bit size of an element in the ring. More... | |
unsigned int | MaxElementByteLength () const |
Provides the maximum byte size of an element in the ring. More... | |
Element | RandomElement (RandomNumberGenerator &rng, const RandomizationParameter &ignore_for_now=0) const |
Provides a random element in the ring. More... | |
bool | operator== (const ModularArithmetic &rhs) const |
Compares two ModularArithmetic for equality. More... | |
Public Member Functions inherited from AbstractRing< Integer > | |
AbstractRing () | |
Construct an AbstractRing. More... | |
AbstractRing (const AbstractRing &source) | |
Copy construct an AbstractRing. More... | |
AbstractRing & | operator= (const AbstractRing &source) |
Assign an AbstractRing. More... | |
virtual bool | IsUnit (const Element &a) const=0 |
Determines whether an element is a unit in the group. More... | |
virtual const Element & | MultiplicativeIdentity () const=0 |
Retrieves the multiplicative identity. More... | |
virtual const Element & | Multiply (const Element &a, const Element &b) const=0 |
Multiplies elements in the group. More... | |
virtual const Element & | MultiplicativeInverse (const Element &a) const=0 |
Calculate the multiplicative inverse of an element in the group. More... | |
virtual const Element & | Square (const Element &a) const |
Square an element in the group. More... | |
virtual const Element & | Divide (const Element &a, const Element &b) const |
Divides elements in the group. More... | |
virtual Element | Exponentiate (const Element &a, const Integer &e) const |
Raises a base to an exponent in the group. More... | |
virtual Element | CascadeExponentiate (const Element &x, const Integer &e1, const Element &y, const Integer &e2) const |
TODO. More... | |
virtual void | SimultaneousExponentiate (Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const |
Exponentiates a base to multiple exponents in the Ring. More... | |
virtual const AbstractGroup< Integer > & | MultiplicativeGroup () const |
Retrieves the multiplicative group. More... | |
Public Member Functions inherited from AbstractGroup< Integer > | |
virtual bool | Equal (const Element &a, const Element &b) const=0 |
Compare two elements for equality. More... | |
virtual const Element & | Identity () const=0 |
Provides the Identity element. More... | |
virtual const Element & | Add (const Element &a, const Element &b) const=0 |
Adds elements in the group. More... | |
virtual const Element & | Inverse (const Element &a) const=0 |
Inverts the element in the group. More... | |
virtual bool | InversionIsFast () const |
Determine if inversion is fast. More... | |
virtual const Element & | Double (const Element &a) const |
Doubles an element in the group. More... | |
virtual const Element & | Subtract (const Element &a, const Element &b) const |
Subtracts elements in the group. More... | |
virtual Element & | Accumulate (Element &a, const Element &b) const |
TODO. More... | |
virtual Element & | Reduce (Element &a, const Element &b) const |
Reduces an element in the congruence class. More... | |
virtual Element | ScalarMultiply (const Element &a, const Integer &e) const |
Performs a scalar multiplication. More... | |
virtual Element | CascadeScalarMultiply (const Element &x, const Integer &e1, const Element &y, const Integer &e2) const |
TODO. More... | |
virtual void | SimultaneousMultiply (Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const |
Multiplies a base to multiple exponents in a group. More... | |
Additional Inherited Members | |
Public Types inherited from ModularArithmetic | |
typedef int | RandomizationParameter |
typedef Integer | Element |
Public Types inherited from AbstractRing< Integer > | |
typedef Integer | Element |
Public Types inherited from AbstractGroup< Integer > | |
typedef Integer | Element |
Static Public Attributes inherited from ModularArithmetic | |
static const RandomizationParameter | DefaultRandomizationParameter |
Performs modular arithmetic in Montgomery representation for increased speed.
The Montgomery representation represents each congruence class [a]
as a*r%n
, where r
is a convenient power of 2.
const Element&
returned by member functions are references to internal data members. Since each object may have only one such data member for holding results, the following code will produce incorrect results:
abcd = group.Add(group.Add(a,b), group.Add(c,d));
But this should be fine:
abcd = group.Add(a, group.Add(b, group.Add(c,d));
Definition at line 295 of file modarith.h.
|
inlinevirtual |
Definition at line 298 of file modarith.h.
MontgomeryRepresentation::MontgomeryRepresentation | ( | const Integer & | modulus | ) |
Construct a MontgomeryRepresentation.
modulus | congruence class modulus |
|
inlinevirtual |
Clone a MontgomeryRepresentation.
Clone effectively copy constructs a new MontgomeryRepresentation. The caller is responsible for deleting the pointer returned from this method.
Reimplemented from ModularArithmetic.
Definition at line 309 of file modarith.h.
|
inlinevirtual |
Retrieves the representation.
Reimplemented from ModularArithmetic.
Definition at line 311 of file modarith.h.
Reduces an element in the congruence class.
a | element to convert |
ConvertIn is useful for derived classes, like MontgomeryRepresentation, which must convert between representations.
Reimplemented from ModularArithmetic.
Definition at line 313 of file modarith.h.
Reduces an element in the congruence class.
a | element to convert |
ConvertOut is useful for derived classes, like MontgomeryRepresentation, which must convert between representations.
Reimplemented from ModularArithmetic.
|
inlinevirtual |
Retrieves the multiplicative identity.
the base class implementations returns 1.
Reimplemented from ModularArithmetic.
Definition at line 318 of file modarith.h.
|
virtual |
Multiplies elements in the ring.
a | the multiplicand |
b | the multiplier |
Multiply returns a*b%n
.
Reimplemented from ModularArithmetic.
Square an element in the ring.
a | the element |
Square returns a*a%n
. The element a
must provide a Square member function.
Reimplemented from ModularArithmetic.
Calculate the multiplicative inverse of an element in the ring.
a | the element |
MultiplicativeInverse returns a-1%n
. The element a
must provide a InverseMod member function.
Reimplemented from ModularArithmetic.
|
inlinevirtual |
TODO.
x | first element |
e1 | first exponent |
y | second element |
e2 | second exponent |
Reimplemented from ModularArithmetic.
Definition at line 327 of file modarith.h.
|
inlinevirtual |
Exponentiates a base to multiple exponents in the ring.
results | an array of Elements |
base | the base to raise to the exponents |
exponents | an array of exponents |
exponentsCount | the number of exponents in the array |
SimultaneousExponentiate() raises the base to each exponent in the exponents array and stores the result at the respective position in the results array.
SimultaneousExponentiate() must be implemented in a derived class.
COUNTOF(results) == exponentsCount
COUNTOF(exponents) == exponentsCount
Reimplemented from ModularArithmetic.
Definition at line 330 of file modarith.h.