Crypto++ 8.7
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
12NAMESPACE_BEGIN(CryptoPP)
13
14/// \brief GF(256) with polynomial basis
15class GF256
16{
17public:
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
66private:
67 word m_modulus;
68};
69
70NAMESPACE_END
71
72#endif
GF(256) with polynomial basis.
Definition: gf256.h:16
Interface for random number generators.
Definition: cryptlib.h:1435
virtual byte GenerateByte()
Generate new random byte and return it.
Square block cipher.
Definition: square.h:25
word64 word
Full word used for multiprecision integer arithmetic.
Definition: config_int.h:182
Abstract base classes that provide a uniform interface to this library.
Utility functions for the Crypto++ library.
Crypto++ library namespace.