Coverage Report

Created: 2024-11-21 07:03

/src/cryptopp/gf256.h
Line
Count
Source (jump to first uncovered line)
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
716
  GF256(byte modulus) : m_modulus(modulus) {}
22
23
  Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
24
0
    {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();}
25
26
  bool Equal(Element a, Element b) const
27
0
    {return a==b;}
28
29
  Element Zero() const
30
0
    {return 0;}
31
32
  Element Add(Element a, Element b) const
33
0
    {return a^b;}
34
35
  Element& Accumulate(Element &a, Element b) const
36
0
    {return a^=b;}
37
38
  Element Inverse(Element a) const
39
0
    {return a;}
40
41
  Element Subtract(Element a, Element b) const
42
0
    {return a^b;}
43
44
  Element& Reduce(Element &a, Element b) const
45
0
    {return a^=b;}
46
47
  Element Double(Element a) const
48
0
    {CRYPTOPP_UNUSED(a); return 0;}
49
50
  Element One() const
51
0
    {return 1;}
52
53
  Element Multiply(Element a, Element b) const;
54
55
  Element Square(Element a) const
56
0
    {return Multiply(a, a);}
57
58
  bool IsUnit(Element a) const
59
0
    {return a != 0;}
60
61
  Element MultiplicativeInverse(Element a) const;
62
63
  Element Divide(Element a, Element b) const
64
0
    {return Multiply(a, MultiplicativeInverse(b));}
65
66
private:
67
  word m_modulus;
68
};
69
70
NAMESPACE_END
71
72
#endif