summaryrefslogtreecommitdiffstats
path: root/apps/genrsa.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>1999-10-26 01:56:29 +0000
committerBodo Möller <bodo@openssl.org>1999-10-26 01:56:29 +0000
commita31011e8e0ea18f1cc79d7eb53238768ae9369c6 (patch)
treeda6c9af95c39c6e6c44d2b71ace3bd4495728be1 /apps/genrsa.c
parent38899535f85784442395aeab921b25fc79266491 (diff)
Various randomness handling bugfixes and improvements --
some utilities that should have used RANDFILE did not, and -rand handling was broken except in genrsa.
Diffstat (limited to 'apps/genrsa.c')
-rw-r--r--apps/genrsa.c63
1 files changed, 8 insertions, 55 deletions
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 <sys/stat.h>
#include "apps.h"
#include <openssl/bio.h>
-#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
@@ -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