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
virtual void ProcessData(byte *outString, const byte *inString, size_t length)=0
encrypt or decrypt an array of bytes of specified length
virtual void DiscardBytes(size_t n)
generate and discard n bytes
interface for random number generators
Definition: cryptlib.h:668
bool IsForwardTransformation() const
returns whether this is an encryption object
Definition: arc4.h:25
Alleged RC4
Definition: arc4.h:39
Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest...
Definition: arc4.h:55
interface for one direction (encryption or decryption) of a stream cipher or cipher mode ...
Definition: cryptlib.h:610
virtual void GenerateBlock(byte *output, size_t size)
generate random array of bytes
SymmetricCipher Decryption
implements the SymmetricCipher interface
Definition: seckey.h:206
support query of variable key length, template parameters are default, min, max, multiple (default mu...
Definition: seckey.h:80
Each class derived from this one defines two types, Encryption and Decryption, both of which implemen...
Definition: seckey.h:201
bool IsSelfInverting() const
returns whether this transformation is self-inverting (e.g. xor with a keystream) ...
Definition: arc4.h:24
SymmetricCipher Encryption
implements the SymmetricCipher interface
Definition: seckey.h:204
Definition: arc4.h:8
Definition: panama.h:24
bool IsRandomAccess() const
returns whether this cipher supports random access
Definition: arc4.h:23
interface for retrieving values given their names
Definition: cryptlib.h:224