Crypto++ 8.7
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/// \since Crypto++ 3.1
6
7#ifndef CRYPTOPP_ARC4_H
8#define CRYPTOPP_ARC4_H
9
10#include "cryptlib.h"
11#include "strciphr.h"
12#include "secblock.h"
13#include "smartptr.h"
14
15NAMESPACE_BEGIN(CryptoPP)
16
17namespace Weak1 {
18
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++ 3.1
22class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
23{
24public:
25 ~ARC4_Base();
26
27 CRYPTOPP_STATIC_CONSTEXPR const char* 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
38 typedef SymmetricCipherFinal<ARC4_Base> Encryption;
39 typedef SymmetricCipherFinal<ARC4_Base> Decryption;
40
41protected:
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/// \brief Alleged RC4
50/// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>
51/// \since Crypto++ 3.1
53
54/// \brief MARC4 base class
55/// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
56/// \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest
57/// \since Crypto++ 3.1
58class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
59{
60public:
61 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARC4";}
62
65
66protected:
67 unsigned int GetDefaultDiscardBytes() const {return 256;}
68};
69
70/// \brief Modified Alleged RC4
71/// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>
72/// \since Crypto++ 3.1
74
75}
76#if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
77namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
78#else
79using namespace Weak1; // import Weak1 into CryptoPP with warning
80#ifdef __GNUC__
81#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."
82#else
83#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.")
84#endif
85#endif
86
87NAMESPACE_END
88
89#endif
Interface for retrieving values given their names.
Definition: cryptlib.h:322
Interface for random number generators.
Definition: cryptlib.h:1435
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Definition: cryptlib.h:1291
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:166
ARC4 base class.
Definition: arc4.h:23
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: arc4.h:34
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: arc4.h:35
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: arc4.h:36
Alleged RC4.
Definition: arc4.h:52
MARC4 base class.
Definition: arc4.h:59
Modified Alleged RC4.
Definition: arc4.h:73
Abstract base classes that provide a uniform interface to this library.
Crypto++ library namespace.
Namespace containing weak and wounded algorithms.
Definition: arc4.cpp:14
Classes and functions for secure memory allocations.
Classes for automatic resource management.
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition: seckey.h:414