X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fevp%2Fe_rc4.c;h=55baad7446dcef1925232574092a32e54b55cf59;hb=f092a073a75be72731e57b175d2df73d2d0eddd8;hp=e1ffb5d95a6c475e388c8607db80a502f32e8aa5;hpb=eda1f21f1af8b6f77327e7b37573af9c1ba73726;p=oweals%2Fopenssl.git diff --git a/crypto/evp/e_rc4.c b/crypto/evp/e_rc4.c index e1ffb5d95a..55baad7446 100644 --- a/crypto/evp/e_rc4.c +++ b/crypto/evp/e_rc4.c @@ -1,5 +1,5 @@ /* crypto/evp/e_rc4.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -56,54 +56,82 @@ * [including the GNU Public Licence.] */ -#ifndef NO_RC4 - #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#ifndef NOPROTO -static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, - unsigned char *iv,int enc); -static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - unsigned char *in, unsigned int inl); -#else -static void rc4_init_key(); -static void rc4_cipher(); -#endif +#ifndef OPENSSL_NO_RC4 + +#include +#include +#include +#include "evp_locl.h" + +/* FIXME: surely this is available elsewhere? */ +#define EVP_RC4_KEY_SIZE 16 -static EVP_CIPHER r4_cipher= +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, + const unsigned char *in, unsigned int 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 + }; + +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 }; -EVP_CIPHER *EVP_rc4() +const EVP_CIPHER *EVP_rc4(void) { return(&r4_cipher); } -static void rc4_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +const EVP_CIPHER *EVP_rc4_40(void) + { + return(&r4_40_cipher); + } + +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 void rc4_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + 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