comparison src/prngs/rc4.c @ 381:999a5eb4ed10 libtomcrypt-dropbear

propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28) to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:39:21 +0000
parents d5faf4814ddb
children
comparison
equal deleted inserted replaced
281:997e6f7dc01e 381:999a5eb4ed10
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file rc4.c 14 @file rc4.c
128 unsigned long n; 128 unsigned long n;
129 129
130 LTC_ARGCHK(out != NULL); 130 LTC_ARGCHK(out != NULL);
131 LTC_ARGCHK(prng != NULL); 131 LTC_ARGCHK(prng != NULL);
132 132
133 #ifdef LTC_VALGRIND
134 zeromem(out, outlen);
135 #endif
136
133 n = outlen; 137 n = outlen;
134 x = prng->rc4.x; 138 x = prng->rc4.x;
135 y = prng->rc4.y; 139 y = prng->rc4.y;
136 s = prng->rc4.buf; 140 s = prng->rc4.buf;
137 while (outlen--) { 141 while (outlen--) {
169 LTC_ARGCHK(outlen != NULL); 173 LTC_ARGCHK(outlen != NULL);
170 LTC_ARGCHK(out != NULL); 174 LTC_ARGCHK(out != NULL);
171 LTC_ARGCHK(prng != NULL); 175 LTC_ARGCHK(prng != NULL);
172 176
173 if (*outlen < 32) { 177 if (*outlen < 32) {
178 *outlen = 32;
174 return CRYPT_BUFFER_OVERFLOW; 179 return CRYPT_BUFFER_OVERFLOW;
175 } 180 }
176 181
177 if (rc4_read(out, 32, prng) != 32) { 182 if (rc4_read(out, 32, prng) != 32) {
178 return CRYPT_ERROR_READPRNG; 183 return CRYPT_ERROR_READPRNG;
209 PRNG self-test 214 PRNG self-test
210 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled 215 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
211 */ 216 */
212 int rc4_test(void) 217 int rc4_test(void)
213 { 218 {
214 #ifndef LTC_TEST 219 #if !defined(LTC_TEST) || defined(LTC_VALGRIND)
215 return CRYPT_NOP; 220 return CRYPT_NOP;
216 #else 221 #else
217 static const struct { 222 static const struct {
218 unsigned char key[8], pt[8], ct[8]; 223 unsigned char key[8], pt[8], ct[8];
219 } tests[] = { 224 } tests[] = {
240 XMEMCPY(dst, tests[x].pt, 8); 245 XMEMCPY(dst, tests[x].pt, 8);
241 if (rc4_read(dst, 8, &prng) != 8) { 246 if (rc4_read(dst, 8, &prng) != 8) {
242 return CRYPT_ERROR_READPRNG; 247 return CRYPT_ERROR_READPRNG;
243 } 248 }
244 rc4_done(&prng); 249 rc4_done(&prng);
245 if (memcmp(dst, tests[x].ct, 8)) { 250 if (XMEMCMP(dst, tests[x].ct, 8)) {
246 #if 0 251 #if 0
247 int y; 252 int y;
248 printf("\n\nRC4 failed, I got:\n"); 253 printf("\n\nRC4 failed, I got:\n");
249 for (y = 0; y < 8; y++) printf("%02x ", dst[y]); 254 for (y = 0; y < 8; y++) printf("%02x ", dst[y]);
250 printf("\n"); 255 printf("\n");
258 263
259 #endif 264 #endif
260 265
261 266
262 /* $Source: /cvs/libtom/libtomcrypt/src/prngs/rc4.c,v $ */ 267 /* $Source: /cvs/libtom/libtomcrypt/src/prngs/rc4.c,v $ */
263 /* $Revision: 1.3 $ */ 268 /* $Revision: 1.9 $ */
264 /* $Date: 2005/05/05 14:35:59 $ */ 269 /* $Date: 2006/11/16 00:32:18 $ */