gost.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // gost.h - originally written and placed in the public domain by Wei Dai
  2. /// \file gost.h
  3. /// \brief Classes for the GIST block cipher
  4. #ifndef CRYPTOPP_GOST_H
  5. #define CRYPTOPP_GOST_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. /// \brief GOST block cipher information
  10. /// \since Crypto++ 2.1
  11. struct GOST_Info : public FixedBlockSize<8>, public FixedKeyLength<32>
  12. {
  13. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "GOST";}
  14. };
  15. /// \brief GOST block cipher
  16. /// \sa <a href="http://www.cryptopp.com/wiki/GOST">GOST</a>
  17. /// \since Crypto++ 2.1
  18. class GOST : public GOST_Info, public BlockCipherDocumentation
  19. {
  20. /// \brief GOST block cipher default operation
  21. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
  22. {
  23. public:
  24. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  25. protected:
  26. static void PrecalculateSTable();
  27. static const byte sBox[8][16];
  28. static volatile bool sTableCalculated;
  29. static word32 sTable[4][256];
  30. FixedSizeSecBlock<word32, 8> m_key;
  31. };
  32. /// \brief GOST block cipher encryption operation
  33. class CRYPTOPP_NO_VTABLE Enc : public Base
  34. {
  35. public:
  36. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  37. };
  38. /// \brief GOST block cipher decryption operation
  39. class CRYPTOPP_NO_VTABLE Dec : public Base
  40. {
  41. public:
  42. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  43. };
  44. public:
  45. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  46. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  47. };
  48. typedef GOST::Encryption GOSTEncryption;
  49. typedef GOST::Decryption GOSTDecryption;
  50. NAMESPACE_END
  51. #endif