diff options
Diffstat (limited to 'src/lib/libssl/src/apps/rand.c')
| -rw-r--r-- | src/lib/libssl/src/apps/rand.c | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/src/lib/libssl/src/apps/rand.c b/src/lib/libssl/src/apps/rand.c index cfbba30755..f51f5bec35 100644 --- a/src/lib/libssl/src/apps/rand.c +++ b/src/lib/libssl/src/apps/rand.c | |||
| @@ -1,4 +1,57 @@ | |||
| 1 | /* apps/rand.c */ | 1 | /* apps/rand.c */ |
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 2 | 55 | ||
| 3 | #include "apps.h" | 56 | #include "apps.h" |
| 4 | 57 | ||
| @@ -23,6 +76,7 @@ int MAIN(int, char **); | |||
| 23 | 76 | ||
| 24 | int MAIN(int argc, char **argv) | 77 | int MAIN(int argc, char **argv) |
| 25 | { | 78 | { |
| 79 | ENGINE *e = NULL; | ||
| 26 | int i, r, ret = 1; | 80 | int i, r, ret = 1; |
| 27 | int badopt; | 81 | int badopt; |
| 28 | char *outfile = NULL; | 82 | char *outfile = NULL; |
| @@ -30,6 +84,7 @@ int MAIN(int argc, char **argv) | |||
| 30 | int base64 = 0; | 84 | int base64 = 0; |
| 31 | BIO *out = NULL; | 85 | BIO *out = NULL; |
| 32 | int num = -1; | 86 | int num = -1; |
| 87 | char *engine=NULL; | ||
| 33 | 88 | ||
| 34 | apps_startup(); | 89 | apps_startup(); |
| 35 | 90 | ||
| @@ -37,6 +92,9 @@ int MAIN(int argc, char **argv) | |||
| 37 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) | 92 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) |
| 38 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); | 93 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); |
| 39 | 94 | ||
| 95 | if (!load_config(bio_err, NULL)) | ||
| 96 | goto err; | ||
| 97 | |||
| 40 | badopt = 0; | 98 | badopt = 0; |
| 41 | i = 0; | 99 | i = 0; |
| 42 | while (!badopt && argv[++i] != NULL) | 100 | while (!badopt && argv[++i] != NULL) |
| @@ -48,6 +106,13 @@ int MAIN(int argc, char **argv) | |||
| 48 | else | 106 | else |
| 49 | badopt = 1; | 107 | badopt = 1; |
| 50 | } | 108 | } |
| 109 | else if (strcmp(argv[i], "-engine") == 0) | ||
| 110 | { | ||
| 111 | if ((argv[i+1] != NULL) && (engine == NULL)) | ||
| 112 | engine = argv[++i]; | ||
| 113 | else | ||
| 114 | badopt = 1; | ||
| 115 | } | ||
| 51 | else if (strcmp(argv[i], "-rand") == 0) | 116 | else if (strcmp(argv[i], "-rand") == 0) |
| 52 | { | 117 | { |
| 53 | if ((argv[i+1] != NULL) && (inrand == NULL)) | 118 | if ((argv[i+1] != NULL) && (inrand == NULL)) |
| @@ -62,7 +127,7 @@ int MAIN(int argc, char **argv) | |||
| 62 | else | 127 | else |
| 63 | badopt = 1; | 128 | badopt = 1; |
| 64 | } | 129 | } |
| 65 | else if (isdigit(argv[i][0])) | 130 | else if (isdigit((unsigned char)argv[i][0])) |
| 66 | { | 131 | { |
| 67 | if (num < 0) | 132 | if (num < 0) |
| 68 | { | 133 | { |
| @@ -84,12 +149,15 @@ int MAIN(int argc, char **argv) | |||
| 84 | { | 149 | { |
| 85 | BIO_printf(bio_err, "Usage: rand [options] num\n"); | 150 | BIO_printf(bio_err, "Usage: rand [options] num\n"); |
| 86 | BIO_printf(bio_err, "where options are\n"); | 151 | BIO_printf(bio_err, "where options are\n"); |
| 87 | BIO_printf(bio_err, "-out file - write to file\n"); | 152 | 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); | 153 | BIO_printf(bio_err, "-engine e - use engine e, possibly a hardware device.\n"); |
| 89 | BIO_printf(bio_err, "-base64 - encode output\n"); | 154 | BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
| 155 | BIO_printf(bio_err, "-base64 - encode output\n"); | ||
| 90 | goto err; | 156 | goto err; |
| 91 | } | 157 | } |
| 92 | 158 | ||
| 159 | e = setup_engine(bio_err, engine, 0); | ||
| 160 | |||
| 93 | app_RAND_load_file(NULL, bio_err, (inrand != NULL)); | 161 | app_RAND_load_file(NULL, bio_err, (inrand != NULL)); |
| 94 | if (inrand != NULL) | 162 | if (inrand != NULL) |
| 95 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 163 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", |
| @@ -101,7 +169,15 @@ int MAIN(int argc, char **argv) | |||
| 101 | if (outfile != NULL) | 169 | if (outfile != NULL) |
| 102 | r = BIO_write_filename(out, outfile); | 170 | r = BIO_write_filename(out, outfile); |
| 103 | else | 171 | else |
| 172 | { | ||
| 104 | r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); | 173 | r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); |
| 174 | #ifdef OPENSSL_SYS_VMS | ||
| 175 | { | ||
| 176 | BIO *tmpbio = BIO_new(BIO_f_linebuffer()); | ||
| 177 | out = BIO_push(tmpbio, out); | ||
| 178 | } | ||
| 179 | #endif | ||
| 180 | } | ||
| 105 | if (r <= 0) | 181 | if (r <= 0) |
| 106 | goto err; | 182 | goto err; |
| 107 | 183 | ||
| @@ -136,5 +212,6 @@ err: | |||
| 136 | ERR_print_errors(bio_err); | 212 | ERR_print_errors(bio_err); |
| 137 | if (out) | 213 | if (out) |
| 138 | BIO_free_all(out); | 214 | BIO_free_all(out); |
| 215 | apps_shutdown(); | ||
| 139 | EXIT(ret); | 216 | EXIT(ret); |
| 140 | } | 217 | } |
