Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/crypto/rc4/rc4_skey.c

raw
1 /*
2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (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
8 */
9
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
16 #include <openssl/rc4.h>
17 #include "rc4_local.h"
18 #include <openssl/opensslv.h>
19
20 const char *RC4_options(void)
21 {
22 if (sizeof(RC4_INT) == 1)
23 return "rc4(char)";
24 else
25 return "rc4(int)";
26 }
27
28 /*-
29 * RC4 as implemented from a posting from
30 * Newsgroups: sci.crypt
31 * Subject: RC4 Algorithm revealed.
32 * Message-ID: <[email protected]>
33 * Date: Wed, 14 Sep 1994 06:35:31 GMT
34 */
35
36 void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
37 {
38 register RC4_INT tmp;
39 register int id1, id2;
40 register RC4_INT *d;
41 unsigned int i;
42
43 d = &(key->data[0]);
44 key->x = 0;
45 key->y = 0;
46 id1 = id2 = 0;
47
48 #define SK_LOOP(d, n) \
49 { \
50 tmp = d[(n)]; \
51 id2 = (data[id1] + tmp + id2) & 0xff; \
52 if (++id1 == len) \
53 id1 = 0; \
54 d[(n)] = d[id2]; \
55 d[id2] = tmp; \
56 }
57
58 for (i = 0; i < 256; i++)
59 d[i] = i;
60 for (i = 0; i < 256; i += 4) {
61 SK_LOOP(d, i + 0);
62 SK_LOOP(d, i + 1);
63 SK_LOOP(d, i + 2);
64 SK_LOOP(d, i + 3);
65 }
66 }