From 19e44ac2ec9d4245353de5e770b15a8653cbc5fb Mon Sep 17 00:00:00 2001 From: Marco d'Itri Date: Sun, 9 Sep 2018 01:17:10 +0200 Subject: [PATCH] mkpasswd: let crypt_gensalt collect entropy by itself Let crypt_gensalt(3) collect entropy by itself instead of having mkpasswd provide it. This is supported by the libxcrypt implementation of crypt_gensalt(3). --- mkpasswd.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mkpasswd.c b/mkpasswd.c index 558624c..743c269 100644 --- a/mkpasswd.c +++ b/mkpasswd.c @@ -294,7 +294,8 @@ int main(int argc, char *argv[]) perror("crypt_gensalt"); exit(2); } - free(entropy); + if (entropy) + free(entropy); #else unsigned int salt_len = salt_maxlen; @@ -360,9 +361,21 @@ int main(int argc, char *argv[]) exit(0); } -#if defined RANDOM_DEVICE || defined HAVE_ARC4RANDOM_BUF || defined HAVE_GETENTROPY +#ifdef CRYPT_GENSALT_IMPLEMENTS_AUTO_ENTROPY -void* get_random_bytes(const unsigned int count) +/* + * If NULL is passed to the libxcrypt version of crypt_gensalt() instead of + * the buffer of random bytes then the function will obtain by itself the + * required randomness. + */ +inline void *get_random_bytes(const unsigned int count) +{ + return NULL; +} + +#elif defined RANDOM_DEVICE || defined HAVE_ARC4RANDOM_BUF || defined HAVE_GETENTROPY + +void *get_random_bytes(const unsigned int count) { char *buf = NOFAIL(malloc(count));