1#ifndef CRYPTOPP_ARC4_H 2#define CRYPTOPP_ARC4_H 3 4#include "strciphr.h" 5 6NAMESPACE_BEGIN(CryptoPP) 7 8namespace Weak1 { 9 10//! _ 11class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation 12{ 13public: 14 ~ARC4_Base(); 15 16 static const char *StaticAlgorithmName() {return "ARC4";} 17 18 void GenerateBlock(byte *output, size_t size); 19 void DiscardBytes(size_t n); 20 21 void ProcessData(byte *outString, const byte *inString, size_t length); 22 23 bool IsRandomAccess() const {return false;} 24 bool IsSelfInverting() const {return true;} 25 bool IsForwardTransformation() const {return true;} 26 27 typedef SymmetricCipherFinal<ARC4_Base> Encryption; 28 typedef SymmetricCipherFinal<ARC4_Base> Decryption; 29 30protected: 31 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 32 virtual unsigned int GetDefaultDiscardBytes() const {return 0;} 33 34 FixedSizeSecBlock<byte, 256> m_state; 35 byte m_x, m_y; 36}; 37 38//! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a> 39DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4) 40 41//! _ 42class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base 43{ 44public: 45 static const char *StaticAlgorithmName() {return "MARC4";} 46 47 typedef SymmetricCipherFinal<MARC4_Base> Encryption; 48 typedef SymmetricCipherFinal<MARC4_Base> Decryption; 49 50protected: 51 unsigned int GetDefaultDiscardBytes() const {return 256;} 52}; 53 54//! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest 55DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4) 56 57} 58#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1 59namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak 60#else 61using namespace Weak1; // import Weak1 into CryptoPP with warning 62#ifdef __GNUC__ 63#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." 64#else 65#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.") 66#endif 67#endif 68 69NAMESPACE_END 70 71#endif 72