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