]>
Commit | Line | Data |
---|---|---|
aa6bb135 | 1 | /* |
3c2bdd7d | 2 | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
4a8b0c55 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
aa6bb135 RS |
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 | ||
a8fca728 P |
10 | /* |
11 | * RC4 low level APIs are deprecated for public use, but still ok for internal | |
12 | * use. | |
13 | */ | |
14 | #include "internal/deprecated.h" | |
15 | ||
d02b48c6 | 16 | #include <stdio.h> |
b39fc560 | 17 | #include "internal/cryptlib.h" |
39c4b709 RL |
18 | |
19 | #ifndef OPENSSL_NO_RC4 | |
20 | ||
0f113f3e MC |
21 | # include <openssl/evp.h> |
22 | # include <openssl/objects.h> | |
23 | # include <openssl/rc4.h> | |
dbad1690 | 24 | |
25f2138b | 25 | # include "crypto/evp.h" |
6435f0f6 | 26 | |
0f113f3e MC |
27 | typedef struct { |
28 | RC4_KEY ks; /* working key */ | |
29 | } EVP_RC4_KEY; | |
dbad1690 | 30 | |
44ab2dfd | 31 | # define data(ctx) ((EVP_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx)) |
d02b48c6 | 32 | |
1921eaad | 33 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e | 34 | const unsigned char *iv, int enc); |
be06a934 | 35 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
36 | const unsigned char *in, size_t inl); |
37 | static const EVP_CIPHER r4_cipher = { | |
38 | NID_rc4, | |
39 | 1, EVP_RC4_KEY_SIZE, 0, | |
40 | EVP_CIPH_VARIABLE_LENGTH, | |
41 | rc4_init_key, | |
42 | rc4_cipher, | |
43 | NULL, | |
44 | sizeof(EVP_RC4_KEY), | |
45 | NULL, | |
46 | NULL, | |
47 | NULL, | |
48 | NULL | |
49 | }; | |
58964a49 | 50 | |
0f113f3e MC |
51 | static const EVP_CIPHER r4_40_cipher = { |
52 | NID_rc4_40, | |
53 | 1, 5 /* 40 bit */ , 0, | |
54 | EVP_CIPH_VARIABLE_LENGTH, | |
55 | rc4_init_key, | |
56 | rc4_cipher, | |
57 | NULL, | |
58 | sizeof(EVP_RC4_KEY), | |
59 | NULL, | |
60 | NULL, | |
61 | NULL, | |
62 | NULL | |
63 | }; | |
d02b48c6 | 64 | |
13588350 | 65 | const EVP_CIPHER *EVP_rc4(void) |
0f113f3e | 66 | { |
26a7d938 | 67 | return &r4_cipher; |
0f113f3e | 68 | } |
d02b48c6 | 69 | |
13588350 | 70 | const EVP_CIPHER *EVP_rc4_40(void) |
0f113f3e | 71 | { |
26a7d938 | 72 | return &r4_40_cipher; |
0f113f3e | 73 | } |
58964a49 | 74 | |
1921eaad | 75 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e MC |
76 | const unsigned char *iv, int enc) |
77 | { | |
48b05bb6 P |
78 | int keylen; |
79 | ||
80 | if ((keylen = EVP_CIPHER_CTX_key_length(ctx)) <= 0) | |
81 | return 0; | |
82 | RC4_set_key(&data(ctx)->ks, keylen, key); | |
0f113f3e MC |
83 | return 1; |
84 | } | |
d02b48c6 | 85 | |
be06a934 | 86 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
87 | const unsigned char *in, size_t inl) |
88 | { | |
89 | RC4(&data(ctx)->ks, inl, in, out); | |
90 | return 1; | |
91 | } | |
d02b48c6 | 92 | #endif |