Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:03

0001 // gf256.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file gf256.h

0004 /// \brief Classes and functions for schemes over GF(256)

0005 
0006 #ifndef CRYPTOPP_GF256_H
0007 #define CRYPTOPP_GF256_H
0008 
0009 #include "cryptlib.h"
0010 #include "misc.h"
0011 
0012 NAMESPACE_BEGIN(CryptoPP)
0013 
0014 /// \brief GF(256) with polynomial basis

0015 class GF256
0016 {
0017 public:
0018     typedef byte Element;
0019     typedef int RandomizationParameter;
0020 
0021     GF256(byte modulus) : m_modulus(modulus) {}
0022 
0023     Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
0024         {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();}
0025 
0026     bool Equal(Element a, Element b) const
0027         {return a==b;}
0028 
0029     Element Zero() const
0030         {return 0;}
0031 
0032     Element Add(Element a, Element b) const
0033         {return a^b;}
0034 
0035     Element& Accumulate(Element &a, Element b) const
0036         {return a^=b;}
0037 
0038     Element Inverse(Element a) const
0039         {return a;}
0040 
0041     Element Subtract(Element a, Element b) const
0042         {return a^b;}
0043 
0044     Element& Reduce(Element &a, Element b) const
0045         {return a^=b;}
0046 
0047     Element Double(Element a) const
0048         {CRYPTOPP_UNUSED(a); return 0;}
0049 
0050     Element One() const
0051         {return 1;}
0052 
0053     Element Multiply(Element a, Element b) const;
0054 
0055     Element Square(Element a) const
0056         {return Multiply(a, a);}
0057 
0058     bool IsUnit(Element a) const
0059         {return a != 0;}
0060 
0061     Element MultiplicativeInverse(Element a) const;
0062 
0063     Element Divide(Element a, Element b) const
0064         {return Multiply(a, MultiplicativeInverse(b));}
0065 
0066 private:
0067     word m_modulus;
0068 };
0069 
0070 NAMESPACE_END
0071 
0072 #endif