diff options
| author | matthieu <> | 2006-05-14 08:56:25 +0000 |
|---|---|---|
| committer | matthieu <> | 2006-05-14 08:56:25 +0000 |
| commit | 9870da15fd30b13454e96db10a86d21087122b81 (patch) | |
| tree | bb8e1716cb7258f8ee95b9d8b5fa3c915ae31a54 /src/lib | |
| parent | 8aa67aa403ec677913310a5ed9cff716566323cf (diff) | |
| download | openbsd-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/lib')
| -rw-r--r-- | src/lib/libssl/src/apps/rand.c | 21 |
1 files changed, 20 insertions, 1 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); |
