diff options
author | Rob Landley <rob@landley.net> | 2019-02-23 16:43:06 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-23 16:43:06 -0600 |
commit | 38c3e0d0165f575203ec72fa1569d2e4791c2827 (patch) | |
tree | 14f51d44a4231b5df7c97ff4286c2db69b1695f1 /toys/pending | |
parent | 609c3e3cd3d83c02490ac26753bb78a63e0e48b5 (diff) | |
download | toybox-38c3e0d0165f575203ec72fa1569d2e4791c2827.tar.gz |
Cleanup mcookie.
Diffstat (limited to 'toys/pending')
-rw-r--r-- | toys/pending/mcookie.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/toys/pending/mcookie.c b/toys/pending/mcookie.c index 83cf0a91..12138b89 100644 --- a/toys/pending/mcookie.c +++ b/toys/pending/mcookie.c @@ -3,24 +3,20 @@ * Copyright 2019 AD Isaac Dunham <ibid.ag@gmail.com> * * No standard. - * util-linux mcookie originally found the md5sum of several files in /proc - * and reported that; more recent versions use the best random number source - * and find the md5sum, thus wasting entropy. - * We just ask the system for 128 bits and print it. - * * + * -f and -m are not supported: md5sums of arbitrary files are not a good + * source of entropy, just ask the system for 128 bits and print it. + USE_MCOOKIE(NEWTOY(mcookie, "v(verbose)V(version)", TOYFLAG_USR|TOYFLAG_BIN)) config MCOOKIE bool "mcookie" default n help - usage: mcookie [-v | -V] + usage: mcookie [-vV] + + Generate a 128-bit strong random number. - Generate a 128-bit random number from system sources. - -f and -m are not supported; md5 sums of arbitrary files are not a - good source of entropy - -h show help -v show entropy source (verbose) -V show version */ @@ -30,18 +26,10 @@ config MCOOKIE void mcookie_main(void) { - int i; - if (toys.optflags & FLAG_V) { - puts("mcookie from toybox"); - return; - } + long long *ll = (void *)toybuf; + + if (FLAG(V)) return (void)puts("mcookie from toybox"); xgetrandom(toybuf, 16, 0); - if (toys.optflags & FLAG_v) { - fputs("Got 16 bytes from xgetrandom()\n", stderr); - } - for (i = 0; i < 16; i++) { - sprintf(toybuf+16+2*i,"%02x", toybuf[i]); - } - toybuf[48] = '\0'; - puts(toybuf + 16); + if (FLAG(v)) fputs("Got 16 bytes from xgetrandom()\n", stderr); + xprintf("%016llx%06llx\n", ll[0], ll[1]); } |