Botan  1.11.15
src/lib/vendor/openssl/openssl_rc4.cpp
Go to the documentation of this file.
00001 /*
00002 * OpenSSL RC4
00003 * (C) 1999-2007,2015 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/internal/stream_utils.h>
00009 #include <botan/parsing.h>
00010 #include <openssl/rc4.h>
00011 
00012 namespace Botan {
00013 
00014 namespace {
00015 
00016 class OpenSSL_RC4 : public StreamCipher
00017    {
00018    public:
00019       void clear() { clear_mem(&m_rc4, 1); }
00020 
00021       std::string name() const { return "RC4"; }
00022       StreamCipher* clone() const { return new OpenSSL_RC4; }
00023 
00024       Key_Length_Specification key_spec() const
00025          {
00026          return Key_Length_Specification(1, 32);
00027          }
00028 
00029       OpenSSL_RC4() { clear(); }
00030       ~OpenSSL_RC4() { clear(); }
00031    private:
00032       void cipher(const byte in[], byte out[], size_t length)
00033          {
00034          ::RC4(&m_rc4, length, in, out);
00035          }
00036 
00037       void key_schedule(const byte key[], size_t length)
00038          {
00039          ::RC4_set_key(&m_rc4, length, key);
00040          }
00041 
00042       RC4_KEY m_rc4;
00043    };
00044 
00045 }
00046 
00047 BOTAN_REGISTER_TYPE(StreamCipher, OpenSSL_RC4, "RC4", make_new_T<OpenSSL_RC4>, "openssl", 64);
00048 
00049 }