Crypto++  6.0
Free C++ class library of cryptographic schemes
arc4.h
Go to the documentation of this file.
1 // arc4.h - originally 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 /// \brief ARC4 base class
19 /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
20 /// \since Crypto++ 1.0
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  CRYPTOPP_STATIC_CONSTEXPR 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 /// \brief Alleged RC4
49 /// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>
50 /// \since Crypto++ 1.0
52 
53 /// \brief MARC4 base class
54 /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
55 /// \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest
56 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
57 {
58 public:
59  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARC4";}
60 
63 
64 protected:
65  unsigned int GetDefaultDiscardBytes() const {return 256;}
66 };
67 
68 /// \brief Modified Alleged RC4
69 /// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>
70 /// \since Crypto++ 1.0
72 
73 }
74 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
75 namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
76 #else
77 using namespace Weak1; // import Weak1 into CryptoPP with warning
78 #ifdef __GNUC__
79 #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."
80 #else
81 #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.")
82 #endif
83 #endif
84 
85 NAMESPACE_END
86 
87 #endif
MARC4 base class.
Definition: arc4.h:56
Abstract base classes that provide a uniform interface to this library.
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1327
Classes and functions for secure memory allocations.
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: arc4.h:34
Alleged RC4.
Definition: arc4.h:51
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1236
ARC4 base class.
Definition: arc4.h:21
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:187
Modified Alleged RC4.
Definition: arc4.h:71
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:434
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: arc4.h:35
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: arc4.h:33
Crypto++ library namespace.
Namespace containing weak and wounded algorithms.
Definition: arc4.cpp:14
Interface for retrieving values given their names.
Definition: cryptlib.h:291