6 #ifndef CRYPTOPP_ALGEBRA_H 7 #define CRYPTOPP_ALGEBRA_H 38 virtual bool Equal(
const Element &
a,
const Element &
b)
const =0;
42 virtual const Element& Identity()
const =0;
48 virtual const Element&
Add(
const Element &a,
const Element &b)
const =0;
53 virtual const Element& Inverse(
const Element &a)
const =0;
62 virtual const Element& Double(
const Element &a)
const;
68 virtual const Element&
Subtract(
const Element &a,
const Element &b)
const;
74 virtual Element& Accumulate(Element &a,
const Element &b)
const;
80 virtual Element& Reduce(Element &a,
const Element &b)
const;
86 virtual Element ScalarMultiply(
const Element &a,
const Integer &
e)
const;
94 virtual Element CascadeScalarMultiply(
const Element &
x,
const Integer &e1,
const Element &y,
const Integer &e2)
const;
106 virtual void SimultaneousMultiply(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
139 virtual bool IsUnit(
const Element &
a)
const =0;
143 virtual const Element& MultiplicativeIdentity()
const =0;
149 virtual const Element&
Multiply(
const Element &a,
const Element &
b)
const =0;
153 virtual const Element& MultiplicativeInverse(
const Element &a)
const =0;
158 virtual const Element&
Square(
const Element &a)
const;
164 virtual const Element&
Divide(
const Element &a,
const Element &b)
const;
170 virtual Element Exponentiate(
const Element &a,
const Integer &
e)
const;
178 virtual Element CascadeExponentiate(
const Element &
x,
const Integer &e1,
const Element &y,
const Integer &e2)
const;
190 virtual void SimultaneousExponentiate(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const;
204 bool Equal(
const Element &a,
const Element &b)
const 205 {
return GetRing().Equal(a, b);}
208 {
return GetRing().MultiplicativeIdentity();}
210 const Element&
Add(
const Element &a,
const Element &b)
const 211 {
return GetRing().Multiply(a, b);}
214 {
return a = GetRing().Multiply(a, b);}
216 const Element&
Inverse(
const Element &a)
const 217 {
return GetRing().MultiplicativeInverse(a);}
219 const Element&
Subtract(
const Element &a,
const Element &b)
const 220 {
return GetRing().Divide(a, b);}
222 Element&
Reduce(Element &a,
const Element &b)
const 223 {
return a = GetRing().Divide(a, b);}
225 const Element&
Double(
const Element &a)
const 226 {
return GetRing().Square(a);}
229 {
return GetRing().Exponentiate(a, e);}
232 {
return GetRing().CascadeExponentiate(x, e1, y, e2);}
235 {GetRing().SimultaneousExponentiate(results, base, exponents, exponentsCount);}
248 template <
class T,
class E = Integer>
254 bool operator<(const BaseAndExponent<T, E> &rhs)
const {
return exponent < rhs.exponent;}
260 template <
class Element,
class Iterator>
262 template <
class Element,
class Iterator>
286 virtual void DivisionAlgorithm(Element &r, Element &q,
const Element &
a,
const Element &
d)
const =0;
292 virtual const Element& Mod(
const Element &
a,
const Element &
b)
const =0;
298 virtual const Element& Gcd(
const Element &
a,
const Element &
b)
const;
322 bool Equal(
const Element &
a,
const Element &
b)
const 326 {
return Element::Zero();}
328 const Element&
Add(
const Element &
a,
const Element &
b)
const 329 {
return result = a+
b;}
335 {
return result = -
a;}
337 const Element&
Subtract(
const Element &
a,
const Element &
b)
const 338 {
return result = a-
b;}
340 Element&
Reduce(Element &
a,
const Element &
b)
const 347 {
return Element::One();}
349 const Element&
Multiply(
const Element &
a,
const Element &
b)
const 350 {
return result = a*
b;}
361 const Element&
Divide(
const Element &
a,
const Element &
b)
const 362 {
return result = a/
b;}
364 const Element&
Mod(
const Element &
a,
const Element &
b)
const 365 {
return result = a%
b;}
393 : m_domain(domain), m_modulus(modulus) {}
401 bool Equal(
const Element &
a,
const Element &
b)
const 402 {
return m_domain.Equal(m_domain.Mod(m_domain.Subtract(a, b), m_modulus), m_domain.Identity());}
405 {
return m_domain.Identity();}
407 const Element&
Add(
const Element &
a,
const Element &
b)
const 408 {
return m_domain.Add(a, b);}
411 {
return m_domain.Accumulate(a, b);}
414 {
return m_domain.Inverse(a);}
416 const Element&
Subtract(
const Element &
a,
const Element &
b)
const 417 {
return m_domain.Subtract(a, b);}
419 Element&
Reduce(Element &
a,
const Element &
b)
const 420 {
return m_domain.Reduce(a, b);}
423 {
return m_domain.Double(a);}
426 {
return m_domain.IsUnit(m_domain.Gcd(a, m_modulus));}
429 {
return m_domain.MultiplicativeIdentity();}
431 const Element&
Multiply(
const Element &
a,
const Element &
b)
const 432 {
return m_domain.Mod(m_domain.Multiply(a, b), m_modulus);}
435 {
return m_domain.Mod(m_domain.Square(a), m_modulus);}
437 const Element& MultiplicativeInverse(
const Element &
a)
const;
449 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
PolynomialMod2 Squared() const
const Element & Inverse(const Element &a) const
Inverts the element in the group.
AbstractRing & operator=(const AbstractRing &source)
Assign an AbstractRing.
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
const Element & Inverse(const Element &a) const
Inverts the element in the group.
Utility functions for the Crypto++ library.
PolynomialMod2 Doubled() const
is always zero since we're working modulo 2
const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
virtual bool InversionIsFast() const
Determine if inversion is fast.
const Element & Square(const Element &a) const
Square an element in the group.
Element & Reduce(Element &a, const Element &b) const
Reduces an element in the congruence class.
#define NAMESPACE_BEGIN(x)
void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const
Performs the division algorithm on two elements in the ring.
Element & Reduce(Element &a, const Element &b) const
Reduces an element in the congruence class.
Abstract Euclidean domain.
BaseAndExponent(const T &base, const E &exponent)
virtual const AbstractGroup< T > & MultiplicativeGroup() const
Retrieves the multiplicative group.
AbstractRing()
Construct an AbstractRing.
Library configuration file.
const Element & Mod(const Element &a, const Element &b) const
Performs a modular reduction in the ring.
const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
int Add(word *C, const word *A, const word *B, size_t N)
const AbstractRing< T > & GetRing() const
Element & Accumulate(Element &a, const Element &b) const
TODO.
Element GeneralCascadeMultiplication(const AbstractGroup< Element > &group, Iterator begin, Iterator end)
const Element & Identity() const
Provides the Identity element.
const Element & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
const Element & Identity() const
Provides the Identity element.
Element & Accumulate(Element &a, const Element &b) const
TODO.
PolynomialMod2 MultiplicativeInverse() const
return inverse if *this is a unit, otherwise return 0
const Element & Add(const Element &a, const Element &b) const
Adds elements in the group.
bool IsUnit() const
only 1 is a unit
const EuclideanDomain & GetDomain() const
QuotientRing(const EuclideanDomain &domain, const Element &modulus)
Element & Accumulate(Element &a, const Element &b) const
TODO.
bool IsUnit(const Element &a) const
Determines whether an element is a unit in the group.
const Element & Multiply(const Element &a, const Element &b) const
Multiplies elements in the group.
Multiple precision integer with arithmetic operations.
bool operator==(const QuotientRing< T > &rhs) const
void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB)
Element & Reduce(Element &a, const Element &b) const
Reduces an element in the congruence class.
const Element & GetModulus() const
const Element & Identity() const
Provides the Identity element.
Element GeneralCascadeExponentiation(const AbstractRing< Element > &ring, Iterator begin, Iterator end)
bool operator==(const EuclideanDomainOf< T > &rhs) const
const Element & MultiplicativeInverse(const Element &a) const
Calculate the multiplicative inverse of an element in the group.
Element ScalarMultiply(const Element &a, const Integer &e) const
Performs a scalar multiplication.
AbstractRing(const AbstractRing &source)
Copy construct an AbstractRing.
const Element & Inverse(const Element &a) const
Inverts the element in the group.
#define CRYPTOPP_NO_VTABLE
const Element & Add(const Element &a, const Element &b) const
Adds elements in the group.
MultiplicativeGroupT m_mg
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
const Element & Multiply(const Element &a, const Element &b) const
Multiplies elements in the group.
const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
#define CRYPTOPP_UNUSED(x)
void Multiply(word *R, word *T, const word *A, const word *B, size_t N)
const Element & Double(const Element &a) const
Doubles an element in the group.
Multiple precision integer with arithmetic operations.
void Square(word *R, word *T, const word *A, size_t N)
Element CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
const Element & Add(const Element &a, const Element &b) const
Adds elements in the group.
int Subtract(word *C, const word *A, const word *B, size_t N)
void SimultaneousMultiply(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Multiplies a base to multiple exponents in a group.
const Element & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
const Element & Square(const Element &a) const
Square an element in the group.
const Element & Divide(const Element &a, const Element &b) const
Divides elements in the group.
const AbstractRing< T > * m_pRing
const Element & Double(const Element &a) const
Doubles an element in the group.
const Element & Double(const Element &a) const
Doubles an element in the group.
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
bool IsUnit(const Element &a) const
Determines whether an element is a unit in the group.