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