Crypto++ 8.9 Free C++ class library of cryptographic schemes

gf256.h
Go to the documentation of this file.
1 // gf256.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file gf256.h
4 /// \brief Classes and functions for schemes over GF(256)
5
6 #ifndef CRYPTOPP_GF256_H
7 #define CRYPTOPP_GF256_H
8
9 #include "cryptlib.h"
10 #include "misc.h"
11
12 NAMESPACE_BEGIN(CryptoPP)
13
14 /// \brief GF(256) with polynomial basis
15 class GF256
16 {
17 public:
18 typedef byte Element;
19 typedef int RandomizationParameter;
20
21 GF256(byte modulus) : m_modulus(modulus) {}
22
23 Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
24 {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();}
25
26 bool Equal(Element a, Element b) const
27 {return a==b;}
28
29 Element Zero() const
30 {return 0;}
31
32 Element Add(Element a, Element b) const
33 {return a^b;}
34
35 Element& Accumulate(Element &a, Element b) const
36 {return a^=b;}
37
38 Element Inverse(Element a) const
39 {return a;}
40
41 Element Subtract(Element a, Element b) const
42 {return a^b;}
43
44 Element& Reduce(Element &a, Element b) const
45 {return a^=b;}
46
47 Element Double(Element a) const
48 {CRYPTOPP_UNUSED(a); return 0;}
49
50 Element One() const
51 {return 1;}
52
53 Element Multiply(Element a, Element b) const;
54
55 Element Square(Element a) const
56 {return Multiply(a, a);}
57
58 bool IsUnit(Element a) const
59 {return a != 0;}
60
61 Element MultiplicativeInverse(Element a) const;
62
63 Element Divide(Element a, Element b) const
64 {return Multiply(a, MultiplicativeInverse(b));}
65
66 private:
67 word m_modulus;
68 };
69
70 NAMESPACE_END
71
72 #endif
GF256
GF(256) with polynomial basis.
Definition: gf256.h:16
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1440
RandomNumberGenerator::GenerateByte
virtual byte GenerateByte()
Generate new random byte and return it.
Square
Square block cipher.
Definition: square.h:25
word
word64 word
Full word used for multiprecision integer arithmetic.
Definition: config_int.h:192
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
misc.h
Utility functions for the Crypto++ library.
CryptoPP
Crypto++ library namespace.