Botan
1.11.15
|
00001 /* 00002 * RC4 00003 * (C) 1999-2008 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_RC4_H__ 00009 #define BOTAN_RC4_H__ 00010 00011 #include <botan/stream_cipher.h> 00012 #include <botan/types.h> 00013 00014 namespace Botan { 00015 00016 /** 00017 * RC4 stream cipher 00018 */ 00019 class BOTAN_DLL RC4 : public StreamCipher 00020 { 00021 public: 00022 void cipher(const byte in[], byte out[], size_t length); 00023 00024 void clear(); 00025 std::string name() const; 00026 00027 StreamCipher* clone() const { return new RC4(SKIP); } 00028 00029 Key_Length_Specification key_spec() const 00030 { 00031 return Key_Length_Specification(1, 256); 00032 } 00033 00034 static RC4* make(const Spec& spec); 00035 00036 /** 00037 * @param skip skip this many initial bytes in the keystream 00038 */ 00039 RC4(size_t skip = 0); 00040 00041 ~RC4() { clear(); } 00042 private: 00043 void key_schedule(const byte[], size_t); 00044 void generate(); 00045 00046 const size_t SKIP; 00047 00048 byte X, Y; 00049 secure_vector<byte> state; 00050 00051 secure_vector<byte> buffer; 00052 size_t position; 00053 }; 00054 00055 } 00056 00057 #endif