Crypto++  5.6.5
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 ARC4 base class
20 //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
21 //! \since Crypto++ 1.0
22 class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
23 {
24 public:
25  ~ARC4_Base();
26 
27  CRYPTOPP_STATIC_CONSTEXPR char* const StaticAlgorithmName() {return "ARC4";}
28 
29  void GenerateBlock(byte *output, size_t size);
30  void DiscardBytes(size_t n);
31 
32  void ProcessData(byte *outString, const byte *inString, size_t length);
33 
34  bool IsRandomAccess() const {return false;}
35  bool IsSelfInverting() const {return true;}
36  bool IsForwardTransformation() const {return true;}
37 
40 
41 protected:
42  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
43  virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
44 
46  byte m_x, m_y;
47 };
48 
49 //! \class ARC4
50 //! \brief Alleged RC4
51 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
52 //! \since Crypto++ 1.0
54 
55 //! \class MARC4_Base
56 //! \brief MARC4 base class
57 //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
58 //! \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest
59 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
60 {
61 public:
62  CRYPTOPP_STATIC_CONSTEXPR char* const StaticAlgorithmName() {return "MARC4";}
63 
66 
67 protected:
68  unsigned int GetDefaultDiscardBytes() const {return 256;}
69 };
70 
71 //! \class MARC4
72 //! \brief Modified Alleged RC4
73 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
74 //! \since Crypto++ 1.0
76 
77 }
78 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
79 namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
80 #else
81 using namespace Weak1; // import Weak1 into CryptoPP with warning
82 #ifdef __GNUC__
83 #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."
84 #else
85 #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.")
86 #endif
87 #endif
88 
89 NAMESPACE_END
90 
91 #endif
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: arc4.h:34
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:326
MARC4 base class.
Definition: arc4.h:59
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:339
Classes for automatic resource management.
Interface for random number generators.
Definition: cryptlib.h:1197
Classes and functions for secure memory allocations.
Alleged RC4.
Definition: arc4.h:53
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1110
ARC4 base class.
Definition: arc4.h:22
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: arc4.h:36
SymmetricCipher Decryption
implements the SymmetricCipher interface
Definition: seckey.h:423
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:163
Modified Alleged RC4.
Definition: arc4.h:75
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:418
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: arc4.h:35
Crypto++ library namespace.
SymmetricCipher Encryption
implements the SymmetricCipher interface
Definition: seckey.h:421
Namespace containing weak and wounded algorithms.
Definition: arc4.cpp:14
Interface for retrieving values given their names.
Definition: cryptlib.h:278