]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/evp/e_rc4.c
Add "origin" field to EVP_CIPHER, EVP_MD
[thirdparty/openssl.git] / crypto / evp / e_rc4.c
CommitLineData
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
27typedef 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 33static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
0f113f3e 34 const unsigned char *iv, int enc);
be06a934 35static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
0f113f3e
MC
36 const unsigned char *in, size_t inl);
37static const EVP_CIPHER r4_cipher = {
38 NID_rc4,
39 1, EVP_RC4_KEY_SIZE, 0,
40 EVP_CIPH_VARIABLE_LENGTH,
f6c95e46 41 EVP_ORIG_GLOBAL,
0f113f3e
MC
42 rc4_init_key,
43 rc4_cipher,
44 NULL,
45 sizeof(EVP_RC4_KEY),
46 NULL,
47 NULL,
48 NULL,
49 NULL
50};
58964a49 51
0f113f3e
MC
52static const EVP_CIPHER r4_40_cipher = {
53 NID_rc4_40,
54 1, 5 /* 40 bit */ , 0,
55 EVP_CIPH_VARIABLE_LENGTH,
f6c95e46 56 EVP_ORIG_GLOBAL,
0f113f3e
MC
57 rc4_init_key,
58 rc4_cipher,
59 NULL,
60 sizeof(EVP_RC4_KEY),
61 NULL,
62 NULL,
63 NULL,
64 NULL
65};
d02b48c6 66
13588350 67const EVP_CIPHER *EVP_rc4(void)
0f113f3e 68{
26a7d938 69 return &r4_cipher;
0f113f3e 70}
d02b48c6 71
13588350 72const EVP_CIPHER *EVP_rc4_40(void)
0f113f3e 73{
26a7d938 74 return &r4_40_cipher;
0f113f3e 75}
58964a49 76
1921eaad 77static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
0f113f3e
MC
78 const unsigned char *iv, int enc)
79{
48b05bb6
P
80 int keylen;
81
82 if ((keylen = EVP_CIPHER_CTX_key_length(ctx)) <= 0)
83 return 0;
84 RC4_set_key(&data(ctx)->ks, keylen, key);
0f113f3e
MC
85 return 1;
86}
d02b48c6 87
be06a934 88static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
0f113f3e
MC
89 const unsigned char *in, size_t inl)
90{
91 RC4(&data(ctx)->ks, inl, in, out);
92 return 1;
93}
d02b48c6 94#endif