X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Fgenrsa.c;h=96df5703c482e4d1b5b4f7f282286d957cb58973;hp=cdba6189ad6493323459d36fc2e39e5957494927;hb=a31011e8e0ea18f1cc79d7eb53238768ae9369c6;hpb=78414a6a897db42c9bcf06aa21c705811ab33921;ds=sidebyside diff --git a/apps/genrsa.c b/apps/genrsa.c index cdba6189ad..96df5703c4 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -56,45 +56,35 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include #include #include #include "apps.h" -#include "bio.h" -#include "rand.h" -#include "err.h" -#include "bn.h" -#include "rsa.h" -#include "evp.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include +#include #define DEFBITS 512 #undef PROG #define PROG genrsa_main -#ifndef NOPROTO -static void MS_CALLBACK genrsa_cb(int p, int n, char *arg); -static long gr_load_rand(char *names); -#else -static void MS_CALLBACK genrsa_cb(); -static long gr_load_rand(); -#endif - -int MAIN(argc, argv) -int argc; -char **argv; +static void MS_CALLBACK genrsa_cb(int p, int n, void *arg); +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(); @@ -172,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 (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { - if (rnum == 0) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } - } - else - { - 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,(char *)bio_err); + 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; @@ -222,7 +190,7 @@ bad: l+=rsa->e->d[i]; } BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l); - if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL)) + if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL,NULL)) goto err; ret=0; @@ -234,10 +202,7 @@ err: EXIT(ret); } -static void MS_CALLBACK genrsa_cb(p, n, arg) -int p; -int n; -char *arg; +static void MS_CALLBACK genrsa_cb(int p, int n, void *arg) { char c='*'; @@ -246,33 +211,9 @@ char *arg; if (p == 2) c='*'; if (p == 3) c='\n'; BIO_write((BIO *)arg,&c,1); - BIO_flush((BIO *)arg); + (void)BIO_flush((BIO *)arg); #ifdef LINT p=n; #endif } - -static long gr_load_rand(name) -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