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
final :
public StreamCipher
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 Invalid_IV_Length(
"RC4", len);
57 void seek(uint64_t)
override
59 throw Not_Implemented(
"RC4 does not support seeking");
62 void cipher(
const uint8_t in[], uint8_t out[],
size_t length)
override
65 ::RC4(&m_rc4, length, in, out);
68 void key_schedule(
const uint8_t key[],
size_t length)
override
70 ::RC4_set_key(&m_rc4, length, key);
72 for(
size_t i = 0; i != m_skip; ++i)
73 ::RC4(&m_rc4, 1, &d, &d);
84 std::unique_ptr<StreamCipher>
85 make_openssl_rc4(
size_t skip)
87 return std::unique_ptr<StreamCipher>(
new OpenSSL_RC4(skip));
void clear_mem(T *ptr, size_t n)
int(* final)(unsigned char *, CTX *)
std::string to_string(const BER_Object &obj)