3way.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // 3way.h - originally written and placed in the public domain by Wei Dai
  2. /// \file 3way.h
  3. /// \brief Classes for the 3-Way block cipher
  4. #ifndef CRYPTOPP_THREEWAY_H
  5. #define CRYPTOPP_THREEWAY_H
  6. #include "config.h"
  7. #include "seckey.h"
  8. #include "secblock.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. /// \brief ThreeWay block cipher information
  11. struct ThreeWay_Info : public FixedBlockSize<12>, public FixedKeyLength<12>, public VariableRounds<11>
  12. {
  13. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "3-Way";}
  14. };
  15. /// \brief ThreeWay block cipher
  16. /// \sa <a href="http://www.cryptopp.com/wiki/3-Way">3-Way</a>
  17. class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation
  18. {
  19. /// \brief Class specific implementation and overrides used to operate the cipher.
  20. /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  21. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<ThreeWay_Info>
  22. {
  23. public:
  24. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
  25. protected:
  26. unsigned int m_rounds;
  27. FixedSizeSecBlock<word32, 3> m_k;
  28. };
  29. /// \brief Class specific methods used to operate the cipher in the forward direction.
  30. /// \details Implementations and overrides in \p Enc apply to \p ENCRYPTION.
  31. class CRYPTOPP_NO_VTABLE Enc : public Base
  32. {
  33. public:
  34. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  35. };
  36. /// \brief Class specific methods used to operate the cipher in the reverse direction.
  37. /// \details Implementations and overrides in \p Dec apply to \p DECRYPTION.
  38. class CRYPTOPP_NO_VTABLE Dec : public Base
  39. {
  40. public:
  41. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  42. };
  43. public:
  44. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  45. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  46. };
  47. typedef ThreeWay::Encryption ThreeWayEncryption;
  48. typedef ThreeWay::Decryption ThreeWayDecryption;
  49. NAMESPACE_END
  50. #endif