6#ifndef CRYPTOPP_MODARITH_H 
    7#define CRYPTOPP_MODARITH_H 
   17#if CRYPTOPP_MSC_VERSION 
   19# pragma warning(disable: 4231 4275) 
   47    typedef int RandomizationParameter;
 
   55        : m_modulus(modulus), m_result(static_cast<
word>(0), modulus.reg.size()) {}
 
 
   67            m_modulus = ma.m_modulus;
 
   68            m_result = 
Integer(
static_cast<word>(0), m_modulus.reg.size());
 
 
  104        {m_modulus = newModulus; m_result.reg.
resize(m_modulus.reg.size());}
 
 
  116        {
return a%m_modulus;}
 
 
  191        {
return m_result1 = a*b%m_modulus;}
 
 
  198        {
return m_result1 = a.Squared()%m_modulus;}
 
 
  211        {
return m_result1 = a.InverseMod(m_modulus);}
 
 
  244        {
return (m_modulus-1).BitCount();}
 
 
  249        {
return (m_modulus-1).ByteCount();}
 
 
  261        CRYPTOPP_UNUSED(ignore_for_now);
 
 
  270        {
return m_modulus == rhs.m_modulus;}
 
 
  272    static const RandomizationParameter DefaultRandomizationParameter;
 
  281    mutable Integer m_result, m_result1;
 
 
  314        {
return (a<<(
WORD_BITS*m_modulus.reg.size()))%m_modulus;}
 
 
 
  340#if CRYPTOPP_MSC_VERSION 
Classes for performing mathematics over different fields.
 
Abstract Euclidean domain.
 
virtual const Element & Add(const Element &a, const Element &b) const =0
Adds elements in the group.
 
virtual const Element & Multiply(const Element &a, const Element &b) const =0
Multiplies elements in the group.
 
virtual void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the Ring.
 
virtual const Element & MultiplicativeInverse(const Element &a) const =0
Calculate the multiplicative inverse of an element in the group.
 
virtual Element CascadeExponentiate(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
 
Multiple precision integer with arithmetic operations.
 
static const Integer & Zero()
Integer representing 0.
 
static Integer Power2(size_t e)
Exponentiates to a power of 2.
 
bool IsUnit() const
Determine if 1 or -1.
 
static Integer Gcd(const Integer &a, const Integer &n)
Calculate greatest common divisor.
 
static const Integer & One()
Integer representing 1.
 
Ring of congruence classes modulo n.
 
bool IsUnit(const Integer &a) const
Determines whether an element is a unit in the ring.
 
const Integer & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
 
bool operator==(const ModularArithmetic &rhs) const
Compares two ModularArithmetic for equality.
 
Integer & Reduce(Integer &a, const Integer &b) const
TODO.
 
ModularArithmetic(const Integer &modulus=Integer::One())
Construct a ModularArithmetic.
 
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
 
const Integer & Half(const Integer &a) const
Divides an element by 2.
 
const Integer & Square(const Integer &a) const
Square an element in the ring.
 
void SetModulus(const Integer &newModulus)
Sets the modulus.
 
const Integer & Double(const Integer &a) const
Doubles an element in the ring.
 
const Integer & Inverse(const Integer &a) const
Inverts the element in the ring.
 
unsigned int MaxElementBitLength() const
Provides the maximum bit size of an element in the ring.
 
void BERDecodeElement(BufferedTransformation &in, Element &a) const
Decodes element in DER format.
 
unsigned int MaxElementByteLength() const
Provides the maximum byte size of an element in the ring.
 
virtual ModularArithmetic * Clone() const
Clone a ModularArithmetic.
 
Element RandomElement(RandomNumberGenerator &rng, const RandomizationParameter &ignore_for_now=0) const
Provides a random element in the ring.
 
void DEREncodeElement(BufferedTransformation &out, const Element &a) const
Encodes element in DER format.
 
ModularArithmetic & operator=(const ModularArithmetic &ma)
Assign a ModularArithmetic.
 
ModularArithmetic(const ModularArithmetic &ma)
Copy construct a ModularArithmetic.
 
virtual bool IsMontgomeryRepresentation() const
Retrieves the representation.
 
bool Equal(const Integer &a, const Integer &b) const
Compare two elements for equality.
 
const Integer & GetModulus() const
Retrieves the modulus.
 
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
 
const Integer & Identity() const
Provides the Identity element.
 
ModularArithmetic(BufferedTransformation &bt)
Construct a ModularArithmetic.
 
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
 
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
 
virtual Integer ConvertOut(const Integer &a) const
Reduces an element in the congruence class.
 
Integer & Accumulate(Integer &a, const Integer &b) const
TODO.
 
const Integer & Subtract(const Integer &a, const Integer &b) const
Subtracts elements in the ring.
 
const Integer & Divide(const Integer &a, const Integer &b) const
Divides elements in the ring.
 
const Integer & Add(const Integer &a, const Integer &b) const
Adds elements in the ring.
 
virtual Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
 
void DEREncode(BufferedTransformation &bt) const
Encodes in DER format.
 
Performs modular arithmetic in Montgomery representation for increased speed.
 
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
 
Integer ConvertOut(const Integer &a) const
Reduces an element in the congruence class.
 
const Integer & Square(const Integer &a) const
Square an element in the ring.
 
Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
 
bool IsMontgomeryRepresentation() const
Retrieves the representation.
 
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
 
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
 
const Integer & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
 
MontgomeryRepresentation(const Integer &modulus)
Construct a MontgomeryRepresentation.
 
virtual ModularArithmetic * Clone() const
Clone a MontgomeryRepresentation.
 
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
 
Interface for random number generators.
 
void resize(size_type newSize)
Change size and preserve contents.
 
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Instantiate templates in a dynamic library.
 
word64 word
Full word used for multiprecision integer arithmetic.
 
const unsigned int WORD_BITS
Size of a platform word in bits.
 
Abstract base classes that provide a uniform interface to this library.
 
Multiple precision integer with arithmetic operations.
 
Utility functions for the Crypto++ library.
 
Crypto++ library namespace.
 
Classes and functions for secure memory allocations.