summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libssl/src/apps/rand.c21
-rw-r--r--usr.sbin/openssl/openssl.15
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/libssl/src/apps/rand.c b/lib/libssl/src/apps/rand.c
index 63724bc7302..e23e84af823 100644
--- a/lib/libssl/src/apps/rand.c
+++ b/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);
diff --git a/usr.sbin/openssl/openssl.1 b/usr.sbin/openssl/openssl.1
index 3453ef41f96..6b2a34d7ff0 100644
--- a/usr.sbin/openssl/openssl.1
+++ b/usr.sbin/openssl/openssl.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: openssl.1,v 1.52 2005/11/27 13:12:00 jmc Exp $
+.\" $OpenBSD: openssl.1,v 1.53 2006/05/14 08:56:25 matthieu Exp $
.\" ====================================================================
.\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
.\"
@@ -4245,6 +4245,7 @@ $ openssl -in keycerts.pem -export -name "My PKCS#12 file" \e
.Cm openssl rand
.Op Fl base64
.Op Fl engine Ar id
+.Op Fl hex
.Op Fl out Ar file
.Op Fl rand Ar file ...
.Ar num
@@ -4285,6 +4286,8 @@ string) will cause
to attempt to obtain a functional reference to the specified engine,
thus initialising it if needed.
The engine will then be set as the default for all available algorithms.
+.It Fl hex
+Specify hexadecimal output.
.It Fl out Ar file
Write to
.Ar file