/src/openssl/crypto/rc4/rc4_skey.c
Line  | Count  | Source (jump to first uncovered line)  | 
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  | 0  | { | 
22  | 0  |     if (sizeof(RC4_INT) == 1)  | 
23  | 0  |         return "rc4(char)";  | 
24  | 0  |     else  | 
25  | 0  |         return "rc4(int)";  | 
26  | 0  | }  | 
27  |  |  | 
28  |  | /*-  | 
29  |  |  * RC4 as implemented from a posting from  | 
30  |  |  * Newsgroups: sci.crypt  | 
31  |  |  * Subject: RC4 Algorithm revealed.  | 
32  |  |  * Message-ID: <sternCvKL4B.Hyy@netcom.com>  | 
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  | 0  | { | 
38  | 0  |     register RC4_INT tmp;  | 
39  | 0  |     register int id1, id2;  | 
40  | 0  |     register RC4_INT *d;  | 
41  | 0  |     unsigned int i;  | 
42  |  | 
  | 
43  | 0  |     d = &(key->data[0]);  | 
44  | 0  |     key->x = 0;  | 
45  | 0  |     key->y = 0;  | 
46  | 0  |     id1 = id2 = 0;  | 
47  |  | 
  | 
48  | 0  | #define SK_LOOP(d,n) { \ | 
49  | 0  |                 tmp=d[(n)]; \  | 
50  | 0  |                 id2 = (data[id1] + tmp + id2) & 0xff; \  | 
51  | 0  |                 if (++id1 == len) id1=0; \  | 
52  | 0  |                 d[(n)]=d[id2]; \  | 
53  | 0  |                 d[id2]=tmp; }  | 
54  |  | 
  | 
55  | 0  |     for (i = 0; i < 256; i++)  | 
56  | 0  |         d[i] = i;  | 
57  | 0  |     for (i = 0; i < 256; i += 4) { | 
58  | 0  |         SK_LOOP(d, i + 0);  | 
59  | 0  |         SK_LOOP(d, i + 1);  | 
60  | 0  |         SK_LOOP(d, i + 2);  | 
61  | 0  |         SK_LOOP(d, i + 3);  | 
62  | 0  |     }  | 
63  | 0  | }  |