Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

  1. // 3way.h - 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. //! \class ThreeWay_Info
  11. //! \brief The cipher's key, iv, block size and name information.
  12. struct ThreeWay_Info : public FixedBlockSize<12>, public FixedKeyLength<12>, public VariableRounds<11>
  13. {
  14. static const char *StaticAlgorithmName() {return "3-Way";}
  15. };
  16. // <a href="http://www.weidai.com/scan-mirror/cs.html#3-Way">3-Way</a>
  17. //! \class ThreeWay
  18. //! \brief Provides 3-Way encryption and decryption
  19. class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation
  20. {
  21. //! \class Base
  22. //! \brief Class specific implementation and overrides used to operate the cipher.
  23. //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  24. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<ThreeWay_Info>
  25. {
  26. public:
  27. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
  28. protected:
  29. unsigned int m_rounds;
  30. FixedSizeSecBlock<word32, 3> m_k;
  31. };
  32. //! \class Enc
  33. //! \brief Class specific methods used to operate the cipher in the forward direction.
  34. //! \details Implementations and overrides in \p Enc apply to \p ENCRYPTION.
  35. class CRYPTOPP_NO_VTABLE Enc : public Base
  36. {
  37. public:
  38. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  39. };
  40. //! \class Dec
  41. //! \brief Class specific methods used to operate the cipher in the reverse direction.
  42. //! \details Implementations and overrides in \p Dec apply to \p DECRYPTION.
  43. class CRYPTOPP_NO_VTABLE Dec : public Base
  44. {
  45. public:
  46. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  47. };
  48. public:
  49. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  50. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  51. };
  52. typedef ThreeWay::Encryption ThreeWayEncryption;
  53. typedef ThreeWay::Decryption ThreeWayDecryption;
  54. NAMESPACE_END
  55. #endif