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