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.

86 lines
2.3 KiB

  1. #ifndef CRYPTOPP_SAFER_H
  2. #define CRYPTOPP_SAFER_H
  3. /** \file
  4. */
  5. #include "seckey.h"
  6. #include "secblock.h"
  7. NAMESPACE_BEGIN(CryptoPP)
  8. /// base class, do not use directly
  9. class SAFER
  10. {
  11. public:
  12. class CRYPTOPP_NO_VTABLE Base : public BlockCipher
  13. {
  14. public:
  15. unsigned int OptimalDataAlignment() const {return 1;}
  16. void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs &params);
  17. protected:
  18. virtual bool Strengthened() const =0;
  19. SecByteBlock keySchedule;
  20. static const byte exp_tab[256];
  21. static const byte log_tab[256];
  22. };
  23. class CRYPTOPP_NO_VTABLE Enc : public Base
  24. {
  25. public:
  26. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  27. };
  28. class CRYPTOPP_NO_VTABLE Dec : public Base
  29. {
  30. public:
  31. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  32. };
  33. };
  34. template <class BASE, class INFO, bool STR>
  35. class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
  36. {
  37. protected:
  38. bool Strengthened() const {return STR;}
  39. };
  40. //! _
  41. struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
  42. {
  43. static const char *StaticAlgorithmName() {return "SAFER-K";}
  44. };
  45. /// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
  46. class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
  47. {
  48. public:
  49. typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
  50. typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_K_Info, false> > Decryption;
  51. };
  52. //! _
  53. struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
  54. {
  55. static const char *StaticAlgorithmName() {return "SAFER-SK";}
  56. };
  57. /// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
  58. class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
  59. {
  60. public:
  61. typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
  62. typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
  63. };
  64. typedef SAFER_K::Encryption SAFER_K_Encryption;
  65. typedef SAFER_K::Decryption SAFER_K_Decryption;
  66. typedef SAFER_SK::Encryption SAFER_SK_Encryption;
  67. typedef SAFER_SK::Decryption SAFER_SK_Decryption;
  68. NAMESPACE_END
  69. #endif