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.

73 lines
1.9 KiB

  1. #ifndef CRYPTOPP_RC2_H
  2. #define CRYPTOPP_RC2_H
  3. /** \file
  4. */
  5. #include "seckey.h"
  6. #include "secblock.h"
  7. #include "algparam.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
  11. {
  12. CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024)
  13. CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024)
  14. static const char *StaticAlgorithmName() {return "RC2";}
  15. };
  16. /// <a href="http://www.weidai.com/scan-mirror/cs.html#RC2">RC2</a>
  17. class RC2 : public RC2_Info, public BlockCipherDocumentation
  18. {
  19. class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
  20. {
  21. public:
  22. void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
  23. unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word16>();}
  24. protected:
  25. FixedSizeSecBlock<word16, 64> K; // expanded key table
  26. };
  27. class CRYPTOPP_NO_VTABLE Enc : public Base
  28. {
  29. public:
  30. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  31. };
  32. class CRYPTOPP_NO_VTABLE Dec : public Base
  33. {
  34. public:
  35. void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
  36. };
  37. public:
  38. class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
  39. {
  40. public:
  41. Encryption() {}
  42. Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
  43. {SetKey(key, keyLen);}
  44. Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
  45. {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
  46. };
  47. class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
  48. {
  49. public:
  50. Decryption() {}
  51. Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
  52. {SetKey(key, keyLen);}
  53. Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
  54. {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
  55. };
  56. };
  57. typedef RC2::Encryption RC2Encryption;
  58. typedef RC2::Decryption RC2Decryption;
  59. NAMESPACE_END
  60. #endif