Main Page | Class List | Directories | File List | Class Members | File Members

app_rand.c File Reference

#include "apps.h"
#include <openssl/bio.h>
#include <openssl/rand.h>

Go to the source code of this file.

Defines

#define NON_MAIN

Functions

int app_RAND_load_file (const char *file, BIO *bio_e, int dont_warn)
long app_RAND_load_files (char *name)
int app_RAND_write_file (const char *file, BIO *bio_e)
void app_RAND_allow_write_file (void)

Variables

static int seeded = 0
static int egdsocket = 0


Define Documentation

#define NON_MAIN
 

Definition at line 112 of file app_rand.c.


Function Documentation

void app_RAND_allow_write_file void   ) 
 

Definition at line 215 of file app_rand.c.

References seeded.

Referenced by app_RAND_load_files().

00216         {
00217         seeded = 1;
00218         }

int app_RAND_load_file const char *  file,
BIO bio_e,
int  dont_warn
 

Definition at line 122 of file app_rand.c.

References BIO_flush, BIO_printf(), egdsocket, RAND_egd(), RAND_file_name(), RAND_load_file(), RAND_status(), and seeded.

Referenced by MAIN().

00123         {
00124         int consider_randfile = (file == NULL);
00125         char buffer[200];
00126         
00127 #ifdef OPENSSL_SYS_WINDOWS
00128         BIO_printf(bio_e,"Loading 'screen' into random state -");
00129         BIO_flush(bio_e);
00130         RAND_screen();
00131         BIO_printf(bio_e," done\n");
00132 #endif
00133 
00134         if (file == NULL)
00135                 file = RAND_file_name(buffer, sizeof buffer);
00136         else if (RAND_egd(file) > 0)
00137                 {
00138                 /* we try if the given filename is an EGD socket.
00139                    if it is, we don't write anything back to the file. */
00140                 egdsocket = 1;
00141                 return 1;
00142                 }
00143         if (file == NULL || !RAND_load_file(file, -1))
00144                 {
00145                 if (RAND_status() == 0)
00146                         {
00147                         if (!dont_warn)
00148                                 {
00149                                 BIO_printf(bio_e,"unable to load 'random state'\n");
00150                                 BIO_printf(bio_e,"This means that the random number generator has not been seeded\n");
00151                                 BIO_printf(bio_e,"with much random data.\n");
00152                                 if (consider_randfile) /* explanation does not apply when a file is explicitly named */
00153                                         {
00154                                         BIO_printf(bio_e,"Consider setting the RANDFILE environment variable to point at a file that\n");
00155                                         BIO_printf(bio_e,"'random' data can be kept in (the file will be overwritten).\n");
00156                                         }
00157                                 }
00158                         return 0;
00159                         }
00160                 }
00161         seeded = 1;
00162         return 1;
00163         }

long app_RAND_load_files char *  name  ) 
 

Definition at line 165 of file app_rand.c.

References app_RAND_allow_write_file(), LIST_SEPARATOR_CHAR, p, RAND_egd(), and RAND_load_file().

Referenced by MAIN().

00166         {
00167         char *p,*n;
00168         int last;
00169         long tot=0;
00170         int egd;
00171         
00172         for (;;)
00173                 {
00174                 last=0;
00175                 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++);
00176                 if (*p == '\0') last=1;
00177                 *p='\0';
00178                 n=name;
00179                 name=p+1;
00180                 if (*n == '\0') break;
00181 
00182                 egd=RAND_egd(n);
00183                 if (egd > 0)
00184                         tot+=egd;
00185                 else
00186                         tot+=RAND_load_file(n,-1);
00187                 if (last) break;
00188                 }
00189         if (tot > 512)
00190                 app_RAND_allow_write_file();
00191         return(tot);
00192         }

int app_RAND_write_file const char *  file,
BIO bio_e
 

Definition at line 194 of file app_rand.c.

References BIO_printf(), egdsocket, RAND_file_name(), RAND_write_file(), and seeded.

00195         {
00196         char buffer[200];
00197         
00198         if (egdsocket || !seeded)
00199                 /* If we did not manage to read the seed file,
00200                  * we should not write a low-entropy seed file back --
00201                  * it would suppress a crucial warning the next time
00202                  * we want to use it. */
00203                 return 0;
00204 
00205         if (file == NULL)
00206                 file = RAND_file_name(buffer, sizeof buffer);
00207         if (file == NULL || !RAND_write_file(file))
00208                 {
00209                 BIO_printf(bio_e,"unable to write 'random state'\n");
00210                 return 0;
00211                 }
00212         return 1;
00213         }


Variable Documentation

int egdsocket = 0 [static]
 

Definition at line 120 of file app_rand.c.

Referenced by app_RAND_load_file(), app_RAND_write_file(), and RAND_poll().

int seeded = 0 [static]
 

Definition at line 119 of file app_rand.c.

Referenced by app_RAND_allow_write_file(), app_RAND_load_file(), app_RAND_write_file(), and WndProc().


© sourcejam.com 2005-2008