gf2_32.h 1.5 KB

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