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.

61 lines
1.6 KiB

  1. // twofish.h - written and placed in the public domain by Wei Dai
  2. //! \file twofish.h
  3. //! \brief Classes for the Twofish block cipher
  4. #ifndef CRYPTOPP_TWOFISH_H
  5. #define CRYPTOPP_TWOFISH_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. struct Twofish_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>, FixedRounds<16>
  11. {
  12. static const char *StaticAlgorithmName() {return "Twofish";}
  13. };
  14. /// <a href="http://www.weidai.com/scan-mirror/cs.html#Twofish">Twofish</a>
  15. class Twofish : public Twofish_Info, public BlockCipherDocumentation
  16. {
  17. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
  18. {
  19. public:
  20. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  21. protected:
  22. static word32 h0(word32 x, const word32 *key, unsigned int kLen);
  23. static word32 h(word32 x, const word32 *key, unsigned int kLen);
  24. static const byte q[2][256];
  25. static const word32 mds[4][256];
  26. FixedSizeSecBlock<word32, 40> m_k;
  27. FixedSizeSecBlock<word32, 4*256> m_s;
  28. };
  29. class CRYPTOPP_NO_VTABLE Enc : public Base
  30. {
  31. public:
  32. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  33. };
  34. class CRYPTOPP_NO_VTABLE Dec : public Base
  35. {
  36. public:
  37. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  38. };
  39. public:
  40. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  41. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  42. };
  43. typedef Twofish::Encryption TwofishEncryption;
  44. typedef Twofish::Decryption TwofishDecryption;
  45. NAMESPACE_END
  46. #endif