2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
13 #ifndef OPENSSL_NO_RC4
15 # include <openssl/evp.h>
16 # include <openssl/objects.h>
17 # include <openssl/rc4.h>
19 # include "internal/evp_int.h"
22 RC4_KEY ks; /* working key */
25 # define data(ctx) ((EVP_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))
27 static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
28 const unsigned char *iv, int enc);
29 static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
30 const unsigned char *in, size_t inl);
31 static const EVP_CIPHER r4_cipher = {
33 1, EVP_RC4_KEY_SIZE, 0,
34 EVP_CIPH_VARIABLE_LENGTH,
45 static const EVP_CIPHER r4_40_cipher = {
47 1, 5 /* 40 bit */ , 0,
48 EVP_CIPH_VARIABLE_LENGTH,
59 const EVP_CIPHER *EVP_rc4(void)
64 const EVP_CIPHER *EVP_rc4_40(void)
69 static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
70 const unsigned char *iv, int enc)
72 RC4_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
76 static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
77 const unsigned char *in, size_t inl)
79 RC4(&data(ctx)->ks, inl, in, out);