]>
Commit | Line | Data |
---|---|---|
aa6bb135 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 3 | * |
aa6bb135 RS |
4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
d02b48c6 | 10 | #include <stdio.h> |
b39fc560 | 11 | #include "internal/cryptlib.h" |
39c4b709 RL |
12 | |
13 | #ifndef OPENSSL_NO_RC4 | |
14 | ||
0f113f3e MC |
15 | # include <openssl/evp.h> |
16 | # include <openssl/objects.h> | |
17 | # include <openssl/rc4.h> | |
dbad1690 | 18 | |
6435f0f6 RL |
19 | # include "internal/evp_int.h" |
20 | ||
dbad1690 | 21 | /* FIXME: surely this is available elsewhere? */ |
0f113f3e | 22 | # define EVP_RC4_KEY_SIZE 16 |
dbad1690 | 23 | |
0f113f3e MC |
24 | typedef struct { |
25 | RC4_KEY ks; /* working key */ | |
26 | } EVP_RC4_KEY; | |
dbad1690 | 27 | |
44ab2dfd | 28 | # define data(ctx) ((EVP_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx)) |
d02b48c6 | 29 | |
1921eaad | 30 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e | 31 | const unsigned char *iv, int enc); |
be06a934 | 32 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
33 | const unsigned char *in, size_t inl); |
34 | static const EVP_CIPHER r4_cipher = { | |
35 | NID_rc4, | |
36 | 1, EVP_RC4_KEY_SIZE, 0, | |
37 | EVP_CIPH_VARIABLE_LENGTH, | |
38 | rc4_init_key, | |
39 | rc4_cipher, | |
40 | NULL, | |
41 | sizeof(EVP_RC4_KEY), | |
42 | NULL, | |
43 | NULL, | |
44 | NULL, | |
45 | NULL | |
46 | }; | |
58964a49 | 47 | |
0f113f3e MC |
48 | static const EVP_CIPHER r4_40_cipher = { |
49 | NID_rc4_40, | |
50 | 1, 5 /* 40 bit */ , 0, | |
51 | EVP_CIPH_VARIABLE_LENGTH, | |
52 | rc4_init_key, | |
53 | rc4_cipher, | |
54 | NULL, | |
55 | sizeof(EVP_RC4_KEY), | |
56 | NULL, | |
57 | NULL, | |
58 | NULL, | |
59 | NULL | |
60 | }; | |
d02b48c6 | 61 | |
13588350 | 62 | const EVP_CIPHER *EVP_rc4(void) |
0f113f3e MC |
63 | { |
64 | return (&r4_cipher); | |
65 | } | |
d02b48c6 | 66 | |
13588350 | 67 | const EVP_CIPHER *EVP_rc4_40(void) |
0f113f3e MC |
68 | { |
69 | return (&r4_40_cipher); | |
70 | } | |
58964a49 | 71 | |
1921eaad | 72 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e MC |
73 | const unsigned char *iv, int enc) |
74 | { | |
75 | RC4_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | |
76 | return 1; | |
77 | } | |
d02b48c6 | 78 | |
be06a934 | 79 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
80 | const unsigned char *in, size_t inl) |
81 | { | |
82 | RC4(&data(ctx)->ks, inl, in, out); | |
83 | return 1; | |
84 | } | |
d02b48c6 | 85 | #endif |