Crypto++ 7.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 /// \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
15 NAMESPACE_BEGIN(CryptoPP)
16
17 namespace 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
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 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
41 protected:
42 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
43 virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
44
45 FixedSizeSecBlock<byte, 256> m_state;
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
52 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4)
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
58 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
59 {
60 public:
61 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARC4";}
62
63 typedef SymmetricCipherFinal<MARC4_Base> Encryption;
64 typedef SymmetricCipherFinal<MARC4_Base> Decryption;
65
66 protected:
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
73 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4)
74
75 }
76 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
77 namespace Weak {using namespace Weak1;} // import Weak1 into CryptoPP::Weak
78 #else
79 using 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
87 NAMESPACE_END
88
89 #endif
Weak::MARC4_Base
MARC4 base class.
Definition: arc4.h:58
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
smartptr.h
Classes for automatic resource management.
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1349
secblock.h
Classes and functions for secure memory allocations.
Weak::ARC4_Base::IsSelfInverting
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: arc4.h:35
Weak::ARC4
Alleged RC4.
Definition: arc4.h:52
SymmetricCipher
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1256
Weak::ARC4_Base
ARC4 base class.
Definition: arc4.h:22
FixedSizeSecBlock< byte, 256 >
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165
Weak::MARC4
Modified Alleged RC4.
Definition: arc4.h:73
strciphr.h
Classes for implementing stream ciphers.
SymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:413
Weak::ARC4_Base::IsForwardTransformation
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: arc4.h:36
Weak::ARC4_Base::IsRandomAccess
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: arc4.h:34
CryptoPP
Crypto++ library namespace.
SymmetricCipherFinal< ARC4_Base >
Weak
Namespace containing weak and wounded algorithms.
Definition: arc4.cpp:14
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:293