gf256.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // gf256.h - originally written and placed in the public domain by Wei Dai
  2. /// \file gf256.h
  3. /// \brief Classes and functions for schemes over GF(256)
  4. #ifndef CRYPTOPP_GF256_H
  5. #define CRYPTOPP_GF256_H
  6. #include "cryptlib.h"
  7. #include "misc.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. /// \brief GF(256) with polynomial basis
  10. class GF256
  11. {
  12. public:
  13. typedef byte Element;
  14. typedef int RandomizationParameter;
  15. GF256(byte modulus) : m_modulus(modulus) {}
  16. Element RandomElement(RandomNumberGenerator &rng, int ignored = 0) const
  17. {CRYPTOPP_UNUSED(ignored); return rng.GenerateByte();}
  18. bool Equal(Element a, Element b) const
  19. {return a==b;}
  20. Element Zero() const
  21. {return 0;}
  22. Element Add(Element a, Element b) const
  23. {return a^b;}
  24. Element& Accumulate(Element &a, Element b) const
  25. {return a^=b;}
  26. Element Inverse(Element a) const
  27. {return a;}
  28. Element Subtract(Element a, Element b) const
  29. {return a^b;}
  30. Element& Reduce(Element &a, Element b) const
  31. {return a^=b;}
  32. Element Double(Element a) const
  33. {CRYPTOPP_UNUSED(a); return 0;}
  34. Element One() const
  35. {return 1;}
  36. Element Multiply(Element a, Element b) const;
  37. Element Square(Element a) const
  38. {return Multiply(a, a);}
  39. bool IsUnit(Element a) const
  40. {return a != 0;}
  41. Element MultiplicativeInverse(Element a) const;
  42. Element Divide(Element a, Element b) const
  43. {return Multiply(a, MultiplicativeInverse(b));}
  44. private:
  45. word m_modulus;
  46. };
  47. NAMESPACE_END
  48. #endif