X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fevp%2Fe_rc4.c;h=67af850bea1ab955cdc3159bd57bb9f8a55c3b73;hp=bc108f4356d69f082ebe6c294b7fff33fd26951e;hb=8215e7a93897347a97de87b3d26fe84cc8a5b05d;hpb=be06a9348d83187071270a29aabfe10cc3904f85 diff --git a/crypto/evp/e_rc4.c b/crypto/evp/e_rc4.c index bc108f4356..67af850bea 100644 --- a/crypto/evp/e_rc4.c +++ b/crypto/evp/e_rc4.c @@ -56,18 +56,30 @@ * [including the GNU Public Licence.] */ -#ifndef NO_RC4 - #include #include "cryptlib.h" + +#ifndef OPENSSL_NO_RC4 + #include #include +#include + +/* FIXME: surely this is available elsewhere? */ +#define EVP_RC4_KEY_SIZE 16 -static int rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, - unsigned char *iv,int enc); +typedef struct + { + RC4_KEY ks; /* working key */ + } EVP_RC4_KEY; + +#define data(ctx) ((EVP_RC4_KEY *)(ctx)->cipher_data) + +static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv,int enc); static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - unsigned char *in, unsigned int inl); -static EVP_CIPHER r4_cipher= + const unsigned char *in, unsigned int inl); +static const EVP_CIPHER r4_cipher= { NID_rc4, 1,EVP_RC4_KEY_SIZE,0, @@ -75,14 +87,14 @@ static EVP_CIPHER r4_cipher= rc4_init_key, rc4_cipher, NULL, - sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ - sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), + sizeof(EVP_RC4_KEY), + NULL, NULL, NULL, NULL }; -static EVP_CIPHER r4_40_cipher= +static const EVP_CIPHER r4_40_cipher= { NID_rc4_40, 1,5 /* 40 bit */,0, @@ -90,37 +102,35 @@ static EVP_CIPHER r4_40_cipher= rc4_init_key, rc4_cipher, NULL, - sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ - sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), + sizeof(EVP_RC4_KEY), NULL, NULL, + NULL, NULL }; -EVP_CIPHER *EVP_rc4(void) +const EVP_CIPHER *EVP_rc4(void) { return(&r4_cipher); } -EVP_CIPHER *EVP_rc4_40(void) +const EVP_CIPHER *EVP_rc4_40(void) { return(&r4_40_cipher); } -static int rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, - unsigned char *iv, int enc) +static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv, int enc) { - if (key != NULL) - memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); - RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), - ctx->c.rc4.key); + RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), + key); return 1; } static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - unsigned char *in, unsigned int inl) + const unsigned char *in, unsigned int inl) { - RC4(&(ctx->c.rc4.ks),inl,in,out); + RC4(&data(ctx)->ks,inl,in,out); return 1; } #endif