Crypto++  5.6.3
Free C++ class library of cryptographic schemes
arc4.h
Go to the documentation of this file.
1 // arc4.h - written and placed in the public domain by Wei Dai
2 
3 //! \file arc4.h
4 //! \brief Classes for ARC4 cipher
5 
6 #ifndef CRYPTOPP_ARC4_H
7 #define CRYPTOPP_ARC4_H
8 
9 #include "cryptlib.h"
10 #include "strciphr.h"
11 #include "secblock.h"
12 #include "smartptr.h"
13 
14 NAMESPACE_BEGIN(CryptoPP)
15 
16 namespace Weak1 {
17 
18 //! \class ARC4_Base
19 //! \brief Class specific methods used to operate the cipher.
20 //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
21 class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
22 {
23 public:
24  ~ARC4_Base();
25 
26  static const char *StaticAlgorithmName() {return "ARC4";}
27 
28  void GenerateBlock(byte *output, size_t size);
29  void DiscardBytes(size_t n);
30 
31  void ProcessData(byte *outString, const byte *inString, size_t length);
32 
33  bool IsRandomAccess() const {return false;}
34  bool IsSelfInverting() const {return true;}
35  bool IsForwardTransformation() const {return true;}
36 
39 
40 protected:
41  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
42  virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
43 
45  byte m_x, m_y;
46 };
47 
48 //! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
50 
51 //! \class MARC4_Base
52 //! \brief Class specific methods used to operate the cipher.
53 //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
54 //! \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest
55 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
56 {
57 public:
58  static const char *StaticAlgorithmName() {return "MARC4";}
59 
62 
63 protected:
64  unsigned int GetDefaultDiscardBytes() const {return 256;}
65 };
66 
68 
69 }
70 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
71 namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
72 #else
73 using namespace Weak1; // import Weak1 into CryptoPP with warning
74 #ifdef __GNUC__
75 #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."
76 #else
77 #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.")
78 #endif
79 #endif
80 
81 NAMESPACE_END
82 
83 #endif
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: arc4.h:33
virtual void ProcessData(byte *outString, const byte *inString, size_t length)=0
Encrypt or decrypt an array of bytes.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Definition: cryptlib.cpp:330
Class specific methods used to operate the cipher.
Definition: arc4.h:55
Abstract base classes that provide a uniform interface to this library.
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Definition: cryptlib.cpp:343
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1186
Classes and functions for secure memory allocations.
Alleged RC4
Definition: arc4.h:49
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1099
Class specific methods used to operate the cipher.
Definition: arc4.h:21
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: arc4.h:35
SymmetricCipher Decryption
implements the SymmetricCipher interface
Definition: seckey.h:417
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:157
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:412
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: arc4.h:34
Crypto++ library namespace.
SymmetricCipher Encryption
implements the SymmetricCipher interface
Definition: seckey.h:415
Namespace containing weak and wounded algorithms.
Definition: arc4.cpp:14
Interface for retrieving values given their names.
Definition: cryptlib.h:277