Crypto++  5.6.3
Free C++ class library of cryptographic schemes
gf256.h
1 #ifndef CRYPTOPP_GF256_H
2 #define CRYPTOPP_GF256_H
3 
4 #include "cryptlib.h"
5 #include "misc.h"
6 
7 NAMESPACE_BEGIN(CryptoPP)
8 
9 //! GF(256) with polynomial basis
10 class GF256
11 {
12 public:
13  typedef byte Element;
14  typedef int RandomizationParameter;
15 
16  GF256(byte modulus) : m_modulus(modulus) {}
17 
18  Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
19  {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();}
20 
21  bool Equal(Element a, Element b) const
22  {return a==b;}
23 
24  Element Zero() const
25  {return 0;}
26 
27  Element Add(Element a, Element b) const
28  {return a^b;}
29 
30  Element& Accumulate(Element &a, Element b) const
31  {return a^=b;}
32 
33  Element Inverse(Element a) const
34  {return a;}
35 
36  Element Subtract(Element a, Element b) const
37  {return a^b;}
38 
39  Element& Reduce(Element &a, Element b) const
40  {return a^=b;}
41 
42  Element Double(Element a) const
43  {CRYPTOPP_UNUSED(a); return 0;}
44 
45  Element One() const
46  {return 1;}
47 
48  Element Multiply(Element a, Element b) const;
49 
50  Element Square(Element a) const
51  {return Multiply(a, a);}
52 
53  bool IsUnit(Element a) const
54  {return a != 0;}
55 
56  Element MultiplicativeInverse(Element a) const;
57 
58  Element Divide(Element a, Element b) const
59  {return Multiply(a, MultiplicativeInverse(b));}
60 
61 private:
62  word m_modulus;
63 };
64 
65 NAMESPACE_END
66 
67 #endif
Utility functions for the Crypto++ library.
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:1186
GF(256) with polynomial basis.
Definition: gf256.h:10
virtual byte GenerateByte()
Generate new random byte and return it.
Definition: cryptlib.cpp:294
Crypto++ library namespace.