8 #include <botan/stream_cipher.h>
10 #if defined(BOTAN_HAS_OPENSSL) && defined(BOTAN_HAS_RC4)
12 #include <botan/internal/openssl.h>
13 #include <botan/parsing.h>
14 #include <botan/exceptn.h>
15 #include <openssl/rc4.h>
21 class OpenSSL_RC4 :
public StreamCipher
24 void clear()
override {
clear_mem(&m_rc4, 1); }
26 std::string provider()
const override {
return "openssl"; }
28 std::string name()
const override
41 StreamCipher* clone()
const override {
return new OpenSSL_RC4(m_skip); }
43 Key_Length_Specification key_spec()
const override
45 return Key_Length_Specification(1, 32);
48 explicit OpenSSL_RC4(
size_t skip = 0) : m_skip(skip) { clear(); }
49 ~OpenSSL_RC4() { clear(); }
51 void set_iv(
const uint8_t*,
size_t len)
override
54 throw Exception(
"RC4 does not support an IV");
57 void seek(uint64_t)
override
59 throw Exception(
"RC4 does not support seeking");
62 void cipher(
const uint8_t in[], uint8_t out[],
size_t length)
override
64 ::RC4(&m_rc4, length, in, out);
67 void key_schedule(
const uint8_t key[],
size_t length)
override
69 ::RC4_set_key(&m_rc4, length, key);
71 for(
size_t i = 0; i != m_skip; ++i)
72 ::RC4(&m_rc4, 1, &d, &d);
81 std::unique_ptr<StreamCipher>
82 make_openssl_rc4(
size_t skip)
84 return std::unique_ptr<StreamCipher>(
new OpenSSL_RC4(skip));
void clear_mem(T *ptr, size_t n)
std::string to_string(const BER_Object &obj)