diff options
Diffstat (limited to 'src/lib/libssl/src/apps/rand.c')
| -rw-r--r-- | src/lib/libssl/src/apps/rand.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/lib/libssl/src/apps/rand.c b/src/lib/libssl/src/apps/rand.c index cfbba30755..6add7bbd6c 100644 --- a/src/lib/libssl/src/apps/rand.c +++ b/src/lib/libssl/src/apps/rand.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <openssl/bio.h> | 9 | #include <openssl/bio.h> |
| 10 | #include <openssl/err.h> | 10 | #include <openssl/err.h> |
| 11 | #include <openssl/rand.h> | 11 | #include <openssl/rand.h> |
| 12 | #include <openssl/engine.h> | ||
| 12 | 13 | ||
| 13 | #undef PROG | 14 | #undef PROG |
| 14 | #define PROG rand_main | 15 | #define PROG rand_main |
| @@ -23,6 +24,7 @@ int MAIN(int, char **); | |||
| 23 | 24 | ||
| 24 | int MAIN(int argc, char **argv) | 25 | int MAIN(int argc, char **argv) |
| 25 | { | 26 | { |
| 27 | ENGINE *e = NULL; | ||
| 26 | int i, r, ret = 1; | 28 | int i, r, ret = 1; |
| 27 | int badopt; | 29 | int badopt; |
| 28 | char *outfile = NULL; | 30 | char *outfile = NULL; |
| @@ -30,6 +32,7 @@ int MAIN(int argc, char **argv) | |||
| 30 | int base64 = 0; | 32 | int base64 = 0; |
| 31 | BIO *out = NULL; | 33 | BIO *out = NULL; |
| 32 | int num = -1; | 34 | int num = -1; |
| 35 | char *engine=NULL; | ||
| 33 | 36 | ||
| 34 | apps_startup(); | 37 | apps_startup(); |
| 35 | 38 | ||
| @@ -48,6 +51,13 @@ int MAIN(int argc, char **argv) | |||
| 48 | else | 51 | else |
| 49 | badopt = 1; | 52 | badopt = 1; |
| 50 | } | 53 | } |
| 54 | if (strcmp(argv[i], "-engine") == 0) | ||
| 55 | { | ||
| 56 | if ((argv[i+1] != NULL) && (engine == NULL)) | ||
| 57 | engine = argv[++i]; | ||
| 58 | else | ||
| 59 | badopt = 1; | ||
| 60 | } | ||
| 51 | else if (strcmp(argv[i], "-rand") == 0) | 61 | else if (strcmp(argv[i], "-rand") == 0) |
| 52 | { | 62 | { |
| 53 | if ((argv[i+1] != NULL) && (inrand == NULL)) | 63 | if ((argv[i+1] != NULL) && (inrand == NULL)) |
| @@ -62,7 +72,7 @@ int MAIN(int argc, char **argv) | |||
| 62 | else | 72 | else |
| 63 | badopt = 1; | 73 | badopt = 1; |
| 64 | } | 74 | } |
| 65 | else if (isdigit(argv[i][0])) | 75 | else if (isdigit((unsigned char)argv[i][0])) |
| 66 | { | 76 | { |
| 67 | if (num < 0) | 77 | if (num < 0) |
| 68 | { | 78 | { |
| @@ -84,12 +94,31 @@ int MAIN(int argc, char **argv) | |||
| 84 | { | 94 | { |
| 85 | BIO_printf(bio_err, "Usage: rand [options] num\n"); | 95 | BIO_printf(bio_err, "Usage: rand [options] num\n"); |
| 86 | BIO_printf(bio_err, "where options are\n"); | 96 | BIO_printf(bio_err, "where options are\n"); |
| 87 | BIO_printf(bio_err, "-out file - write to file\n"); | 97 | BIO_printf(bio_err, "-out file - write to file\n"); |
| 88 | BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); | 98 | BIO_printf(bio_err," -engine e - use engine e, possibly a hardware device.\n"); |
| 89 | BIO_printf(bio_err, "-base64 - encode output\n"); | 99 | BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
| 100 | BIO_printf(bio_err, "-base64 - encode output\n"); | ||
| 90 | goto err; | 101 | goto err; |
| 91 | } | 102 | } |
| 92 | 103 | ||
| 104 | if (engine != NULL) | ||
| 105 | { | ||
| 106 | if((e = ENGINE_by_id(engine)) == NULL) | ||
| 107 | { | ||
| 108 | BIO_printf(bio_err,"invalid engine \"%s\"\n", | ||
| 109 | engine); | ||
| 110 | goto err; | ||
| 111 | } | ||
| 112 | if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) | ||
| 113 | { | ||
| 114 | BIO_printf(bio_err,"can't use that engine\n"); | ||
| 115 | goto err; | ||
| 116 | } | ||
| 117 | BIO_printf(bio_err,"engine \"%s\" set.\n", engine); | ||
| 118 | /* Free our "structural" reference. */ | ||
| 119 | ENGINE_free(e); | ||
| 120 | } | ||
| 121 | |||
| 93 | app_RAND_load_file(NULL, bio_err, (inrand != NULL)); | 122 | app_RAND_load_file(NULL, bio_err, (inrand != NULL)); |
| 94 | if (inrand != NULL) | 123 | if (inrand != NULL) |
| 95 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 124 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", |
| @@ -101,7 +130,15 @@ int MAIN(int argc, char **argv) | |||
| 101 | if (outfile != NULL) | 130 | if (outfile != NULL) |
| 102 | r = BIO_write_filename(out, outfile); | 131 | r = BIO_write_filename(out, outfile); |
| 103 | else | 132 | else |
| 133 | { | ||
| 104 | r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); | 134 | r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); |
| 135 | #ifdef VMS | ||
| 136 | { | ||
| 137 | BIO *tmpbio = BIO_new(BIO_f_linebuffer()); | ||
| 138 | out = BIO_push(tmpbio, out); | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | } | ||
| 105 | if (r <= 0) | 142 | if (r <= 0) |
| 106 | goto err; | 143 | goto err; |
| 107 | 144 | ||
