Crypto++  5.6.3
Free C++ class library of cryptographic schemes
gf2_32.h
1 #ifndef CRYPTOPP_GF2_32_H
2 #define CRYPTOPP_GF2_32_H
3 
4 #include "cryptlib.h"
5 #include "secblock.h"
6 #include "misc.h"
7 
8 NAMESPACE_BEGIN(CryptoPP)
9 
10 //! GF(2^32) with polynomial basis
11 class GF2_32
12 {
13 public:
14  typedef word32 Element;
15  typedef int RandomizationParameter;
16 
17  GF2_32(word32 modulus=0x0000008D) : m_modulus(modulus) {}
18 
19  Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
20  {CRYPTOPP_UNUSED(ignored); return rng.GenerateWord32();}
21 
22  bool Equal(Element a, Element b) const
23  {return a==b;}
24 
25  Element Identity() const
26  {return 0;}
27 
28  Element Add(Element a, Element b) const
29  {return a^b;}
30 
31  Element& Accumulate(Element &a, Element b) const
32  {return a^=b;}
33 
34  Element Inverse(Element a) const
35  {return a;}
36 
37  Element Subtract(Element a, Element b) const
38  {return a^b;}
39 
40  Element& Reduce(Element &a, Element b) const
41  {return a^=b;}
42 
43  Element Double(Element a) const
44  {CRYPTOPP_UNUSED(a); return 0;}
45 
46  Element MultiplicativeIdentity() const
47  {return 1;}
48 
49  Element Multiply(Element a, Element b) const;
50 
51  Element Square(Element a) const
52  {return Multiply(a, a);}
53 
54  bool IsUnit(Element a) const
55  {return a != 0;}
56 
57  Element MultiplicativeInverse(Element a) const;
58 
59  Element Divide(Element a, Element b) const
60  {return Multiply(a, MultiplicativeInverse(b));}
61 
62 private:
63  word32 m_modulus;
64 };
65 
66 NAMESPACE_END
67 
68 #endif
GF(2^32) with polynomial basis.
Definition: gf2_32.h:11
Utility functions for the Crypto++ library.
virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL)
Generate a random 32 bit word in the range min to max, inclusive.
Definition: cryptlib.cpp:301
Abstract base classes that provide a uniform interface to this library.
Square block cipher.
Definition: square.h:24
Interface for random number generators.
Definition: cryptlib.h:1176
Classes and functions for secure memory allocations.
Crypto++ library namespace.