]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rc4/rc4_skey.c
Reorganize local header files
[thirdparty/openssl.git] / crypto / rc4 / rc4_skey.c
CommitLineData
62867571
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
58964a49 3 *
5e4435a7 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
62867571
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
58964a49
RE
8 */
9
ec577822 10#include <openssl/rc4.h>
706457b7 11#include "rc4_local.h"
ec577822 12#include <openssl/opensslv.h>
58964a49 13
6b691a5c 14const char *RC4_options(void)
0f113f3e 15{
0f113f3e 16 if (sizeof(RC4_INT) == 1)
26a7d938 17 return "rc4(char)";
0f113f3e 18 else
26a7d938 19 return "rc4(int)";
0f113f3e 20}
58964a49 21
c80fd6b2
MC
22/*-
23 * RC4 as implemented from a posting from
58964a49 24 * Newsgroups: sci.crypt
58964a49
RE
25 * Subject: RC4 Algorithm revealed.
26 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
27 * Date: Wed, 14 Sep 1994 06:35:31 GMT
28 */
29
c236e66d 30void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
0f113f3e
MC
31{
32 register RC4_INT tmp;
33 register int id1, id2;
34 register RC4_INT *d;
35 unsigned int i;
36
37 d = &(key->data[0]);
38 key->x = 0;
39 key->y = 0;
40 id1 = id2 = 0;
58964a49 41
376729e1 42#define SK_LOOP(d,n) { \
0f113f3e
MC
43 tmp=d[(n)]; \
44 id2 = (data[id1] + tmp + id2) & 0xff; \
45 if (++id1 == len) id1=0; \
46 d[(n)]=d[id2]; \
47 d[id2]=tmp; }
58964a49 48
0f113f3e
MC
49 for (i = 0; i < 256; i++)
50 d[i] = i;
51 for (i = 0; i < 256; i += 4) {
52 SK_LOOP(d, i + 0);
53 SK_LOOP(d, i + 1);
54 SK_LOOP(d, i + 2);
55 SK_LOOP(d, i + 3);
56 }
57}