Counter Strike : Global Offensive Source Code
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.

91 lines
2.3 KiB

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