]>
Commit | Line | Data |
---|---|---|
aa6bb135 RS |
1 | /* |
2 | * Copyright 1995-2016 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 | ||
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 | |
25f2138b | 19 | # include "crypto/evp.h" |
6435f0f6 | 20 | |
0f113f3e MC |
21 | typedef struct { |
22 | RC4_KEY ks; /* working key */ | |
23 | } EVP_RC4_KEY; | |
dbad1690 | 24 | |
44ab2dfd | 25 | # define data(ctx) ((EVP_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx)) |
d02b48c6 | 26 | |
1921eaad | 27 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e | 28 | const unsigned char *iv, int enc); |
be06a934 | 29 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
30 | const unsigned char *in, size_t inl); |
31 | static const EVP_CIPHER r4_cipher = { | |
32 | NID_rc4, | |
33 | 1, EVP_RC4_KEY_SIZE, 0, | |
34 | EVP_CIPH_VARIABLE_LENGTH, | |
35 | rc4_init_key, | |
36 | rc4_cipher, | |
37 | NULL, | |
38 | sizeof(EVP_RC4_KEY), | |
39 | NULL, | |
40 | NULL, | |
41 | NULL, | |
42 | NULL | |
43 | }; | |
58964a49 | 44 | |
0f113f3e MC |
45 | static const EVP_CIPHER r4_40_cipher = { |
46 | NID_rc4_40, | |
47 | 1, 5 /* 40 bit */ , 0, | |
48 | EVP_CIPH_VARIABLE_LENGTH, | |
49 | rc4_init_key, | |
50 | rc4_cipher, | |
51 | NULL, | |
52 | sizeof(EVP_RC4_KEY), | |
53 | NULL, | |
54 | NULL, | |
55 | NULL, | |
56 | NULL | |
57 | }; | |
d02b48c6 | 58 | |
13588350 | 59 | const EVP_CIPHER *EVP_rc4(void) |
0f113f3e | 60 | { |
26a7d938 | 61 | return &r4_cipher; |
0f113f3e | 62 | } |
d02b48c6 | 63 | |
13588350 | 64 | const EVP_CIPHER *EVP_rc4_40(void) |
0f113f3e | 65 | { |
26a7d938 | 66 | return &r4_40_cipher; |
0f113f3e | 67 | } |
58964a49 | 68 | |
1921eaad | 69 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e MC |
70 | const unsigned char *iv, int enc) |
71 | { | |
72 | RC4_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | |
73 | return 1; | |
74 | } | |
d02b48c6 | 75 | |
be06a934 | 76 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
0f113f3e MC |
77 | const unsigned char *in, size_t inl) |
78 | { | |
79 | RC4(&data(ctx)->ks, inl, in, out); | |
80 | return 1; | |
81 | } | |
d02b48c6 | 82 | #endif |