comparison libtomcrypt/src/prngs/sober128.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents 1b9e69c058d2
children f849a5ca2efc
comparison
equal deleted inserted replaced
379:b66a00272a90 382:0cbe8f6dbf9e
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 sober128.c 14 @file sober128.c
291 struct sober128_prng *c; 291 struct sober128_prng *c;
292 ulong32 t, tlen; 292 ulong32 t, tlen;
293 293
294 LTC_ARGCHK(out != NULL); 294 LTC_ARGCHK(out != NULL);
295 LTC_ARGCHK(prng != NULL); 295 LTC_ARGCHK(prng != NULL);
296
297 #ifdef LTC_VALGRIND
298 zeromem(out, outlen);
299 #endif
296 300
297 c = &(prng->sober128); 301 c = &(prng->sober128);
298 t = 0; 302 t = 0;
299 tlen = outlen; 303 tlen = outlen;
300 304
379 LTC_ARGCHK(outlen != NULL); 383 LTC_ARGCHK(outlen != NULL);
380 LTC_ARGCHK(out != NULL); 384 LTC_ARGCHK(out != NULL);
381 LTC_ARGCHK(prng != NULL); 385 LTC_ARGCHK(prng != NULL);
382 386
383 if (*outlen < 64) { 387 if (*outlen < 64) {
388 *outlen = 64;
384 return CRYPT_BUFFER_OVERFLOW; 389 return CRYPT_BUFFER_OVERFLOW;
385 } 390 }
386 391
387 if (sober128_read(out, 64, prng) != 64) { 392 if (sober128_read(out, 64, prng) != 64) {
388 return CRYPT_ERROR_READPRNG; 393 return CRYPT_ERROR_READPRNG;
434 439
435 { 440 {
436 16, 4, 20, 441 16, 4, 20,
437 442
438 /* key */ 443 /* key */
439 { 't', 'e', 's', 't', ' ', 'k', 'e', 'y', 444 { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6b, 0x65, 0x79,
440 ' ', '1', '2', '8', 'b', 'i', 't', 's' }, 445 0x20, 0x31, 0x32, 0x38, 0x62, 0x69, 0x74, 0x73 },
441 446
442 /* IV */ 447 /* IV */
443 { 0x00, 0x00, 0x00, 0x0 }, 448 { 0x00, 0x00, 0x00, 0x00 },
444 449
445 /* expected output */ 450 /* expected output */
446 { 0x43, 0x50, 0x0c, 0xcf, 0x89, 0x91, 0x9f, 0x1d, 451 { 0x43, 0x50, 0x0c, 0xcf, 0x89, 0x91, 0x9f, 0x1d,
447 0xaa, 0x37, 0x74, 0x95, 0xf4, 0xb4, 0x58, 0xc2, 452 0xaa, 0x37, 0x74, 0x95, 0xf4, 0xb4, 0x58, 0xc2,
448 0x40, 0x37, 0x8b, 0xbb } 453 0x40, 0x37, 0x8b, 0xbb }
467 472
468 /* ready up */ 473 /* ready up */
469 if ((err = sober128_ready(&prng)) != CRYPT_OK) { 474 if ((err = sober128_ready(&prng)) != CRYPT_OK) {
470 return err; 475 return err;
471 } 476 }
472 memset(dst, 0, tests[x].len); 477 XMEMSET(dst, 0, tests[x].len);
473 if (sober128_read(dst, tests[x].len, &prng) != (unsigned long)tests[x].len) { 478 if (sober128_read(dst, tests[x].len, &prng) != (unsigned long)tests[x].len) {
474 return CRYPT_ERROR_READPRNG; 479 return CRYPT_ERROR_READPRNG;
475 } 480 }
476 sober128_done(&prng); 481 sober128_done(&prng);
477 if (memcmp(dst, tests[x].out, tests[x].len)) { 482 if (XMEMCMP(dst, tests[x].out, tests[x].len)) {
478 #if 0 483 #if 0
479 printf("\n\nSOBER128 failed, I got:\n"); 484 printf("\n\nSOBER128 failed, I got:\n");
480 for (y = 0; y < tests[x].len; y++) printf("%02x ", dst[y]); 485 for (y = 0; y < tests[x].len; y++) printf("%02x ", dst[y]);
481 printf("\n"); 486 printf("\n");
482 #endif 487 #endif
489 494
490 #endif 495 #endif
491 496
492 497
493 /* $Source: /cvs/libtom/libtomcrypt/src/prngs/sober128.c,v $ */ 498 /* $Source: /cvs/libtom/libtomcrypt/src/prngs/sober128.c,v $ */
494 /* $Revision: 1.3 $ */ 499 /* $Revision: 1.8 $ */
495 /* $Date: 2005/05/05 14:35:59 $ */ 500 /* $Date: 2006/11/05 00:11:36 $ */