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