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.

71 lines
2.3 KiB

  1. #ifndef CRYPTOPP_ARC4_H
  2. #define CRYPTOPP_ARC4_H
  3. #include "strciphr.h"
  4. NAMESPACE_BEGIN(CryptoPP)
  5. namespace Weak1 {
  6. //! _
  7. class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
  8. {
  9. public:
  10. ~ARC4_Base();
  11. static const char *StaticAlgorithmName() {return "ARC4";}
  12. void GenerateBlock(byte *output, size_t size);
  13. void DiscardBytes(size_t n);
  14. void ProcessData(byte *outString, const byte *inString, size_t length);
  15. bool IsRandomAccess() const {return false;}
  16. bool IsSelfInverting() const {return true;}
  17. bool IsForwardTransformation() const {return true;}
  18. typedef SymmetricCipherFinal<ARC4_Base> Encryption;
  19. typedef SymmetricCipherFinal<ARC4_Base> Decryption;
  20. protected:
  21. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
  22. virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
  23. FixedSizeSecBlock<byte, 256> m_state;
  24. byte m_x, m_y;
  25. };
  26. //! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
  27. DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4)
  28. //! _
  29. class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
  30. {
  31. public:
  32. static const char *StaticAlgorithmName() {return "MARC4";}
  33. typedef SymmetricCipherFinal<MARC4_Base> Encryption;
  34. typedef SymmetricCipherFinal<MARC4_Base> Decryption;
  35. protected:
  36. unsigned int GetDefaultDiscardBytes() const {return 256;}
  37. };
  38. //! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest
  39. DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4)
  40. }
  41. #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
  42. namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
  43. #else
  44. using namespace Weak1; // import Weak1 into CryptoPP with warning
  45. #ifdef __GNUC__
  46. #warning "You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning."
  47. #else
  48. #pragma message("You may be using a weak algorithm that has been retained for backwards compatibility. Please '#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1' before including this .h file and prepend the class name with 'Weak::' to remove this warning.")
  49. #endif
  50. #endif
  51. NAMESPACE_END
  52. #endif