Size of random output is now a long, also added option to select chunk size

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17949)
This commit is contained in:
Kevin K Biju 2022-03-23 10:40:50 +05:30 committed by Pauli
parent 0bcae9893b
commit 2aa645bca4
1 changed files with 8 additions and 7 deletions

View File

@ -52,7 +52,9 @@ int rand_main(int argc, char **argv)
BIO *out = NULL;
char *outfile = NULL, *prog;
OPTION_CHOICE o;
int format = FORMAT_BINARY, i, num = -1, r, ret = 1;
int format = FORMAT_BINARY, r, i, ret = 1, buflen = 131072;
long num = -1;
uint8_t *buf = NULL;
prog = opt_init(argc, argv, rand_options);
while ((o = opt_next()) != OPT_EOF) {
@ -93,7 +95,7 @@ int rand_main(int argc, char **argv)
argc = opt_num_rest();
argv = opt_rest();
if (argc == 1) {
if (!opt_int(argv[0], &num) || num <= 0)
if (!opt_long(argv[0], &num) || num <= 0)
goto opthelp;
} else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
@ -113,13 +115,11 @@ int rand_main(int argc, char **argv)
out = BIO_push(b64, out);
}
buf = app_malloc(buflen, "buffer for output file");
while (num > 0) {
unsigned char buf[4096];
int chunk;
long chunk;
chunk = num;
if (chunk > (int)sizeof(buf))
chunk = sizeof(buf);
chunk = (num > buflen) ? buflen : num;
r = RAND_bytes(buf, chunk);
if (r <= 0)
goto end;
@ -143,6 +143,7 @@ int rand_main(int argc, char **argv)
end:
if (ret != 0)
ERR_print_errors(bio_err);
OPENSSL_free(buf);
release_engine(e);
BIO_free_all(out);
return ret;