Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: [...@mindrot.org - Fr. 30. Jan. 2009, 11:52:17]: This patch adds a -hex option to the rand app. E.g. $ openssl rand -hex 8 d203552d5eb39e76 What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: [...@mindrot.org - Fr. 30. Jan. 2009, 11:52:17]: This patch adds a -hex option to the rand app. E.g. $ openssl rand -hex 8 d203552d5eb39e76 What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. So ... I was going to add the newline while working on the patch, but then it occurred to me as you said this comes from OpenBSD CVS I might be breaking something there. No risk then? Bodo __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. So ... I was going to add the newline while working on the patch, but then it occurred to me as you said this comes from OpenBSD CVS I might be breaking something there. No risk then? Bodo __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. So ... I was going to add the newline while working on the patch, but then it occurred to me as you said this comes from OpenBSD CVS I might be breaking something there. No risk then? we'll cope ;) -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: What is the rationale of not having a newline at the end? It's text, after all? no rationale, just an oversight. So ... I was going to add the newline while working on the patch, but then it occurred to me as you said this comes from OpenBSD CVS I might be breaking something there. No risk then? we'll cope ;) -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
we'll cope ;) Here's my version of the patch. Let me know if it looks OK for you. Bodo Index: CHANGES === RCS file: /e/openssl/cvs/openssl/CHANGES,v retrieving revision 1.1468 diff -u -r1.1468 CHANGES --- CHANGES 28 Jan 2009 12:54:51 - 1.1468 +++ CHANGES 1 Feb 2009 17:48:03 - @@ -745,6 +745,9 @@ Changes between 0.9.8j and 0.9.8k [xx XXX ] + *) New -hex option for openssl rand. + [Matthieu Herrb] + *) Print out UTF8String and NumericString when parsing ASN1. [Steve Henson] Index: apps/rand.c === RCS file: /e/openssl/cvs/openssl/apps/rand.c,v retrieving revision 1.20 diff -u -r1.20 rand.c --- apps/rand.c 12 Aug 2007 17:44:27 - 1.20 +++ apps/rand.c 1 Feb 2009 17:48:05 - @@ -68,7 +68,8 @@ /* -out file - write to file * -rand file:file - PRNG seed files - * -base64 - encode output + * -base64 - base64 encode output + * -hex - hex encode output * num - write 'num' bytes */ @@ -84,6 +85,7 @@ 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 @@ 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 @@ badopt = 1; } + if (hex base64) + badopt = 1; + if (num 0) badopt = 1; @@ -160,7 +172,8 @@ BIO_printf(bio_err, -engine e - use engine e, possibly a hardware device.\n); #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, -base64 - base64 encode output\n); + BIO_printf(bio_err, -hex - hex encode output\n); goto err; } @@ -210,7 +223,14 @@ r = RAND_bytes(buf, chunk); if (r = 0) goto err; - BIO_write(out, buf, chunk); + if (!hex) + BIO_write(out, buf, chunk); + else + { + for (i = 0; i chunk; i++) + BIO_printf(out, %02x, buf[i]); + BIO_puts(out, \n); + } num -= chunk; } (void)BIO_flush(out); Index: doc/apps/rand.pod === RCS file: /e/openssl/cvs/openssl/doc/apps/rand.pod,v retrieving revision 1.5 diff -u -r1.5 rand.pod --- doc/apps/rand.pod 7 Sep 2001 06:13:26 - 1.5 +++ doc/apps/rand.pod 1 Feb 2009 17:48:15 - @@ -10,6 +10,7 @@ [B-out Ifile] [B-rand Ifile(s)] [B-base64] +[B-hex] Inum =head1 DESCRIPTION @@ -41,6 +42,10 @@ Perform base64 encoding on the output. +=item B-hex + +Show the output as a hex string. + =back =head1 SEE ALSO __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: we'll cope ;) Here's my version of the patch. Let me know if it looks OK for you. looks good to me -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
Re: [openssl.org #1831] PATCH: openssl rand -hex
On Sun, 1 Feb 2009, Bodo Moeller via RT wrote: we'll cope ;) Here's my version of the patch. Let me know if it looks OK for you. looks good to me -d __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
[openssl.org #1831] PATCH: openssl rand -hex
[...@mindrot.org - Fr. 30. Jan. 2009, 11:52:17]: This patch adds a -hex option to the rand app. E.g. $ openssl rand -hex 8 d203552d5eb39e76 What is the rationale of not having a newline at the end? It's text, after all? Bodo __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org
[openssl.org #1831] PATCH: openssl rand -hex
Hi, This patch adds a -hex option to the rand app. E.g. $ openssl rand -hex 8 d203552d5eb39e76 Patch is from Matthieu Herrb (matth...@openbsd.org) via OpenBSD CVS. -d Index: apps/rand.c === RCS file: /cvs/src/lib/libssl/src/apps/rand.c,v retrieving revision 1.1.1.3 retrieving revision 1.6 diff -u -p -r1.1.1.3 -r1.6 --- apps/rand.c 6 Sep 2008 12:15:38 - 1.1.1.3 +++ apps/rand.c 6 Sep 2008 12:17:47 - 1.6 @@ -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; } (void)BIO_flush(out); __ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majord...@openssl.org