6 #ifndef CRYPTOPP_MODARITH_H 7 #define CRYPTOPP_MODARITH_H 31 typedef int RandomizationParameter;
48 const Integer& GetModulus()
const {
return m_modulus;}
49 void SetModulus(
const Integer &newModulus)
50 {m_modulus = newModulus; m_result.reg.
resize(m_modulus.reg.size());}
52 virtual bool IsMontgomeryRepresentation()
const {
return false;}
54 virtual Integer ConvertIn(
const Integer &a)
const 57 virtual Integer ConvertOut(
const Integer &a)
const 60 const Integer& Half(
const Integer &a)
const;
62 bool Equal(
const Integer &a,
const Integer &b)
const 65 const Integer& Identity()
const 68 const Integer& Add(
const Integer &a,
const Integer &b)
const;
70 Integer& Accumulate(Integer &a,
const Integer &b)
const;
72 const Integer& Inverse(
const Integer &a)
const;
74 const Integer& Subtract(
const Integer &a,
const Integer &b)
const;
76 Integer& Reduce(Integer &a,
const Integer &b)
const;
78 const Integer& Double(
const Integer &a)
const 81 const Integer& MultiplicativeIdentity()
const 84 const Integer& Multiply(
const Integer &a,
const Integer &b)
const 85 {
return m_result1 = a*b%m_modulus;}
87 const Integer&
Square(
const Integer &a)
const 88 {
return m_result1 = a.
Squared()%m_modulus;}
90 bool IsUnit(
const Integer &a)
const 93 const Integer& MultiplicativeInverse(
const Integer &a)
const 96 const Integer& Divide(
const Integer &a,
const Integer &b)
const 97 {
return Multiply(a, MultiplicativeInverse(b));}
99 Integer CascadeExponentiate(
const Integer &x,
const Integer &e1,
const Integer &y,
const Integer &e2)
const;
101 void SimultaneousExponentiate(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
103 unsigned int MaxElementBitLength()
const 104 {
return (m_modulus-1).BitCount();}
106 unsigned int MaxElementByteLength()
const 107 {
return (m_modulus-1).ByteCount();}
109 Element RandomElement(
RandomNumberGenerator &rng ,
const RandomizationParameter &ignore_for_now = 0 )
const 112 CRYPTOPP_UNUSED(ignore_for_now);
117 {
return m_modulus == rhs.m_modulus;}
119 static const RandomizationParameter DefaultRandomizationParameter ;
121 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 127 mutable Integer m_result, m_result1;
144 bool IsMontgomeryRepresentation()
const {
return true;}
147 {
return (a<<(WORD_BITS*m_modulus.reg.size()))%m_modulus;}
151 const Integer& MultiplicativeIdentity()
const 152 {
return m_result1 =
Integer::Power2(WORD_BITS*m_modulus.reg.size())%m_modulus;}
163 void SimultaneousExponentiate(
Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const 166 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 Utility functions for the Crypto++ library.
static Integer Gcd(const Integer &a, const Integer &n)
greatest common divisor
void resize(size_type newSize)
Change size and preserve contents.
Abstract base classes that provide a uniform interface to this library.
size_type size() const
Provides the count of elements in the SecBlock.
Abstract Euclidean Domain.
Ring of congruence classes modulo n.
Interface for random number generators.
Classes for performing mathematics over different fields.
static const Integer & One()
Integer representing 1.
Classes and functions for secure memory allocations.
bool IsUnit() const
is 1 or -1
static Integer Power2(size_t e)
Exponentiates to a power of 2.
Multiple precision integer with arithmetic operations.
Performs modular arithmetic in Montgomery representation for increased speed.
Integer InverseMod(const Integer &n) const
calculate multiplicative inverse of *this mod n
static const Integer & Zero()
Integer representing 0.
Crypto++ library namespace.