Crypto++
arc4.h
1 #ifndef CRYPTOPP_ARC4_H
2 #define CRYPTOPP_ARC4_H
3 
4 #include "strciphr.h"
5 
6 NAMESPACE_BEGIN(CryptoPP)
7 
8 namespace Weak1 {
9 
10 //! _
11 class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
12 {
13 public:
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 
29 
30 protected:
31  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
32  virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
33 
35  byte m_x, m_y;
36 };
37 
38 //! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
40 
41 //! _
42 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
43 {
44 public:
45  static const char *StaticAlgorithmName() {return "MARC4";}
46 
49 
50 protected:
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
56 
57 }
58 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
59 namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
60 #else
61 using 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 
69 NAMESPACE_END
70 
71 #endif