6 #ifndef CRYPTOPP_MODARITH_H 7 #define CRYPTOPP_MODARITH_H 84 {m_modulus = newModulus;
m_result.reg.resize(m_modulus.reg.size());}
108 const Integer& Half(
const Integer &a)
const;
115 bool Equal(
const Integer &a,
const Integer &
b)
const 127 const Integer&
Add(
const Integer &a,
const Integer &
b)
const;
133 Integer& Accumulate(Integer &a,
const Integer &b)
const;
138 const Integer& Inverse(
const Integer &a)
const;
144 const Integer&
Subtract(
const Integer &a,
const Integer &b)
const;
150 Integer& Reduce(Integer &a,
const Integer &b)
const;
156 const Integer&
Double(
const Integer &a)
const 170 const Integer&
Multiply(
const Integer &a,
const Integer &b)
const 171 {
return m_result1 = a*b%m_modulus;}
177 const Integer&
Square(
const Integer &a)
const 178 {
return m_result1 = a.
Squared()%m_modulus;}
198 const Integer&
Divide(
const Integer &a,
const Integer &b)
const 199 {
return Multiply(a, MultiplicativeInverse(b));}
207 Integer CascadeExponentiate(
const Integer &
x,
const Integer &e1,
const Integer &y,
const Integer &e2)
const;
219 void SimultaneousExponentiate(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
224 {
return (m_modulus-1).BitCount();}
229 {
return (m_modulus-1).ByteCount();}
297 const Integer&
Multiply(
const Integer &a,
const Integer &
b)
const;
299 const Integer&
Square(
const Integer &a)
const;
bool IsUnit(const Integer &a) const
Determines whether an element is a unit in the ring.
const Integer & GetModulus() const
Retrieves the modulus.
Utility functions for the Crypto++ library.
virtual ModularArithmetic * Clone() const
Clone a ModularArithmetic.
static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n)
greatest common divisor
#define NAMESPACE_BEGIN(x)
#define CRYPTOPP_DLL_TEMPLATE_CLASS
const Integer & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
Abstract base classes that provide a uniform interface to this library.
const Integer & MultiplicativeInverse(const Integer &a) const
Calculate the multiplicative inverse of an element in the ring.
Abstract Euclidean domain.
const Integer & Square(const Integer &a) const
Square an element in the ring.
Ring of congruence classes modulo n.
Interface for random number generators.
Element RandomElement(RandomNumberGenerator &rng, const RandomizationParameter &ignore_for_now=0) const
Provides a random element in the ring.
int Add(word *C, const word *A, const word *B, size_t N)
virtual void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the Ring.
Classes for performing mathematics over different fields.
static const Integer &CRYPTOPP_API One()
Integer representing 1.
virtual ModularArithmetic * Clone() const
Clone a MontgomeryRepresentation.
Classes and functions for secure memory allocations.
bool IsUnit() const
is 1 or -1
virtual Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
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 Integer & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
IntegerSecBlock m_workspace
const unsigned int WORD_BITS
Integer Squared() const
Multiply this integer by itself.
static Integer CRYPTOPP_API Power2(size_t e)
Exponentiates to a power of 2.
unsigned int MaxElementBitLength() const
Provides the maximum bit size of an element in the ring.
virtual ~MontgomeryRepresentation()
Multiple precision integer with arithmetic operations.
const Integer & Double(const Integer &a) const
Doubles an element in the ring.
virtual Element CascadeExponentiate(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
int RandomizationParameter
ModularArithmetic(const Integer &modulus=Integer::One())
Construct a ModularArithmetic.
const Integer & Divide(const Integer &a, const Integer &b) const
Divides elements in the ring.
static const RandomizationParameter DefaultRandomizationParameter
void SetModulus(const Integer &newModulus)
Sets the modulus.
Performs modular arithmetic in Montgomery representation for increased speed.
uint8_t const size_t const size
#define CRYPTOPP_UNUSED(x)
void Multiply(word *R, word *T, const word *A, const word *B, size_t N)
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
bool operator==(const ModularArithmetic &rhs) const
Compares two ModularArithmetic for equality.
Multiple precision integer with arithmetic operations.
static const Integer &CRYPTOPP_API Zero()
Integer representing 0.
int Subtract(word *C, const word *A, const word *B, size_t N)
bool IsMontgomeryRepresentation() const
Retrieves the representation.
ModularArithmetic(const ModularArithmetic &ma)
Copy construct a ModularArithmetic.
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.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
virtual ~ModularArithmetic()
Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.