diff options
author | jsing <> | 2015-10-20 15:50:13 +0000 |
---|---|---|
committer | jsing <> | 2015-10-20 15:50:13 +0000 |
commit | ef26ca54172e50b3204589c7474e95b12345d711 (patch) | |
tree | 9bf0381ca19cc5e91c0daa171070cc207b6dd93e | |
parent | 484887bb471430ca55befb4cc64954a70c4a6eb9 (diff) | |
download | openbsd-ef26ca54172e50b3204589c7474e95b12345d711.tar.gz openbsd-ef26ca54172e50b3204589c7474e95b12345d711.tar.bz2 openbsd-ef26ca54172e50b3204589c7474e95b12345d711.zip |
Lob a style(9) grenade in here.
-rw-r--r-- | src/lib/libcrypto/rc4/rc4.h | 24 | ||||
-rw-r--r-- | src/lib/libcrypto/rc4/rc4_enc.c | 272 | ||||
-rw-r--r-- | src/lib/libcrypto/rc4/rc4_skey.c | 61 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rc4/rc4.h | 24 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rc4/rc4_enc.c | 272 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rc4/rc4_skey.c | 61 |
6 files changed, 370 insertions, 344 deletions
diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h index 5359577402..f59185ed33 100644 --- a/src/lib/libcrypto/rc4/rc4.h +++ b/src/lib/libcrypto/rc4/rc4.h | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4.h,v 1.12 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: rc4.h,v 1.13 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -71,18 +71,16 @@ | |||
71 | extern "C" { | 71 | extern "C" { |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | typedef struct rc4_key_st | 74 | typedef struct rc4_key_st { |
75 | { | 75 | RC4_INT x, y; |
76 | RC4_INT x,y; | ||
77 | RC4_INT data[256]; | 76 | RC4_INT data[256]; |
78 | } RC4_KEY; | 77 | } RC4_KEY; |
79 | 78 | ||
80 | |||
81 | const char *RC4_options(void); | 79 | const char *RC4_options(void); |
82 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | 80 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); |
83 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | 81 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); |
84 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | 82 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, |
85 | unsigned char *outdata); | 83 | unsigned char *outdata); |
86 | 84 | ||
87 | #ifdef __cplusplus | 85 | #ifdef __cplusplus |
88 | } | 86 | } |
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c index e68edddfea..57975a95ae 100644 --- a/src/lib/libcrypto/rc4/rc4_enc.c +++ b/src/lib/libcrypto/rc4/rc4_enc.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4_enc.c,v 1.13 2014/10/28 07:35:59 jsg Exp $ */ | 1 | /* $OpenBSD: rc4_enc.c,v 1.14 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -68,16 +68,17 @@ | |||
68 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | 68 | * Date: Wed, 14 Sep 1994 06:35:31 GMT |
69 | */ | 69 | */ |
70 | 70 | ||
71 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | 71 | void |
72 | unsigned char *outdata) | 72 | RC4(RC4_KEY *key, size_t len, const unsigned char *indata, |
73 | { | 73 | unsigned char *outdata) |
74 | RC4_INT *d; | 74 | { |
75 | RC4_INT x,y,tx,ty; | 75 | RC4_INT *d; |
76 | RC4_INT x, y,tx, ty; | ||
76 | size_t i; | 77 | size_t i; |
77 | 78 | ||
78 | x=key->x; | 79 | x = key->x; |
79 | y=key->y; | 80 | y = key->y; |
80 | d=key->data; | 81 | d = key->data; |
81 | 82 | ||
82 | #if defined(RC4_CHUNK) | 83 | #if defined(RC4_CHUNK) |
83 | /* | 84 | /* |
@@ -121,10 +122,9 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
121 | (RC4_CHUNK)d[(tx+ty)&0xff]\ | 122 | (RC4_CHUNK)d[(tx+ty)&0xff]\ |
122 | ) | 123 | ) |
123 | 124 | ||
124 | if ( ( ((size_t)indata & (sizeof(RC4_CHUNK)-1)) | | 125 | if ((((size_t)indata & (sizeof(RC4_CHUNK) - 1)) | |
125 | ((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 ) | 126 | ((size_t)outdata & (sizeof(RC4_CHUNK) - 1))) == 0 ) { |
126 | { | 127 | RC4_CHUNK ichunk, otp; |
127 | RC4_CHUNK ichunk,otp; | ||
128 | 128 | ||
129 | /* | 129 | /* |
130 | * I reckon we can afford to implement both endian | 130 | * I reckon we can afford to implement both endian |
@@ -146,107 +146,110 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
146 | * before); | 146 | * before); |
147 | * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in | 147 | * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in |
148 | * [LB]ESHFT guards against "shift is out of range" | 148 | * [LB]ESHFT guards against "shift is out of range" |
149 | * warnings when sizeof(RC4_CHUNK)!=8 | 149 | * warnings when sizeof(RC4_CHUNK)!=8 |
150 | * | 150 | * |
151 | * <appro@fy.chalmers.se> | 151 | * <appro@fy.chalmers.se> |
152 | */ | 152 | */ |
153 | if (BYTE_ORDER != LITTLE_ENDIAN) | 153 | if (BYTE_ORDER != LITTLE_ENDIAN) { /* BIG-ENDIAN CASE */ |
154 | { /* BIG-ENDIAN CASE */ | ||
155 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) | 154 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) |
156 | for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK)) | 155 | for (; len & (0 - sizeof(RC4_CHUNK)); len -= sizeof(RC4_CHUNK)) { |
157 | { | ||
158 | ichunk = *(RC4_CHUNK *)indata; | 156 | ichunk = *(RC4_CHUNK *)indata; |
159 | otp = RC4_STEP<<BESHFT(0); | 157 | otp = RC4_STEP << BESHFT(0); |
160 | otp |= RC4_STEP<<BESHFT(1); | 158 | otp |= RC4_STEP << BESHFT(1); |
161 | otp |= RC4_STEP<<BESHFT(2); | 159 | otp |= RC4_STEP << BESHFT(2); |
162 | otp |= RC4_STEP<<BESHFT(3); | 160 | otp |= RC4_STEP << BESHFT(3); |
163 | if (sizeof(RC4_CHUNK)==8) | 161 | if (sizeof(RC4_CHUNK) == 8) { |
164 | { | 162 | otp |= RC4_STEP << BESHFT(4); |
165 | otp |= RC4_STEP<<BESHFT(4); | 163 | otp |= RC4_STEP << BESHFT(5); |
166 | otp |= RC4_STEP<<BESHFT(5); | 164 | otp |= RC4_STEP << BESHFT(6); |
167 | otp |= RC4_STEP<<BESHFT(6); | 165 | otp |= RC4_STEP << BESHFT(7); |
168 | otp |= RC4_STEP<<BESHFT(7); | 166 | } |
169 | } | ||
170 | *(RC4_CHUNK *)outdata = otp^ichunk; | 167 | *(RC4_CHUNK *)outdata = otp^ichunk; |
171 | indata += sizeof(RC4_CHUNK); | 168 | indata += sizeof(RC4_CHUNK); |
172 | outdata += sizeof(RC4_CHUNK); | 169 | outdata += sizeof(RC4_CHUNK); |
173 | } | 170 | } |
174 | if (len) | 171 | if (len) { |
175 | { | 172 | RC4_CHUNK mask = (RC4_CHUNK) - 1, ochunk; |
176 | RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk; | ||
177 | 173 | ||
178 | ichunk = *(RC4_CHUNK *)indata; | 174 | ichunk = *(RC4_CHUNK *)indata; |
179 | ochunk = *(RC4_CHUNK *)outdata; | 175 | ochunk = *(RC4_CHUNK *)outdata; |
180 | otp = 0; | 176 | otp = 0; |
181 | i = BESHFT(0); | 177 | i = BESHFT(0); |
182 | mask <<= (sizeof(RC4_CHUNK)-len)<<3; | 178 | mask <<= (sizeof(RC4_CHUNK) - len) << 3; |
183 | switch (len&(sizeof(RC4_CHUNK)-1)) | 179 | switch (len & (sizeof(RC4_CHUNK) - 1)) { |
184 | { | 180 | case 7: |
185 | case 7: otp = RC4_STEP<<i, i-=8; | 181 | otp = RC4_STEP << i, i -= 8; |
186 | case 6: otp |= RC4_STEP<<i, i-=8; | 182 | case 6: |
187 | case 5: otp |= RC4_STEP<<i, i-=8; | 183 | otp |= RC4_STEP << i, i -= 8; |
188 | case 4: otp |= RC4_STEP<<i, i-=8; | 184 | case 5: |
189 | case 3: otp |= RC4_STEP<<i, i-=8; | 185 | otp |= RC4_STEP << i, i -= 8; |
190 | case 2: otp |= RC4_STEP<<i, i-=8; | 186 | case 4: |
191 | case 1: otp |= RC4_STEP<<i, i-=8; | 187 | otp |= RC4_STEP << i, i -= 8; |
192 | } | 188 | case 3: |
189 | otp |= RC4_STEP << i, i -= 8; | ||
190 | case 2: | ||
191 | otp |= RC4_STEP << i, i -= 8; | ||
192 | case 1: | ||
193 | otp |= RC4_STEP << i, i -= 8; | ||
194 | } | ||
193 | ochunk &= ~mask; | 195 | ochunk &= ~mask; |
194 | ochunk |= (otp^ichunk) & mask; | 196 | ochunk |= (otp ^ ichunk) & mask; |
195 | *(RC4_CHUNK *)outdata = ochunk; | 197 | *(RC4_CHUNK *)outdata = ochunk; |
196 | } | ||
197 | key->x=x; | ||
198 | key->y=y; | ||
199 | return; | ||
200 | } | 198 | } |
201 | else | 199 | key->x = x; |
202 | { /* LITTLE-ENDIAN CASE */ | 200 | key->y = y; |
201 | return; | ||
202 | } else { /* LITTLE-ENDIAN CASE */ | ||
203 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) | 203 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) |
204 | for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK)) | 204 | for (; len & (0 - sizeof(RC4_CHUNK)); len -= sizeof(RC4_CHUNK)) { |
205 | { | 205 | ichunk = *(RC4_CHUNK *)indata; |
206 | ichunk = *(RC4_CHUNK *)indata; | 206 | otp = RC4_STEP; |
207 | otp = RC4_STEP; | 207 | otp |= RC4_STEP << 8; |
208 | otp |= RC4_STEP<<8; | 208 | otp |= RC4_STEP << 16; |
209 | otp |= RC4_STEP<<16; | 209 | otp |= RC4_STEP << 24; |
210 | otp |= RC4_STEP<<24; | 210 | if (sizeof(RC4_CHUNK) == 8) { |
211 | if (sizeof(RC4_CHUNK)==8) | 211 | otp |= RC4_STEP << LESHFT(4); |
212 | { | 212 | otp |= RC4_STEP << LESHFT(5); |
213 | otp |= RC4_STEP<<LESHFT(4); | 213 | otp |= RC4_STEP << LESHFT(6); |
214 | otp |= RC4_STEP<<LESHFT(5); | 214 | otp |= RC4_STEP << LESHFT(7); |
215 | otp |= RC4_STEP<<LESHFT(6); | ||
216 | otp |= RC4_STEP<<LESHFT(7); | ||
217 | } | ||
218 | *(RC4_CHUNK *)outdata = otp^ichunk; | ||
219 | indata += sizeof(RC4_CHUNK); | ||
220 | outdata += sizeof(RC4_CHUNK); | ||
221 | } | 215 | } |
222 | if (len) | 216 | *(RC4_CHUNK *)outdata = otp ^ ichunk; |
223 | { | 217 | indata += sizeof(RC4_CHUNK); |
224 | RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk; | 218 | outdata += sizeof(RC4_CHUNK); |
219 | } | ||
220 | if (len) { | ||
221 | RC4_CHUNK mask = (RC4_CHUNK) - 1, ochunk; | ||
225 | 222 | ||
226 | ichunk = *(RC4_CHUNK *)indata; | 223 | ichunk = *(RC4_CHUNK *)indata; |
227 | ochunk = *(RC4_CHUNK *)outdata; | 224 | ochunk = *(RC4_CHUNK *)outdata; |
228 | otp = 0; | 225 | otp = 0; |
229 | i = 0; | 226 | i = 0; |
230 | mask >>= (sizeof(RC4_CHUNK)-len)<<3; | 227 | mask >>= (sizeof(RC4_CHUNK) - len) << 3; |
231 | switch (len&(sizeof(RC4_CHUNK)-1)) | 228 | switch (len&(sizeof(RC4_CHUNK) - 1)) { |
232 | { | 229 | case 7: |
233 | case 7: otp = RC4_STEP, i+=8; | 230 | otp = RC4_STEP, i += 8; |
234 | case 6: otp |= RC4_STEP<<i, i+=8; | 231 | case 6: |
235 | case 5: otp |= RC4_STEP<<i, i+=8; | 232 | otp |= RC4_STEP << i, i += 8; |
236 | case 4: otp |= RC4_STEP<<i, i+=8; | 233 | case 5: |
237 | case 3: otp |= RC4_STEP<<i, i+=8; | 234 | otp |= RC4_STEP << i, i += 8; |
238 | case 2: otp |= RC4_STEP<<i, i+=8; | 235 | case 4: |
239 | case 1: otp |= RC4_STEP<<i, i+=8; | 236 | otp |= RC4_STEP << i, i += 8; |
240 | } | 237 | case 3: |
238 | otp |= RC4_STEP << i, i += 8; | ||
239 | case 2: | ||
240 | otp |= RC4_STEP << i, i += 8; | ||
241 | case 1: | ||
242 | otp |= RC4_STEP << i, i += 8; | ||
243 | } | ||
241 | ochunk &= ~mask; | 244 | ochunk &= ~mask; |
242 | ochunk |= (otp^ichunk) & mask; | 245 | ochunk |= (otp ^ ichunk) & mask; |
243 | *(RC4_CHUNK *)outdata = ochunk; | 246 | *(RC4_CHUNK *)outdata = ochunk; |
244 | } | ||
245 | key->x=x; | ||
246 | key->y=y; | ||
247 | return; | ||
248 | } | 247 | } |
248 | key->x = x; | ||
249 | key->y = y; | ||
250 | return; | ||
249 | } | 251 | } |
252 | } | ||
250 | #endif | 253 | #endif |
251 | #define LOOP(in,out) \ | 254 | #define LOOP(in,out) \ |
252 | x=((x+1)&0xff); \ | 255 | x=((x+1)&0xff); \ |
@@ -262,40 +265,51 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
262 | #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) | 265 | #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) |
263 | #endif | 266 | #endif |
264 | 267 | ||
265 | i=len>>3; | 268 | i = len >> 3; |
266 | if (i) | 269 | if (i) { |
267 | { | 270 | for (;;) { |
268 | for (;;) | 271 | RC4_LOOP(indata, outdata, 0); |
269 | { | 272 | RC4_LOOP(indata, outdata, 1); |
270 | RC4_LOOP(indata,outdata,0); | 273 | RC4_LOOP(indata, outdata, 2); |
271 | RC4_LOOP(indata,outdata,1); | 274 | RC4_LOOP(indata, outdata, 3); |
272 | RC4_LOOP(indata,outdata,2); | 275 | RC4_LOOP(indata, outdata, 4); |
273 | RC4_LOOP(indata,outdata,3); | 276 | RC4_LOOP(indata, outdata, 5); |
274 | RC4_LOOP(indata,outdata,4); | 277 | RC4_LOOP(indata, outdata, 6); |
275 | RC4_LOOP(indata,outdata,5); | 278 | RC4_LOOP(indata, outdata, 7); |
276 | RC4_LOOP(indata,outdata,6); | ||
277 | RC4_LOOP(indata,outdata,7); | ||
278 | #ifdef RC4_INDEX | 279 | #ifdef RC4_INDEX |
279 | indata+=8; | 280 | indata += 8; |
280 | outdata+=8; | 281 | outdata += 8; |
281 | #endif | 282 | #endif |
282 | if (--i == 0) break; | 283 | if (--i == 0) |
283 | } | 284 | break; |
285 | } | ||
286 | } | ||
287 | i = len&0x07; | ||
288 | if (i) { | ||
289 | for (;;) { | ||
290 | RC4_LOOP(indata, outdata, 0); | ||
291 | if (--i == 0) | ||
292 | break; | ||
293 | RC4_LOOP(indata, outdata, 1); | ||
294 | if (--i == 0) | ||
295 | break; | ||
296 | RC4_LOOP(indata, outdata, 2); | ||
297 | if (--i == 0) | ||
298 | break; | ||
299 | RC4_LOOP(indata, outdata, 3); | ||
300 | if (--i == 0) | ||
301 | break; | ||
302 | RC4_LOOP(indata, outdata, 4); | ||
303 | if (--i == 0) | ||
304 | break; | ||
305 | RC4_LOOP(indata, outdata, 5); | ||
306 | if (--i == 0) | ||
307 | break; | ||
308 | RC4_LOOP(indata, outdata, 6); | ||
309 | if (--i == 0) | ||
310 | break; | ||
284 | } | 311 | } |
285 | i=len&0x07; | ||
286 | if (i) | ||
287 | { | ||
288 | for (;;) | ||
289 | { | ||
290 | RC4_LOOP(indata,outdata,0); if (--i == 0) break; | ||
291 | RC4_LOOP(indata,outdata,1); if (--i == 0) break; | ||
292 | RC4_LOOP(indata,outdata,2); if (--i == 0) break; | ||
293 | RC4_LOOP(indata,outdata,3); if (--i == 0) break; | ||
294 | RC4_LOOP(indata,outdata,4); if (--i == 0) break; | ||
295 | RC4_LOOP(indata,outdata,5); if (--i == 0) break; | ||
296 | RC4_LOOP(indata,outdata,6); if (--i == 0) break; | ||
297 | } | ||
298 | } | ||
299 | key->x=x; | ||
300 | key->y=y; | ||
301 | } | 312 | } |
313 | key->x = x; | ||
314 | key->y = y; | ||
315 | } | ||
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c index 7ef4da3f15..861941fb4d 100644 --- a/src/lib/libcrypto/rc4/rc4_skey.c +++ b/src/lib/libcrypto/rc4/rc4_skey.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4_skey.c,v 1.13 2014/10/28 07:35:59 jsg Exp $ */ | 1 | /* $OpenBSD: rc4_skey.c,v 1.14 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,8 +60,9 @@ | |||
60 | #include "rc4_locl.h" | 60 | #include "rc4_locl.h" |
61 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
62 | 62 | ||
63 | const char *RC4_options(void) | 63 | const char * |
64 | { | 64 | RC4_options(void) |
65 | { | ||
65 | #ifdef RC4_INDEX | 66 | #ifdef RC4_INDEX |
66 | if (sizeof(RC4_INT) == 1) | 67 | if (sizeof(RC4_INT) == 1) |
67 | return("rc4(idx,char)"); | 68 | return("rc4(idx,char)"); |
@@ -73,7 +74,7 @@ const char *RC4_options(void) | |||
73 | else | 74 | else |
74 | return("rc4(ptr,int)"); | 75 | return("rc4(ptr,int)"); |
75 | #endif | 76 | #endif |
76 | } | 77 | } |
77 | 78 | ||
78 | /* RC4 as implemented from a posting from | 79 | /* RC4 as implemented from a posting from |
79 | * Newsgroups: sci.crypt | 80 | * Newsgroups: sci.crypt |
@@ -83,17 +84,18 @@ const char *RC4_options(void) | |||
83 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | 84 | * Date: Wed, 14 Sep 1994 06:35:31 GMT |
84 | */ | 85 | */ |
85 | 86 | ||
86 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | 87 | void |
87 | { | 88 | RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) |
88 | RC4_INT tmp; | 89 | { |
89 | int id1,id2; | 90 | RC4_INT tmp; |
90 | RC4_INT *d; | 91 | int id1, id2; |
91 | unsigned int i; | 92 | RC4_INT *d; |
92 | 93 | unsigned int i; | |
93 | d= &(key->data[0]); | 94 | |
94 | key->x = 0; | 95 | d = &(key->data[0]); |
95 | key->y = 0; | 96 | key->x = 0; |
96 | id1=id2=0; | 97 | key->y = 0; |
98 | id1 = id2 = 0; | ||
97 | 99 | ||
98 | #define SK_LOOP(d,n) { \ | 100 | #define SK_LOOP(d,n) { \ |
99 | tmp=d[(n)]; \ | 101 | tmp=d[(n)]; \ |
@@ -102,13 +104,12 @@ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | |||
102 | d[(n)]=d[id2]; \ | 104 | d[(n)]=d[id2]; \ |
103 | d[id2]=tmp; } | 105 | d[id2]=tmp; } |
104 | 106 | ||
105 | for (i=0; i < 256; i++) d[i]=i; | 107 | for (i = 0; i < 256; i++) |
106 | for (i=0; i < 256; i+=4) | 108 | d[i] = i; |
107 | { | 109 | for (i = 0; i < 256; i += 4) { |
108 | SK_LOOP(d,i+0); | 110 | SK_LOOP(d, i + 0); |
109 | SK_LOOP(d,i+1); | 111 | SK_LOOP(d, i + 1); |
110 | SK_LOOP(d,i+2); | 112 | SK_LOOP(d, i + 2); |
111 | SK_LOOP(d,i+3); | 113 | SK_LOOP(d, i + 3); |
112 | } | ||
113 | } | 114 | } |
114 | 115 | } | |
diff --git a/src/lib/libssl/src/crypto/rc4/rc4.h b/src/lib/libssl/src/crypto/rc4/rc4.h index 5359577402..f59185ed33 100644 --- a/src/lib/libssl/src/crypto/rc4/rc4.h +++ b/src/lib/libssl/src/crypto/rc4/rc4.h | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4.h,v 1.12 2014/07/10 22:45:57 jsing Exp $ */ | 1 | /* $OpenBSD: rc4.h,v 1.13 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -71,18 +71,16 @@ | |||
71 | extern "C" { | 71 | extern "C" { |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | typedef struct rc4_key_st | 74 | typedef struct rc4_key_st { |
75 | { | 75 | RC4_INT x, y; |
76 | RC4_INT x,y; | ||
77 | RC4_INT data[256]; | 76 | RC4_INT data[256]; |
78 | } RC4_KEY; | 77 | } RC4_KEY; |
79 | 78 | ||
80 | |||
81 | const char *RC4_options(void); | 79 | const char *RC4_options(void); |
82 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | 80 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); |
83 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); | 81 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); |
84 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | 82 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, |
85 | unsigned char *outdata); | 83 | unsigned char *outdata); |
86 | 84 | ||
87 | #ifdef __cplusplus | 85 | #ifdef __cplusplus |
88 | } | 86 | } |
diff --git a/src/lib/libssl/src/crypto/rc4/rc4_enc.c b/src/lib/libssl/src/crypto/rc4/rc4_enc.c index e68edddfea..57975a95ae 100644 --- a/src/lib/libssl/src/crypto/rc4/rc4_enc.c +++ b/src/lib/libssl/src/crypto/rc4/rc4_enc.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4_enc.c,v 1.13 2014/10/28 07:35:59 jsg Exp $ */ | 1 | /* $OpenBSD: rc4_enc.c,v 1.14 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -68,16 +68,17 @@ | |||
68 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | 68 | * Date: Wed, 14 Sep 1994 06:35:31 GMT |
69 | */ | 69 | */ |
70 | 70 | ||
71 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | 71 | void |
72 | unsigned char *outdata) | 72 | RC4(RC4_KEY *key, size_t len, const unsigned char *indata, |
73 | { | 73 | unsigned char *outdata) |
74 | RC4_INT *d; | 74 | { |
75 | RC4_INT x,y,tx,ty; | 75 | RC4_INT *d; |
76 | RC4_INT x, y,tx, ty; | ||
76 | size_t i; | 77 | size_t i; |
77 | 78 | ||
78 | x=key->x; | 79 | x = key->x; |
79 | y=key->y; | 80 | y = key->y; |
80 | d=key->data; | 81 | d = key->data; |
81 | 82 | ||
82 | #if defined(RC4_CHUNK) | 83 | #if defined(RC4_CHUNK) |
83 | /* | 84 | /* |
@@ -121,10 +122,9 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
121 | (RC4_CHUNK)d[(tx+ty)&0xff]\ | 122 | (RC4_CHUNK)d[(tx+ty)&0xff]\ |
122 | ) | 123 | ) |
123 | 124 | ||
124 | if ( ( ((size_t)indata & (sizeof(RC4_CHUNK)-1)) | | 125 | if ((((size_t)indata & (sizeof(RC4_CHUNK) - 1)) | |
125 | ((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 ) | 126 | ((size_t)outdata & (sizeof(RC4_CHUNK) - 1))) == 0 ) { |
126 | { | 127 | RC4_CHUNK ichunk, otp; |
127 | RC4_CHUNK ichunk,otp; | ||
128 | 128 | ||
129 | /* | 129 | /* |
130 | * I reckon we can afford to implement both endian | 130 | * I reckon we can afford to implement both endian |
@@ -146,107 +146,110 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
146 | * before); | 146 | * before); |
147 | * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in | 147 | * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in |
148 | * [LB]ESHFT guards against "shift is out of range" | 148 | * [LB]ESHFT guards against "shift is out of range" |
149 | * warnings when sizeof(RC4_CHUNK)!=8 | 149 | * warnings when sizeof(RC4_CHUNK)!=8 |
150 | * | 150 | * |
151 | * <appro@fy.chalmers.se> | 151 | * <appro@fy.chalmers.se> |
152 | */ | 152 | */ |
153 | if (BYTE_ORDER != LITTLE_ENDIAN) | 153 | if (BYTE_ORDER != LITTLE_ENDIAN) { /* BIG-ENDIAN CASE */ |
154 | { /* BIG-ENDIAN CASE */ | ||
155 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) | 154 | # define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) |
156 | for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK)) | 155 | for (; len & (0 - sizeof(RC4_CHUNK)); len -= sizeof(RC4_CHUNK)) { |
157 | { | ||
158 | ichunk = *(RC4_CHUNK *)indata; | 156 | ichunk = *(RC4_CHUNK *)indata; |
159 | otp = RC4_STEP<<BESHFT(0); | 157 | otp = RC4_STEP << BESHFT(0); |
160 | otp |= RC4_STEP<<BESHFT(1); | 158 | otp |= RC4_STEP << BESHFT(1); |
161 | otp |= RC4_STEP<<BESHFT(2); | 159 | otp |= RC4_STEP << BESHFT(2); |
162 | otp |= RC4_STEP<<BESHFT(3); | 160 | otp |= RC4_STEP << BESHFT(3); |
163 | if (sizeof(RC4_CHUNK)==8) | 161 | if (sizeof(RC4_CHUNK) == 8) { |
164 | { | 162 | otp |= RC4_STEP << BESHFT(4); |
165 | otp |= RC4_STEP<<BESHFT(4); | 163 | otp |= RC4_STEP << BESHFT(5); |
166 | otp |= RC4_STEP<<BESHFT(5); | 164 | otp |= RC4_STEP << BESHFT(6); |
167 | otp |= RC4_STEP<<BESHFT(6); | 165 | otp |= RC4_STEP << BESHFT(7); |
168 | otp |= RC4_STEP<<BESHFT(7); | 166 | } |
169 | } | ||
170 | *(RC4_CHUNK *)outdata = otp^ichunk; | 167 | *(RC4_CHUNK *)outdata = otp^ichunk; |
171 | indata += sizeof(RC4_CHUNK); | 168 | indata += sizeof(RC4_CHUNK); |
172 | outdata += sizeof(RC4_CHUNK); | 169 | outdata += sizeof(RC4_CHUNK); |
173 | } | 170 | } |
174 | if (len) | 171 | if (len) { |
175 | { | 172 | RC4_CHUNK mask = (RC4_CHUNK) - 1, ochunk; |
176 | RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk; | ||
177 | 173 | ||
178 | ichunk = *(RC4_CHUNK *)indata; | 174 | ichunk = *(RC4_CHUNK *)indata; |
179 | ochunk = *(RC4_CHUNK *)outdata; | 175 | ochunk = *(RC4_CHUNK *)outdata; |
180 | otp = 0; | 176 | otp = 0; |
181 | i = BESHFT(0); | 177 | i = BESHFT(0); |
182 | mask <<= (sizeof(RC4_CHUNK)-len)<<3; | 178 | mask <<= (sizeof(RC4_CHUNK) - len) << 3; |
183 | switch (len&(sizeof(RC4_CHUNK)-1)) | 179 | switch (len & (sizeof(RC4_CHUNK) - 1)) { |
184 | { | 180 | case 7: |
185 | case 7: otp = RC4_STEP<<i, i-=8; | 181 | otp = RC4_STEP << i, i -= 8; |
186 | case 6: otp |= RC4_STEP<<i, i-=8; | 182 | case 6: |
187 | case 5: otp |= RC4_STEP<<i, i-=8; | 183 | otp |= RC4_STEP << i, i -= 8; |
188 | case 4: otp |= RC4_STEP<<i, i-=8; | 184 | case 5: |
189 | case 3: otp |= RC4_STEP<<i, i-=8; | 185 | otp |= RC4_STEP << i, i -= 8; |
190 | case 2: otp |= RC4_STEP<<i, i-=8; | 186 | case 4: |
191 | case 1: otp |= RC4_STEP<<i, i-=8; | 187 | otp |= RC4_STEP << i, i -= 8; |
192 | } | 188 | case 3: |
189 | otp |= RC4_STEP << i, i -= 8; | ||
190 | case 2: | ||
191 | otp |= RC4_STEP << i, i -= 8; | ||
192 | case 1: | ||
193 | otp |= RC4_STEP << i, i -= 8; | ||
194 | } | ||
193 | ochunk &= ~mask; | 195 | ochunk &= ~mask; |
194 | ochunk |= (otp^ichunk) & mask; | 196 | ochunk |= (otp ^ ichunk) & mask; |
195 | *(RC4_CHUNK *)outdata = ochunk; | 197 | *(RC4_CHUNK *)outdata = ochunk; |
196 | } | ||
197 | key->x=x; | ||
198 | key->y=y; | ||
199 | return; | ||
200 | } | 198 | } |
201 | else | 199 | key->x = x; |
202 | { /* LITTLE-ENDIAN CASE */ | 200 | key->y = y; |
201 | return; | ||
202 | } else { /* LITTLE-ENDIAN CASE */ | ||
203 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) | 203 | # define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) |
204 | for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK)) | 204 | for (; len & (0 - sizeof(RC4_CHUNK)); len -= sizeof(RC4_CHUNK)) { |
205 | { | 205 | ichunk = *(RC4_CHUNK *)indata; |
206 | ichunk = *(RC4_CHUNK *)indata; | 206 | otp = RC4_STEP; |
207 | otp = RC4_STEP; | 207 | otp |= RC4_STEP << 8; |
208 | otp |= RC4_STEP<<8; | 208 | otp |= RC4_STEP << 16; |
209 | otp |= RC4_STEP<<16; | 209 | otp |= RC4_STEP << 24; |
210 | otp |= RC4_STEP<<24; | 210 | if (sizeof(RC4_CHUNK) == 8) { |
211 | if (sizeof(RC4_CHUNK)==8) | 211 | otp |= RC4_STEP << LESHFT(4); |
212 | { | 212 | otp |= RC4_STEP << LESHFT(5); |
213 | otp |= RC4_STEP<<LESHFT(4); | 213 | otp |= RC4_STEP << LESHFT(6); |
214 | otp |= RC4_STEP<<LESHFT(5); | 214 | otp |= RC4_STEP << LESHFT(7); |
215 | otp |= RC4_STEP<<LESHFT(6); | ||
216 | otp |= RC4_STEP<<LESHFT(7); | ||
217 | } | ||
218 | *(RC4_CHUNK *)outdata = otp^ichunk; | ||
219 | indata += sizeof(RC4_CHUNK); | ||
220 | outdata += sizeof(RC4_CHUNK); | ||
221 | } | 215 | } |
222 | if (len) | 216 | *(RC4_CHUNK *)outdata = otp ^ ichunk; |
223 | { | 217 | indata += sizeof(RC4_CHUNK); |
224 | RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk; | 218 | outdata += sizeof(RC4_CHUNK); |
219 | } | ||
220 | if (len) { | ||
221 | RC4_CHUNK mask = (RC4_CHUNK) - 1, ochunk; | ||
225 | 222 | ||
226 | ichunk = *(RC4_CHUNK *)indata; | 223 | ichunk = *(RC4_CHUNK *)indata; |
227 | ochunk = *(RC4_CHUNK *)outdata; | 224 | ochunk = *(RC4_CHUNK *)outdata; |
228 | otp = 0; | 225 | otp = 0; |
229 | i = 0; | 226 | i = 0; |
230 | mask >>= (sizeof(RC4_CHUNK)-len)<<3; | 227 | mask >>= (sizeof(RC4_CHUNK) - len) << 3; |
231 | switch (len&(sizeof(RC4_CHUNK)-1)) | 228 | switch (len&(sizeof(RC4_CHUNK) - 1)) { |
232 | { | 229 | case 7: |
233 | case 7: otp = RC4_STEP, i+=8; | 230 | otp = RC4_STEP, i += 8; |
234 | case 6: otp |= RC4_STEP<<i, i+=8; | 231 | case 6: |
235 | case 5: otp |= RC4_STEP<<i, i+=8; | 232 | otp |= RC4_STEP << i, i += 8; |
236 | case 4: otp |= RC4_STEP<<i, i+=8; | 233 | case 5: |
237 | case 3: otp |= RC4_STEP<<i, i+=8; | 234 | otp |= RC4_STEP << i, i += 8; |
238 | case 2: otp |= RC4_STEP<<i, i+=8; | 235 | case 4: |
239 | case 1: otp |= RC4_STEP<<i, i+=8; | 236 | otp |= RC4_STEP << i, i += 8; |
240 | } | 237 | case 3: |
238 | otp |= RC4_STEP << i, i += 8; | ||
239 | case 2: | ||
240 | otp |= RC4_STEP << i, i += 8; | ||
241 | case 1: | ||
242 | otp |= RC4_STEP << i, i += 8; | ||
243 | } | ||
241 | ochunk &= ~mask; | 244 | ochunk &= ~mask; |
242 | ochunk |= (otp^ichunk) & mask; | 245 | ochunk |= (otp ^ ichunk) & mask; |
243 | *(RC4_CHUNK *)outdata = ochunk; | 246 | *(RC4_CHUNK *)outdata = ochunk; |
244 | } | ||
245 | key->x=x; | ||
246 | key->y=y; | ||
247 | return; | ||
248 | } | 247 | } |
248 | key->x = x; | ||
249 | key->y = y; | ||
250 | return; | ||
249 | } | 251 | } |
252 | } | ||
250 | #endif | 253 | #endif |
251 | #define LOOP(in,out) \ | 254 | #define LOOP(in,out) \ |
252 | x=((x+1)&0xff); \ | 255 | x=((x+1)&0xff); \ |
@@ -262,40 +265,51 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, | |||
262 | #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) | 265 | #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) |
263 | #endif | 266 | #endif |
264 | 267 | ||
265 | i=len>>3; | 268 | i = len >> 3; |
266 | if (i) | 269 | if (i) { |
267 | { | 270 | for (;;) { |
268 | for (;;) | 271 | RC4_LOOP(indata, outdata, 0); |
269 | { | 272 | RC4_LOOP(indata, outdata, 1); |
270 | RC4_LOOP(indata,outdata,0); | 273 | RC4_LOOP(indata, outdata, 2); |
271 | RC4_LOOP(indata,outdata,1); | 274 | RC4_LOOP(indata, outdata, 3); |
272 | RC4_LOOP(indata,outdata,2); | 275 | RC4_LOOP(indata, outdata, 4); |
273 | RC4_LOOP(indata,outdata,3); | 276 | RC4_LOOP(indata, outdata, 5); |
274 | RC4_LOOP(indata,outdata,4); | 277 | RC4_LOOP(indata, outdata, 6); |
275 | RC4_LOOP(indata,outdata,5); | 278 | RC4_LOOP(indata, outdata, 7); |
276 | RC4_LOOP(indata,outdata,6); | ||
277 | RC4_LOOP(indata,outdata,7); | ||
278 | #ifdef RC4_INDEX | 279 | #ifdef RC4_INDEX |
279 | indata+=8; | 280 | indata += 8; |
280 | outdata+=8; | 281 | outdata += 8; |
281 | #endif | 282 | #endif |
282 | if (--i == 0) break; | 283 | if (--i == 0) |
283 | } | 284 | break; |
285 | } | ||
286 | } | ||
287 | i = len&0x07; | ||
288 | if (i) { | ||
289 | for (;;) { | ||
290 | RC4_LOOP(indata, outdata, 0); | ||
291 | if (--i == 0) | ||
292 | break; | ||
293 | RC4_LOOP(indata, outdata, 1); | ||
294 | if (--i == 0) | ||
295 | break; | ||
296 | RC4_LOOP(indata, outdata, 2); | ||
297 | if (--i == 0) | ||
298 | break; | ||
299 | RC4_LOOP(indata, outdata, 3); | ||
300 | if (--i == 0) | ||
301 | break; | ||
302 | RC4_LOOP(indata, outdata, 4); | ||
303 | if (--i == 0) | ||
304 | break; | ||
305 | RC4_LOOP(indata, outdata, 5); | ||
306 | if (--i == 0) | ||
307 | break; | ||
308 | RC4_LOOP(indata, outdata, 6); | ||
309 | if (--i == 0) | ||
310 | break; | ||
284 | } | 311 | } |
285 | i=len&0x07; | ||
286 | if (i) | ||
287 | { | ||
288 | for (;;) | ||
289 | { | ||
290 | RC4_LOOP(indata,outdata,0); if (--i == 0) break; | ||
291 | RC4_LOOP(indata,outdata,1); if (--i == 0) break; | ||
292 | RC4_LOOP(indata,outdata,2); if (--i == 0) break; | ||
293 | RC4_LOOP(indata,outdata,3); if (--i == 0) break; | ||
294 | RC4_LOOP(indata,outdata,4); if (--i == 0) break; | ||
295 | RC4_LOOP(indata,outdata,5); if (--i == 0) break; | ||
296 | RC4_LOOP(indata,outdata,6); if (--i == 0) break; | ||
297 | } | ||
298 | } | ||
299 | key->x=x; | ||
300 | key->y=y; | ||
301 | } | 312 | } |
313 | key->x = x; | ||
314 | key->y = y; | ||
315 | } | ||
diff --git a/src/lib/libssl/src/crypto/rc4/rc4_skey.c b/src/lib/libssl/src/crypto/rc4/rc4_skey.c index 7ef4da3f15..861941fb4d 100644 --- a/src/lib/libssl/src/crypto/rc4/rc4_skey.c +++ b/src/lib/libssl/src/crypto/rc4/rc4_skey.c | |||
@@ -1,25 +1,25 @@ | |||
1 | /* $OpenBSD: rc4_skey.c,v 1.13 2014/10/28 07:35:59 jsg Exp $ */ | 1 | /* $OpenBSD: rc4_skey.c,v 1.14 2015/10/20 15:50:13 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,8 +60,9 @@ | |||
60 | #include "rc4_locl.h" | 60 | #include "rc4_locl.h" |
61 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
62 | 62 | ||
63 | const char *RC4_options(void) | 63 | const char * |
64 | { | 64 | RC4_options(void) |
65 | { | ||
65 | #ifdef RC4_INDEX | 66 | #ifdef RC4_INDEX |
66 | if (sizeof(RC4_INT) == 1) | 67 | if (sizeof(RC4_INT) == 1) |
67 | return("rc4(idx,char)"); | 68 | return("rc4(idx,char)"); |
@@ -73,7 +74,7 @@ const char *RC4_options(void) | |||
73 | else | 74 | else |
74 | return("rc4(ptr,int)"); | 75 | return("rc4(ptr,int)"); |
75 | #endif | 76 | #endif |
76 | } | 77 | } |
77 | 78 | ||
78 | /* RC4 as implemented from a posting from | 79 | /* RC4 as implemented from a posting from |
79 | * Newsgroups: sci.crypt | 80 | * Newsgroups: sci.crypt |
@@ -83,17 +84,18 @@ const char *RC4_options(void) | |||
83 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | 84 | * Date: Wed, 14 Sep 1994 06:35:31 GMT |
84 | */ | 85 | */ |
85 | 86 | ||
86 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | 87 | void |
87 | { | 88 | RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) |
88 | RC4_INT tmp; | 89 | { |
89 | int id1,id2; | 90 | RC4_INT tmp; |
90 | RC4_INT *d; | 91 | int id1, id2; |
91 | unsigned int i; | 92 | RC4_INT *d; |
92 | 93 | unsigned int i; | |
93 | d= &(key->data[0]); | 94 | |
94 | key->x = 0; | 95 | d = &(key->data[0]); |
95 | key->y = 0; | 96 | key->x = 0; |
96 | id1=id2=0; | 97 | key->y = 0; |
98 | id1 = id2 = 0; | ||
97 | 99 | ||
98 | #define SK_LOOP(d,n) { \ | 100 | #define SK_LOOP(d,n) { \ |
99 | tmp=d[(n)]; \ | 101 | tmp=d[(n)]; \ |
@@ -102,13 +104,12 @@ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | |||
102 | d[(n)]=d[id2]; \ | 104 | d[(n)]=d[id2]; \ |
103 | d[id2]=tmp; } | 105 | d[id2]=tmp; } |
104 | 106 | ||
105 | for (i=0; i < 256; i++) d[i]=i; | 107 | for (i = 0; i < 256; i++) |
106 | for (i=0; i < 256; i+=4) | 108 | d[i] = i; |
107 | { | 109 | for (i = 0; i < 256; i += 4) { |
108 | SK_LOOP(d,i+0); | 110 | SK_LOOP(d, i + 0); |
109 | SK_LOOP(d,i+1); | 111 | SK_LOOP(d, i + 1); |
110 | SK_LOOP(d,i+2); | 112 | SK_LOOP(d, i + 2); |
111 | SK_LOOP(d,i+3); | 113 | SK_LOOP(d, i + 3); |
112 | } | ||
113 | } | 114 | } |
114 | 115 | } | |