summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormatthieu <>2006-05-14 08:56:25 +0000
committermatthieu <>2006-05-14 08:56:25 +0000
commit9870da15fd30b13454e96db10a86d21087122b81 (patch)
treebb8e1716cb7258f8ee95b9d8b5fa3c915ae31a54 /src
parent8aa67aa403ec677913310a5ed9cff716566323cf (diff)
downloadopenbsd-9870da15fd30b13454e96db10a86d21087122b81.tar.gz
openbsd-9870da15fd30b13454e96db10a86d21087122b81.tar.bz2
openbsd-9870da15fd30b13454e96db10a86d21087122b81.zip
Add a -hex option to 'rand' to output hexadecimal output.
ok djm@ miod@, man page help from jmc@.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/src/apps/rand.c21
-rw-r--r--src/usr.sbin/openssl/openssl.15
2 files changed, 24 insertions, 2 deletions
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 @@
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 - 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
@@ -161,6 +173,7 @@ int MAIN(int argc, char **argv)
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 - encode output\n");
176 BIO_printf(bio_err, "-hex - hex encode output\n");
164 goto err; 177 goto err;
165 } 178 }
166 179
@@ -210,7 +223,13 @@ 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 int i;
230 for (i = 0; i < chunk; i++)
231 BIO_printf(out, "%02x", buf[i]);
232 }
214 num -= chunk; 233 num -= chunk;
215 } 234 }
216 BIO_flush(out); 235 BIO_flush(out);
diff --git a/src/usr.sbin/openssl/openssl.1 b/src/usr.sbin/openssl/openssl.1
index 3453ef41f9..6b2a34d7ff 100644
--- a/src/usr.sbin/openssl/openssl.1
+++ b/src/usr.sbin/openssl/openssl.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: openssl.1,v 1.52 2005/11/27 13:12:00 jmc Exp $ 1.\" $OpenBSD: openssl.1,v 1.53 2006/05/14 08:56:25 matthieu Exp $
2.\" ==================================================================== 2.\" ====================================================================
3.\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3.\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4.\" 4.\"
@@ -4245,6 +4245,7 @@ $ openssl -in keycerts.pem -export -name "My PKCS#12 file" \e
4245.Cm openssl rand 4245.Cm openssl rand
4246.Op Fl base64 4246.Op Fl base64
4247.Op Fl engine Ar id 4247.Op Fl engine Ar id
4248.Op Fl hex
4248.Op Fl out Ar file 4249.Op Fl out Ar file
4249.Op Fl rand Ar file ... 4250.Op Fl rand Ar file ...
4250.Ar num 4251.Ar num
@@ -4285,6 +4286,8 @@ string) will cause
4285to attempt to obtain a functional reference to the specified engine, 4286to attempt to obtain a functional reference to the specified engine,
4286thus initialising it if needed. 4287thus initialising it if needed.
4287The engine will then be set as the default for all available algorithms. 4288The engine will then be set as the default for all available algorithms.
4289.It Fl hex
4290Specify hexadecimal output.
4288.It Fl out Ar file 4291.It Fl out Ar file
4289Write to 4292Write to
4290.Ar file 4293.Ar file