summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_rc4.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_rc4.c')
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
index 1c1e3b3857..4064cc5fa0 100644
--- a/src/lib/libcrypto/evp/e_rc4.c
+++ b/src/lib/libcrypto/evp/e_rc4.c
@@ -56,18 +56,31 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RC4 59#ifndef OPENSSL_NO_RC4
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include <openssl/rc4.h>
66
67/* FIXME: surely this is available elsewhere? */
68#define EVP_RC4_KEY_SIZE 16
69
70typedef struct
71 {
72 /* FIXME: what is the key for? */
73 unsigned char key[EVP_RC4_KEY_SIZE];
74 RC4_KEY ks; /* working key */
75 } EVP_RC4_KEY;
76
77#define data(ctx) ((EVP_RC4_KEY *)(ctx)->cipher_data)
65 78
66static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 79static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv,int enc); 80 const unsigned char *iv,int enc);
68static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 81static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 const unsigned char *in, unsigned int inl); 82 const unsigned char *in, unsigned int inl);
70static EVP_CIPHER r4_cipher= 83static const EVP_CIPHER r4_cipher=
71 { 84 {
72 NID_rc4, 85 NID_rc4,
73 1,EVP_RC4_KEY_SIZE,0, 86 1,EVP_RC4_KEY_SIZE,0,
@@ -75,14 +88,13 @@ static EVP_CIPHER r4_cipher=
75 rc4_init_key, 88 rc4_init_key,
76 rc4_cipher, 89 rc4_cipher,
77 NULL, 90 NULL,
78 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 91 sizeof(EVP_RC4_KEY),
79 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)),
80 NULL, 92 NULL,
81 NULL, 93 NULL,
82 NULL 94 NULL
83 }; 95 };
84 96
85static EVP_CIPHER r4_40_cipher= 97static const EVP_CIPHER r4_40_cipher=
86 { 98 {
87 NID_rc4_40, 99 NID_rc4_40,
88 1,5 /* 40 bit */,0, 100 1,5 /* 40 bit */,0,
@@ -90,19 +102,18 @@ static EVP_CIPHER r4_40_cipher=
90 rc4_init_key, 102 rc4_init_key,
91 rc4_cipher, 103 rc4_cipher,
92 NULL, 104 NULL,
93 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 105 sizeof(EVP_RC4_KEY),
94 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)),
95 NULL, 106 NULL,
96 NULL, 107 NULL,
97 NULL 108 NULL
98 }; 109 };
99 110
100EVP_CIPHER *EVP_rc4(void) 111const EVP_CIPHER *EVP_rc4(void)
101 { 112 {
102 return(&r4_cipher); 113 return(&r4_cipher);
103 } 114 }
104 115
105EVP_CIPHER *EVP_rc4_40(void) 116const EVP_CIPHER *EVP_rc4_40(void)
106 { 117 {
107 return(&r4_40_cipher); 118 return(&r4_40_cipher);
108 } 119 }
@@ -110,16 +121,16 @@ EVP_CIPHER *EVP_rc4_40(void)
110static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 121static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc) 122 const unsigned char *iv, int enc)
112 { 123 {
113 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); 124 memcpy(&data(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
114 RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), 125 RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
115 ctx->c.rc4.key); 126 data(ctx)->key);
116 return 1; 127 return 1;
117 } 128 }
118 129
119static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 130static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
120 const unsigned char *in, unsigned int inl) 131 const unsigned char *in, unsigned int inl)
121 { 132 {
122 RC4(&(ctx->c.rc4.ks),inl,in,out); 133 RC4(&data(ctx)->ks,inl,in,out);
123 return 1; 134 return 1;
124 } 135 }
125#endif 136#endif