cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
4758.c
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * IBM 4758 Randomness-Gathering Code *
4 * Copyright Peter Gutmann 1998-2002 *
5 * *
6 ****************************************************************************/
7 
8 /* This module is part of the cryptlib continuously seeded pseudorandom
9  number generator. For usage conditions, see random.c */
10 
11 /* General includes */
12 
13 #include <time.h>
14 #include "../crypt.h"
15 
16 /* OS-specific includes */
17 
18 #include "scc_int.h"
19 
20 /* The size of the returned random data and the number of calls we make for
21  a slow poll. Since the 4758 uses a hardware RNG, it doesn't matter if we
22  call it several times in succession */
23 
24 #define SCC_RANDOM_SIZE 8 /* 64 bits */
25 #define SCC_NO_CALLS 4 /* 256 bits total */
26 
27 void fastPoll( void )
28  {
31 
32  sccGetRandomNumber( buffer, RANDOM_RANDOM );
33  setResourceData( &msgData, buffer, SCC_RANDOM_SIZE );
35  &msgData, CRYPT_IATTRIBUTE_ENTROPY );
36  zeroise( buffer, SCC_RANDOM_SIZE );
37  }
38 
39 void slowPoll( void )
40  {
43  int quality = 100, i;
44 
45  for( i = 0; i < SCC_NO_CALLS; i++ )
46  sccGetRandomNumber( buffer + ( i * SCC_RANDOM_SIZE ), RANDOM_RANDOM );
47 
48  /* Add the data to the randomness pool */
49  setResourceData( &msgData, buffer, SCC_RANDOM_SIZE * SCC_NO_CALLS );
51  &msgData, CRYPT_IATTRIBUTE_ENTROPY );
52  zeroise( buffer, SCC_RANDOM_SIZE * SCC_NO_CALLS );
54  &quality, CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
55  }