23 #ifndef TAO_CRYPT_MODARITH_HPP
24 #define TAO_CRYPT_MODARITH_HPP
27 #include "algebra.hpp"
37 typedef int RandomizationParameter;
41 : modulus(modulus), result((word)0, modulus.reg_.size()) {}
45 modulus(ma.modulus), result((word)0, modulus.reg_.size()) {}
47 const Integer& GetModulus()
const {
return modulus;}
48 void SetModulus(
const Integer &newModulus)
51 result.reg_.resize(modulus.reg_.size());
54 virtual bool IsMontgomeryRepresentation()
const {
return false;}
68 {
return Integer::Zero();}
83 const Integer& MultiplicativeIdentity()
const
84 {
return Integer::One();}
87 {
return result1 = a*b%modulus;}
90 {
return result1 = a.Squared()%modulus;}
92 bool IsUnit(
const Integer &a)
const
93 {
return Integer::Gcd(a, modulus).IsUnit();}
96 {
return result1 = a.InverseMod(modulus);}
99 {
return Multiply(a, MultiplicativeInverse(b));}
104 void SimultaneousExponentiate(
Element *results,
const Element &base,
105 const Integer *exponents,
unsigned int exponentsCount)
const;
107 unsigned int MaxElementBitLength()
const
108 {
return (modulus-1).BitCount();}
110 unsigned int MaxElementByteLength()
const
111 {
return (modulus-1).ByteCount();}
114 static const RandomizationParameter DefaultRandomizationParameter;
118 mutable Integer result, result1;
130 bool IsMontgomeryRepresentation()
const {
return true;}
133 {
return (a<<(WORD_BITS*modulus.reg_.size()))%modulus;}
137 const Integer& MultiplicativeIdentity()
const
138 {
return result1 = Integer::Power2(WORD_BITS*modulus.reg_.size())%modulus;}
148 {
return AbstractRing::CascadeExponentiate(x, e1, y, e2);}
150 void SimultaneousExponentiate(
Element *results,
const Element &base,
151 const Integer *exponents,
unsigned int exponentsCount)
const
152 {AbstractRing::SimultaneousExponentiate(results, base,
153 exponents, exponentsCount);}
165 #endif // TAO_CRYPT_MODARITH_HPP