diff options
Diffstat (limited to 'src/lib/libssl/src/apps/rand.c')
| -rw-r--r-- | src/lib/libssl/src/apps/rand.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/lib/libssl/src/apps/rand.c b/src/lib/libssl/src/apps/rand.c index c3b26c466d..44a1d46a03 100644 --- a/src/lib/libssl/src/apps/rand.c +++ b/src/lib/libssl/src/apps/rand.c | |||
| @@ -68,7 +68,8 @@ | |||
| 68 | 68 | ||
| 69 | /* -out file - write to file | 69 | /* -out file - write to file |
| 70 | * -rand file:file - PRNG seed files | 70 | * -rand file:file - PRNG seed files |
| 71 | * -base64 - encode output | 71 | * -base64 - base64 encode output |
| 72 | * -hex - hex encode output | ||
| 72 | * num - write 'num' bytes | 73 | * num - write 'num' bytes |
| 73 | */ | 74 | */ |
| 74 | 75 | ||
| @@ -84,6 +85,7 @@ int MAIN(int argc, char **argv) | |||
| 84 | char *outfile = NULL; | 85 | char *outfile = NULL; |
| 85 | char *inrand = NULL; | 86 | char *inrand = NULL; |
| 86 | int base64 = 0; | 87 | int base64 = 0; |
| 88 | int hex = 0; | ||
| 87 | BIO *out = NULL; | 89 | BIO *out = NULL; |
| 88 | int num = -1; | 90 | int num = -1; |
| 89 | #ifndef OPENSSL_NO_ENGINE | 91 | #ifndef OPENSSL_NO_ENGINE |
| @@ -133,6 +135,13 @@ int MAIN(int argc, char **argv) | |||
| 133 | else | 135 | else |
| 134 | badopt = 1; | 136 | badopt = 1; |
| 135 | } | 137 | } |
| 138 | else if (strcmp(argv[i], "-hex") == 0) | ||
| 139 | { | ||
| 140 | if (!hex) | ||
| 141 | hex = 1; | ||
| 142 | else | ||
| 143 | badopt = 1; | ||
| 144 | } | ||
| 136 | else if (isdigit((unsigned char)argv[i][0])) | 145 | else if (isdigit((unsigned char)argv[i][0])) |
| 137 | { | 146 | { |
| 138 | if (num < 0) | 147 | if (num < 0) |
| @@ -148,6 +157,9 @@ int MAIN(int argc, char **argv) | |||
| 148 | badopt = 1; | 157 | badopt = 1; |
| 149 | } | 158 | } |
| 150 | 159 | ||
| 160 | if (hex && base64) | ||
| 161 | badopt = 1; | ||
| 162 | |||
| 151 | if (num < 0) | 163 | if (num < 0) |
| 152 | badopt = 1; | 164 | badopt = 1; |
| 153 | 165 | ||
| @@ -160,7 +172,8 @@ int MAIN(int argc, char **argv) | |||
| 160 | BIO_printf(bio_err, "-engine e - use engine e, possibly a hardware device.\n"); | 172 | BIO_printf(bio_err, "-engine e - use engine e, possibly a hardware device.\n"); |
| 161 | #endif | 173 | #endif |
| 162 | BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); | 174 | BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
| 163 | BIO_printf(bio_err, "-base64 - encode output\n"); | 175 | BIO_printf(bio_err, "-base64 - base64 encode output\n"); |
| 176 | BIO_printf(bio_err, "-hex - hex encode output\n"); | ||
| 164 | goto err; | 177 | goto err; |
| 165 | } | 178 | } |
| 166 | 179 | ||
| @@ -210,9 +223,17 @@ int MAIN(int argc, char **argv) | |||
| 210 | r = RAND_bytes(buf, chunk); | 223 | r = RAND_bytes(buf, chunk); |
| 211 | if (r <= 0) | 224 | if (r <= 0) |
| 212 | goto err; | 225 | goto err; |
| 213 | BIO_write(out, buf, chunk); | 226 | if (!hex) |
| 227 | BIO_write(out, buf, chunk); | ||
| 228 | else | ||
| 229 | { | ||
| 230 | for (i = 0; i < chunk; i++) | ||
| 231 | BIO_printf(out, "%02x", buf[i]); | ||
| 232 | } | ||
| 214 | num -= chunk; | 233 | num -= chunk; |
| 215 | } | 234 | } |
| 235 | if (hex) | ||
| 236 | BIO_puts(out, "\n"); | ||
| 216 | (void)BIO_flush(out); | 237 | (void)BIO_flush(out); |
| 217 | 238 | ||
| 218 | app_RAND_write_file(NULL, bio_err); | 239 | app_RAND_write_file(NULL, bio_err); |
