89 #define tdesEncrypt( data, key ) \
90 des_ecb3_encrypt( ( C_Block * ) ( data ), ( C_Block * ) ( data ), \
91 ( key )->desKey1, ( key )->desKey2, \
92 ( key )->desKey3, DES_ENCRYPT )
112 REQUIRES( sanityCheck( randomInfo ) );
116 randomInfo->x917Inited =
FALSE;
142 if( dateTime != NULL )
145 randomInfo->useX931 =
TRUE;
150 randomInfo->x917Inited =
TRUE;
151 randomInfo->x917Count = 0;
153 ENSURES( sanityCheck( randomInfo ) );
174 REQUIRES( sanityCheck( randomInfo ) );
177 REQUIRES( randomInfo->x917Count >= 0 && \
187 for( dataBlockPos = 0; dataBlockPos <
length;
201 if( randomInfo->useX931 )
212 memcpy( encTime, dataPtr, bytesToCopy );
215 FORALL( k, 0, bytesToCopy,
216 encTime[ k ] == data[ dataBlockPos + k ] );
222 randomInfo->x917Pool[ i ] ^= encTime[ i ];
223 tdesEncrypt( randomInfo->x917Pool, &randomInfo->x917Key );
224 memcpy( dataPtr, randomInfo->x917Pool, bytesToCopy );
228 FORALL( k, 0, bytesToCopy, \
229 data[ dataBlockPos + k ] == randomInfo->x917Pool[ k ] );
233 randomInfo->x917Pool[ i ] ^= encTime[ i ];
234 tdesEncrypt( randomInfo->x917Pool, &randomInfo->x917Key );
241 if( randomInfo->useX931 )
247 for( i = X917_POOLSIZE - 1; i >= 0; i-- )
249 randomInfo->x917DT[ i ]++;
250 if( randomInfo->x917DT[ i ] != 0 )
255 ENSURES( ( randomInfo->x917DT[ X917_POOLSIZE - 1 ] == \
257 ( randomInfo->x917DT[ X917_POOLSIZE - 1 ] == 0 && \
258 randomInfo->x917DT[ X917_POOLSIZE - 2 ] == \
260 ( randomInfo->x917DT[ X917_POOLSIZE - 1 ] == 0 && \
261 randomInfo->x917DT[ X917_POOLSIZE - 2 ] == 0 && \
262 randomInfo->x917DT[ X917_POOLSIZE - 3 ] == \
267 dataPtr += bytesToCopy;
268 randomInfo->x917Count++;
271 ENSURES( dataPtr == data + dataBlockPos + bytesToCopy );
276 ENSURES( dataPtr == data + length );
284 ENSURES( sanityCheck( randomInfo ) );
301 #define RNG_TEST_NIST 0
302 #define RNG_TEST_INFOGARD 1
303 #define RNG_TEST_FIPSEVAL 2
305 #define RNG_TEST_VALUES RNG_TEST_INFOGARD
307 #if ( RNG_TEST_VALUES == RNG_TEST_NIST )
308 #define VST_ITERATIONS 5
309 #elif ( RNG_TEST_VALUES == RNG_TEST_INFOGARD )
310 #define VST_ITERATIONS 64
311 #elif ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
312 #define VST_ITERATIONS 64
330 #if ( RNG_TEST_VALUES == RNG_TEST_NIST )
336 "\x75\xC7\x1A\xE5\xA1\x1A\x23\x2C\x40\x25\x6D\xCD\x94\xF7\x67\xB0",
337 "\xC8\x9A\x1D\x88\x8E\xD1\x2F\x3C",
338 "\xD5\x53\x8F\x9C\xF4\x50\xF5\x3C",
339 "\x77\xC6\x95\xC3\x3E\x51\xC8\xC0"
340 #elif ( RNG_TEST_VALUES == RNG_TEST_INFOGARD )
346 "\x62\x5B\xB5\x13\x1A\x45\xF4\x92\x70\x97\x1C\x9E\x0D\x4C\x97\x92",
347 "\x5F\x32\x82\x64\xB7\x87\xB0\x98",
348 "\xA2\x4F\x6E\x0E\xE4\x32\x04\xCD",
349 "\xC7\xAC\x1E\x8F\x10\x0C\xC3\x0A"
350 #elif ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
356 "\xA4\x5B\xF2\xE5\x0D\x15\x37\x10\x79\x83\x2F\x38\xA8\x9B\x2A\xB0",
357 "\x82\x19\xE0\x1B\x2A\x69\x58\xBB",
358 "\x28\x31\x76\xBA\x23\xFA\x31\x81",
364 #if ( RNG_TEST_VALUES == RNG_TEST_NIST )
370 "\x75\xC7\x1A\xE5\xA1\x1A\x23\x2C\x40\x25\x6D\xCD\x94\xF7\x67\xB0",
371 "\xC8\x9A\x1D\x88\x8E\xD1\x2F\x3C",
372 "\x80\x00\x00\x00\x00\x00\x00\x00",
374 {
"\x94\x4D\xC7\x21\x0D\x6D\x7F\xD7",
376 "\xAF\x1A\x64\x85\x91\xBB\x7C\x2C",
378 "\x22\x18\x39\xB0\x74\x51\xE4\x23",
380 "\xEB\xA9\x27\x1E\x04\x04\x37\x12",
382 "\x02\x43\x3C\x94\x17\xA3\x32\x6F" }
383 #elif ( RNG_TEST_VALUES == RNG_TEST_INFOGARD )
389 "\x31\x64\x91\x6E\xA2\xC8\x7A\xAE\x2A\xBC\x32\x3E\xFB\x98\x02\xE3",
390 "\x65\xB9\x10\x82\x77\xAC\x05\x82",
391 "\x80\x00\x00\x00\x00\x00\x00\x00",
393 {
"\xD8\x01\x5B\x96\x6A\xDE\x69\xBA",
395 "\xE7\x37\xE1\x87\x34\x36\x5F\x43",
397 "\xCA\x8F\x00\xC1\xDF\x28\xFC\xFF",
399 "\x9F\xF3\x07\x02\x76\x22\xFA\x2A",
401 "\x0A\x4B\xB2\xE5\x48\x42\x64\x8E",
403 "\xFF\xAD\x84\xA5\x7E\xE0\xDE\x37",
405 "\x0C\xF0\x64\x31\x3A\x78\x89\xFD",
407 "\x97\xB6\x85\x44\x47\xD9\x5A\x01",
409 "\x55\x27\x2F\x90\x0A\xE1\x39\x48",
411 "\xDB\xD7\x31\xBD\xF9\x87\x5A\x04",
413 "\xB1\x95\x89\xA3\x71\xD4\x94\x2D",
415 "\x8D\xA8\xF8\xE8\xC5\x9F\xC4\x97",
417 "\xDD\xFB\xF3\xF3\x19\xBC\xDA\x42",
419 "\xA7\x2D\xDD\x98\xD1\x74\x48\x44",
421 "\xDE\x08\x35\x03\x44\x56\x62\x9E",
423 "\xE9\x77\xDA\xAF\xEF\x7A\xA5\xE0",
425 "\x01\x9C\x3E\xDC\x5A\xE9\x3A\xB8",
427 "\x16\x3C\x3D\xBE\x31\xFF\xD9\x1B",
429 "\xF2\x04\x58\x93\x94\x5B\x47\x74",
431 "\x50\xC8\x87\x99\xFC\x1E\xC5\x5D",
433 "\x15\x45\xF4\x63\x98\x6E\x15\x11",
435 "\x55\xF9\x99\x62\x4F\xE0\x45\xA6",
437 "\xE3\xE0\xDB\x84\x4B\xCA\x75\x05",
439 "\x8F\xB4\xB7\x6D\x80\x85\x62\xD7",
441 "\x9D\x54\x57\xBA\xAE\xB4\x96\xE4",
443 "\x2B\x8A\xBF\xF2\xBD\xC8\x23\x66",
445 "\x39\x36\xC3\x24\xD0\x94\x65\xAF",
447 "\x19\x83\xDD\x22\x7E\x55\x24\x0E",
449 "\x86\x6C\xF6\xE6\xDC\x3D\x03\xFB",
451 "\x03\xD1\x0B\x0F\x17\xB0\x4B\x59",
453 "\x3E\xEB\x1C\xD0\x24\x8E\x25\xA6",
455 "\x9D\x8B\xD4\xB8\xC3\xE4\x25\xDC",
457 "\xBC\x51\x5D\x3A\x0A\x71\x9B\xE1",
459 "\x1B\x35\xFB\x4A\xCA\x4A\xC4\x7C",
461 "\xF8\x33\x86\x68\xB6\xEA\xD4\x93",
463 "\xCD\xFA\x8E\x5F\xFA\x2D\xEB\x17",
465 "\xC9\x65\xA3\x51\x09\x04\x4C\xA3",
467 "\x8D\xA7\x0C\x88\x16\x7B\x27\x46",
469 "\x22\xBA\x92\xA2\x1A\x74\xEB\x5B",
471 "\x1F\xBA\x0F\xAB\x82\x3A\x85\xE7",
473 "\x65\x6F\x4F\xC9\x12\x45\x07\x3D",
475 "\xA8\x03\x44\x1F\xB9\x39\xF0\x9C",
477 "\xE3\xF3\x0B\xB6\xAE\xD6\x43\x31",
479 "\x6A\x75\x58\x8B\x5E\x6F\x5E\xA4",
481 "\xEC\x95\xAD\x55\xAC\x68\x4E\x93",
483 "\xB2\xA7\x9A\x0E\xBF\xB9\x6C\x4E",
485 "\x48\x02\x63\xBB\x61\x46\x00\x6F",
487 "\xC0\xD8\xB7\x11\x39\x5B\x29\x0F",
489 "\xA3\xF3\x91\x93\xFE\x3D\x52\x6D",
491 "\x6F\x50\xBA\x96\x4D\x94\xD1\x53",
493 "\xFF\x82\x40\xA7\x7C\x67\xBB\x8D",
495 "\x7F\x95\xC7\x2F\xD9\xB3\x8F\xF6",
497 "\x7F\xBD\xF1\x42\x8F\x44\xAA\xC1",
499 "\x04\xCE\xC2\x86\x48\x0A\xB9\x7B",
501 "\x86\x56\x29\x48\xC1\xCF\x8E\xC0",
503 "\xB1\xA1\xC0\xF2\x0C\x71\xB2\x67",
505 "\xF3\x57\xA2\x5C\x7D\xAC\xBC\xA8",
507 "\x8F\x8F\x4E\x0E\x34\x8B\xF1\x85",
509 "\x52\xA2\x1D\xF3\x5F\xA7\x01\x90",
511 "\x8B\xE7\x87\x33\x59\x4A\xF6\x16",
513 "\xE0\x3A\x05\x1B\x4C\xA8\x26\xE5",
515 "\x5C\x4B\x73\xBB\x59\x01\xC3\xCF",
517 "\xE5\xD7\xFC\x84\x15\xBF\xB0\xF0",
519 "\x94\x17\xD7\x24\x7E\xAA\x51\x59" }
520 #elif ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
526 "\x3D\x3D\x02\x89\xDA\xEC\x86\x7A\x29\xB3\xF2\xC7\xF1\x2C\x40\xE5",
527 "\x6F\xC8\xAE\x5C\xA6\x78\xE0\x42",
528 "\x80\x00\x00\x00\x00\x00\x00\x00",
536 #if ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
538 static void printVector(
const char *description,
const BYTE *data )
542 printf(
"%s = ", description );
543 for( i = 0; i < 8; i++ )
544 printf(
"%02x", data[ i ] );
548 static void printVectors(
const BYTE *key,
const BYTE *dt,
const BYTE *v,
549 const BYTE *r,
const int count )
551 printf(
"COUNT = %d\n", count );
552 printVector(
"Key1", key );
553 printVector(
"Key2", key + 8 );
554 printVector(
"DT", dt );
555 printVector(
"V", v );
556 printVector(
"R", r );
568 #if defined( INC_ALL )
608 memset( buffer, 0, 16 );
609 status = setKeyX917( testRandomInfo, key, key +
X917_KEYSIZE, NULL );
614 memcmp( buffer,
"\xF0\x8D\xD4\xDE\xFA\x2C\x80\x11",
X917_BLOCKSIZE ) )
619 memcmp( buffer,
"\xA0\xA9\x4E\xEC\xCD\xD9\x28\x7F",
X917_BLOCKSIZE ) )
624 memcmp( buffer,
"\x70\x82\x64\xED\x83\x88\x40\xE4",
X917_BLOCKSIZE ) )
636 #if !defined( CONFIG_SLOW_CPU )
652 initRandomPool( testRandomInfo );
654 status = setKeyX917( testRandomInfo, keyBuffer, x917MCTdata.V,
660 testRandomInfo->x917Count = 0;
664 #if ( RNG_TEST_VALUES != RNG_TEST_FIPSEVAL )
671 endRandomPool( testRandomInfo );
672 #if ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
673 printf(
"[X9.31]\n[2-Key TDES]\n\n" );
674 printVectors( x917MCTdata.key, x917MCTdata.DT, x917MCTdata.V, buffer, 0 );
675 printf(
"\n\n[X9.31]\n[2-Key TDES]\n\n" );
677 for( isX931 =
FALSE; isX931 <=
TRUE; isX931++ )
689 initRandomPool( testRandomInfo );
692 status = setKeyX917( testRandomInfo, keyBuffer, V, \
693 isX931 ? DT : NULL );
696 #if ( RNG_TEST_VALUES != RNG_TEST_FIPSEVAL )
701 endRandomPool( testRandomInfo );
704 #if ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )
707 printVectors( x917VSTdata.key, DT, V, buffer, i );
717 V[ j ] = ( V[ j ] >> 1 ) | 0x80;
719 V[ 0 ] = ( V[ 0 ] >> 1 ) | 0x80;
728 #if ( RNG_TEST_VALUES == RNG_TEST_FIPSEVAL )