Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:53

0001 // arc4.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file arc4.h

0004 /// \brief Classes for ARC4 cipher

0005 /// \since Crypto++ 3.1

0006 
0007 #ifndef CRYPTOPP_ARC4_H
0008 #define CRYPTOPP_ARC4_H
0009 
0010 #include "cryptlib.h"
0011 #include "strciphr.h"
0012 #include "secblock.h"
0013 #include "smartptr.h"
0014 
0015 NAMESPACE_BEGIN(CryptoPP)
0016 
0017 namespace Weak1 {
0018 
0019 /// \brief ARC4 base class

0020 /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions

0021 /// \since Crypto++ 3.1

0022 class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
0023 {
0024 public:
0025     ~ARC4_Base();
0026 
0027     CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "ARC4";}
0028 
0029     void GenerateBlock(byte *output, size_t size);
0030     void DiscardBytes(size_t n);
0031 
0032     void ProcessData(byte *outString, const byte *inString, size_t length);
0033 
0034     bool IsRandomAccess() const {return false;}
0035     bool IsSelfInverting() const {return true;}
0036     bool IsForwardTransformation() const {return true;}
0037 
0038     typedef SymmetricCipherFinal<ARC4_Base> Encryption;
0039     typedef SymmetricCipherFinal<ARC4_Base> Decryption;
0040 
0041 protected:
0042     void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
0043     virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
0044 
0045     FixedSizeSecBlock<byte, 256> m_state;
0046     byte m_x, m_y;
0047 };
0048 
0049 /// \brief Alleged RC4

0050 /// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>

0051 /// \since Crypto++ 3.1

0052 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4);
0053 
0054 /// \brief MARC4 base class

0055 /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions

0056 /// \details MARC4 discards the first 256 bytes of keystream, which may be weaker than the rest

0057 /// \since Crypto++ 3.1

0058 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
0059 {
0060 public:
0061     CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "MARC4";}
0062 
0063     typedef SymmetricCipherFinal<MARC4_Base> Encryption;
0064     typedef SymmetricCipherFinal<MARC4_Base> Decryption;
0065 
0066 protected:
0067     unsigned int GetDefaultDiscardBytes() const {return 256;}
0068 };
0069 
0070 /// \brief Modified Alleged RC4

0071 /// \sa <a href="http://www.cryptopp.com/wiki/RC4">Alleged RC4</a>

0072 /// \since Crypto++ 3.1

0073 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4);
0074 
0075 }
0076 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
0077 namespace Weak {using namespace Weak1;}     // import Weak1 into CryptoPP::Weak

0078 #else
0079 using namespace Weak1;  // import Weak1 into CryptoPP with warning

0080 #ifdef __GNUC__
0081 #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."
0082 #else
0083 #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.")
0084 #endif
0085 #endif
0086 
0087 NAMESPACE_END
0088 
0089 #endif