From 9870da15fd30b13454e96db10a86d21087122b81 Mon Sep 17 00:00:00 2001 From: matthieu <> Date: Sun, 14 May 2006 08:56:25 +0000 Subject: Add a -hex option to 'rand' to output hexadecimal output. ok djm@ miod@, man page help from jmc@. --- src/lib/libssl/src/apps/rand.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/libssl/src/apps/rand.c b/src/lib/libssl/src/apps/rand.c index 63724bc730..e23e84af82 100644 --- a/src/lib/libssl/src/apps/rand.c +++ b/src/lib/libssl/src/apps/rand.c @@ -69,6 +69,7 @@ /* -out file - write to file * -rand file:file - PRNG seed files * -base64 - encode output + * -hex - hex encode output * num - write 'num' bytes */ @@ -84,6 +85,7 @@ int MAIN(int argc, char **argv) char *outfile = NULL; char *inrand = NULL; int base64 = 0; + int hex = 0; BIO *out = NULL; int num = -1; #ifndef OPENSSL_NO_ENGINE @@ -133,6 +135,13 @@ int MAIN(int argc, char **argv) else badopt = 1; } + else if (strcmp(argv[i], "-hex") == 0) + { + if (!hex) + hex = 1; + else + badopt = 1; + } else if (isdigit((unsigned char)argv[i][0])) { if (num < 0) @@ -148,6 +157,9 @@ int MAIN(int argc, char **argv) badopt = 1; } + if (hex && base64) + badopt = 1; + if (num < 0) badopt = 1; @@ -161,6 +173,7 @@ int MAIN(int argc, char **argv) #endif BIO_printf(bio_err, "-rand file%cfile%c... - seed PRNG from files\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); BIO_printf(bio_err, "-base64 - encode output\n"); + BIO_printf(bio_err, "-hex - hex encode output\n"); goto err; } @@ -210,7 +223,13 @@ int MAIN(int argc, char **argv) r = RAND_bytes(buf, chunk); if (r <= 0) goto err; - BIO_write(out, buf, chunk); + if (!hex) + BIO_write(out, buf, chunk); + else { + int i; + for (i = 0; i < chunk; i++) + BIO_printf(out, "%02x", buf[i]); + } num -= chunk; } BIO_flush(out); -- cgit v1.2.3-55-g6feb