X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Fgenrsa.c;h=96df5703c482e4d1b5b4f7f282286d957cb58973;hp=67382065fb9905dd09ff1a2aea5a0025fbfb82d5;hb=a31011e8e0ea18f1cc79d7eb53238768ae9369c6;hpb=74678cc2f8132ad34f7c33731c4765cf3083de8c diff --git a/apps/genrsa.c b/apps/genrsa.c index 67382065fb..96df5703c4 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -63,7 +63,6 @@ #include #include "apps.h" #include -#include #include #include #include @@ -76,18 +75,16 @@ #define PROG genrsa_main static void MS_CALLBACK genrsa_cb(int p, int n, void *arg); -static long gr_load_rand(char *names); int MAIN(int argc, char **argv) { int ret=1; - char buffer[200]; RSA *rsa=NULL; int i,num=DEFBITS; - long rnum=0,l; + long l; EVP_CIPHER *enc=NULL; unsigned long f4=RSA_F4; char *outfile=NULL; - char *inrand=NULL,*randfile; + char *inrand=NULL; BIO *out=NULL; apps_startup(); @@ -165,41 +162,19 @@ bad: } } -#ifdef WINDOWS - BIO_printf(bio_err,"Loading 'screen' into random state -"); - BIO_flush(bio_err); - RAND_screen(); - BIO_printf(bio_err," done\n"); -#endif - randfile=RAND_file_name(buffer,200); - if ((randfile == NULL) || - !(rnum=(long)RAND_load_file(randfile,1024L*1024L))) - { - BIO_printf(bio_err,"unable to load 'random state'\n"); - } - - if (inrand == NULL) - { - if (rnum == 0) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } - } - else + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { - rnum+=gr_load_rand(inrand); + BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); } - if (rnum != 0) - BIO_printf(bio_err,"%ld semi-random bytes loaded\n",rnum); + if (inrand != NULL) + BIO_printf(bio_err,"%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", num); rsa=RSA_generate_key(num,f4,genrsa_cb,bio_err); - if (randfile == NULL) - BIO_printf(bio_err,"unable to write 'random state'\n"); - else - RAND_write_file(randfile); + app_RAND_write_file(NULL, bio_err); if (rsa == NULL) goto err; @@ -241,26 +216,4 @@ static void MS_CALLBACK genrsa_cb(int p, int n, void *arg) p=n; #endif } - -static long gr_load_rand(char *name) - { - char *p,*n; - int last; - long tot=0; - - for (;;) - { - last=0; - for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); - if (*p == '\0') last=1; - *p='\0'; - n=name; - name=p+1; - if (*n == '\0') break; - - tot+=RAND_load_file(n,1024L*1024L); - if (last) break; - } - return(tot); - } #endif