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.

93 lines
2.4 KiB

  1. // cast.h - written and placed in the public domain by Wei Dai
  2. //! \file cast.h
  3. //! \brief Classes for the CAST-128 and CAST-256 block ciphers
  4. #ifndef CRYPTOPP_CAST_H
  5. #define CRYPTOPP_CAST_H
  6. #include "seckey.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. class CAST
  10. {
  11. protected:
  12. static const word32 S[8][256];
  13. };
  14. //! algorithm info
  15. struct CAST128_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 5, 16>
  16. {
  17. static const char *StaticAlgorithmName() {return "CAST-128";}
  18. };
  19. /// <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-128">CAST-128</a>
  20. class CAST128 : public CAST128_Info, public BlockCipherDocumentation
  21. {
  22. class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
  23. {
  24. public:
  25. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  26. protected:
  27. bool reduced;
  28. FixedSizeSecBlock<word32, 32> K;
  29. };
  30. class CRYPTOPP_NO_VTABLE Enc : public Base
  31. {
  32. public:
  33. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  34. };
  35. class CRYPTOPP_NO_VTABLE Dec : public Base
  36. {
  37. public:
  38. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  39. };
  40. public:
  41. typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
  42. typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
  43. };
  44. //! algorithm info
  45. struct CAST256_Info : public FixedBlockSize<16>, public VariableKeyLength<16, 16, 32>
  46. {
  47. static const char *StaticAlgorithmName() {return "CAST-256";}
  48. };
  49. //! <a href="http://www.weidai.com/scan-mirror/cs.html#CAST-256">CAST-256</a>
  50. class CAST256 : public CAST256_Info, public BlockCipherDocumentation
  51. {
  52. class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
  53. {
  54. public:
  55. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  56. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  57. protected:
  58. static const word32 t_m[8][24];
  59. static const unsigned int t_r[8][24];
  60. static void Omega(int i, word32 kappa[8]);
  61. FixedSizeSecBlock<word32, 8*12> K;
  62. };
  63. public:
  64. typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
  65. typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
  66. };
  67. typedef CAST128::Encryption CAST128Encryption;
  68. typedef CAST128::Decryption CAST128Decryption;
  69. typedef CAST256::Encryption CAST256Encryption;
  70. typedef CAST256::Decryption CAST256Decryption;
  71. NAMESPACE_END
  72. #endif