arc4.h

00001 #ifndef CRYPTOPP_ARC4_H
00002 #define CRYPTOPP_ARC4_H
00003 
00004 #include "strciphr.h"
00005 
00006 NAMESPACE_BEGIN(CryptoPP)
00007 
00008 namespace Weak1 {
00009 
00010 //! _
00011 class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, public RandomNumberGenerator, public SymmetricCipher, public SymmetricCipherDocumentation
00012 {
00013 public:
00014         ~ARC4_Base();
00015 
00016         static const char *StaticAlgorithmName() {return "ARC4";}
00017 
00018         void GenerateBlock(byte *output, size_t size);
00019         void DiscardBytes(size_t n);
00020 
00021     void ProcessData(byte *outString, const byte *inString, size_t length);
00022         
00023         bool IsRandomAccess() const {return false;}
00024         bool IsSelfInverting() const {return true;}
00025         bool IsForwardTransformation() const {return true;}
00026 
00027         typedef SymmetricCipherFinal<ARC4_Base> Encryption;
00028         typedef SymmetricCipherFinal<ARC4_Base> Decryption;
00029 
00030 protected:
00031         void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
00032         virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
00033 
00034     FixedSizeSecBlock<byte, 256> m_state;
00035     byte m_x, m_y;
00036 };
00037 
00038 //! <a href="http://www.weidai.com/scan-mirror/cs.html#RC4">Alleged RC4</a>
00039 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<ARC4_Base>, ARC4)
00040 
00041 //! _
00042 class CRYPTOPP_NO_VTABLE MARC4_Base : public ARC4_Base
00043 {
00044 public:
00045         static const char *StaticAlgorithmName() {return "MARC4";}
00046 
00047         typedef SymmetricCipherFinal<MARC4_Base> Encryption;
00048         typedef SymmetricCipherFinal<MARC4_Base> Decryption;
00049 
00050 protected:
00051         unsigned int GetDefaultDiscardBytes() const {return 256;}
00052 };
00053 
00054 //! Modified ARC4: it discards the first 256 bytes of keystream which may be weaker than the rest
00055 DOCUMENTED_TYPEDEF(SymmetricCipherFinal<MARC4_Base>, MARC4)
00056 
00057 }
00058 #if CRYPTOPP_ENABLE_NAMESPACE_WEAK >= 1
00059 namespace Weak {using namespace Weak1;}         // import Weak1 into CryptoPP::Weak
00060 #else
00061 using namespace Weak1;  // import Weak1 into CryptoPP with warning
00062 #ifdef __GNUC__
00063 #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."
00064 #else
00065 #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.")
00066 #endif
00067 #endif
00068 
00069 NAMESPACE_END
00070 
00071 #endif

Generated on Fri Jun 1 11:11:19 2007 for Crypto++ by  doxygen 1.5.2