2016-05-18 03:38:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2016-05-18 03:38:09 +08:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2003-03-21 07:29:17 +08:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_RC4
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/objects.h>
|
|
|
|
# include <openssl/rc4.h>
|
2001-07-31 07:57:25 +08:00
|
|
|
|
2015-12-19 00:01:28 +08:00
|
|
|
# include "internal/evp_int.h"
|
|
|
|
|
2001-07-31 07:57:25 +08:00
|
|
|
/* FIXME: surely this is available elsewhere? */
|
2015-01-22 11:40:55 +08:00
|
|
|
# define EVP_RC4_KEY_SIZE 16
|
2001-07-31 07:57:25 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
typedef struct {
|
|
|
|
RC4_KEY ks; /* working key */
|
|
|
|
} EVP_RC4_KEY;
|
2001-07-31 07:57:25 +08:00
|
|
|
|
2016-03-07 18:17:27 +08:00
|
|
|
# define data(ctx) ((EVP_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-06-03 22:13:58 +08:00
|
|
|
static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *iv, int enc);
|
2000-05-27 20:38:43 +08:00
|
|
|
static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *in, size_t inl);
|
|
|
|
static const EVP_CIPHER r4_cipher = {
|
|
|
|
NID_rc4,
|
|
|
|
1, EVP_RC4_KEY_SIZE, 0,
|
|
|
|
EVP_CIPH_VARIABLE_LENGTH,
|
|
|
|
rc4_init_key,
|
|
|
|
rc4_cipher,
|
|
|
|
NULL,
|
|
|
|
sizeof(EVP_RC4_KEY),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
static const EVP_CIPHER r4_40_cipher = {
|
|
|
|
NID_rc4_40,
|
|
|
|
1, 5 /* 40 bit */ , 0,
|
|
|
|
EVP_CIPH_VARIABLE_LENGTH,
|
|
|
|
rc4_init_key,
|
|
|
|
rc4_cipher,
|
|
|
|
NULL,
|
|
|
|
sizeof(EVP_RC4_KEY),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2001-03-09 10:51:02 +08:00
|
|
|
const EVP_CIPHER *EVP_rc4(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return (&r4_cipher);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2001-03-09 10:51:02 +08:00
|
|
|
const EVP_CIPHER *EVP_rc4_40(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return (&r4_40_cipher);
|
|
|
|
}
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2000-06-03 22:13:58 +08:00
|
|
|
static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *iv, int enc)
|
|
|
|
{
|
|
|
|
RC4_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
|
|
|
|
return 1;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-27 20:38:43 +08:00
|
|
|
static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *in, size_t inl)
|
|
|
|
{
|
|
|
|
RC4(&data(ctx)->ks, inl, in, out);
|
|
|
|
return 1;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
#endif
|