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.

83 lines
2.9 KiB

  1. // arc4.h - written and placed in the public domain by Wei Dai
  2. //! \file arc4.h
  3. //! \brief Classes for ARC4 cipher
  4. #ifndef CRYPTOPP_ARC4_H
  5. #define CRYPTOPP_ARC4_H
  6. #include "cryptlib.h"
  7. #include "strciphr.h"
  8. #include "secblock.h"
  9. #include "smartptr.h"
  10. NAMESPACE_BEGIN(CryptoPP)
  11. namespace Weak1 {
  12. //! \class ARC4_Base
  13. //! \brief Class specific methods used to operate the cipher.
  14. //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  15. class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
  16. {
  17. public:
  18. ~ARC4_Base();
  19. static const char *StaticAlgorithmName() {return "ARC4";}
  20. void GenerateBlock(byte *output, size_t size);
  21. void DiscardBytes(size_t n);
  22. void ProcessData(byte *outString, const byte *inString, size_t length);
  23. bool IsRandomAccess() const {return false;}
  24. bool IsSelfInverting() const {return true;}
  25. bool IsForwardTransformation() const {return true;}
  26. typedef SymmetricCipherFinal<ARC4_Base> Encryption;
  27. typedef SymmetricCipherFinal<ARC4_Base> Decryption;
  28. protected:
  29. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
  30. virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
  31. FixedSizeSecBlock<byte, 256> m_state;
  32. byte m_x, m_y;
  33. };
  34. //! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
  35. DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4)
  36. //! \class MARC4_Base
  37. //! \brief Class specific methods used to operate the cipher.
  38. //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
  39. //! \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest
  40. class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
  41. {
  42. public:
  43. static const char *StaticAlgorithmName() {return "MARC4";}
  44. typedef SymmetricCipherFinal<MARC4_Base> Encryption;
  45. typedef SymmetricCipherFinal<MARC4_Base> Decryption;
  46. protected:
  47. unsigned int GetDefaultDiscardBytes() const {return 256;}
  48. };
  49. DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4)
  50. }
  51. #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
  52. namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
  53. #else
  54. using namespace Weak1; // import Weak1 into CryptoPP with warning
  55. #ifdef __GNUC__
  56. #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."
  57. #else
  58. #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.")
  59. #endif
  60. #endif
  61. NAMESPACE_END
  62. #endif