cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
mvs.c
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * MVS Randomness-Gathering Code *
4 * Copyright Peter Gutmann 1999-2003 *
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 <sys/times.h>
14 #include <sys/resource.h>
15 #include "crypt.h"
16 
17 /* Define the MVS assembler module used to gather random data */
18 
19 #pragma linkage( MVSENT, OS )
20 #pragma map( readRandom, "MVSENT" )
21 int readRandom( int length, unsigned char *buffer );
22 
23 /* The size of the intermediate buffer used to accumulate polled data */
24 
25 #define RANDOM_BUFSIZE 512
26 
27 /* Slow and fast polling routines. There really isn't much that we can
28  get under MVS, and we have to be careful how much we do with readRandom()
29  since it can become quite resource-intensive on some systems so we can't
30  call it from fastPoll() and only get a small amount of data with a slow
31  poll */
32 
33 void fastPoll( void )
34  {
36  hreport_t heapReport;
37  const clock_t timeStamp = clock();
38  int quality = 5;
39 
40  /* There really isn't much available under MVS, it would be nice if we
41  could get output from DISPLAY but this requires a level of plumbing
42  that isn't easily managed from C */
43  setMessageData( &msgData, &timeStamp, sizeof( clock_t ) );
45  &msgData, CRYPT_IATTRIBUTE_ENTROPY );
46  if( __heaprpt( &heapReport ) != -1 )
47  {
48  setMessageData( &msgData, &heapReport, sizeof( hreport_t ) );
50  &msgData, CRYPT_IATTRIBUTE_ENTROPY );
51  }
53  &quality, CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
54  }
55 
56 void slowPoll( void )
57  {
60  int quality = 95, status;
61 
62  status = readRandom( RANDOM_BUFSIZE, buffer );
63  assert( status == 0 );
64  setMessageData( &msgData, buffer, RANDOM_BUFSIZE );
66  CRYPT_IATTRIBUTE_ENTROPY );
67  zeroise( buffer, sizeof( buffer ) );
68  if( status == 0 )
70  &quality, CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
71  }