Crypto++
gf256.h
1 #ifndef CRYPTOPP_GF256_H
2 #define CRYPTOPP_GF256_H
3 
4 #include "cryptlib.h"
5 
6 NAMESPACE_BEGIN(CryptoPP)
7 
8 //! GF(256) with polynomial basis
9 class GF256
10 {
11 public:
12  typedef byte Element;
13  typedef int RandomizationParameter;
14 
15  GF256(byte modulus) : m_modulus(modulus) {}
16 
17  Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
18  {return rng.GenerateByte();}
19 
20  bool Equal(Element a, Element b) const
21  {return a==b;}
22 
23  Element Zero() 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 One() 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  word m_modulus;
62 };
63 
64 NAMESPACE_END
65 
66 #endif
virtual byte GenerateByte()
generate new random byte and return it
Square
Definition: square.h:19
interface for random number generators
Definition: cryptlib.h:668
GF(256) with polynomial basis.
Definition: gf256.h:9