libscrypt now generates salt correctly,
indeed using the very method currently used by lua-scrypt.[1]
[1]:
https://sources.debian.net/src/libscrypt/1.21-3/crypto-scrypt-saltgen.c/
---
luascrypt.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/luascrypt.c b/luascrypt.c
index 181f1e8..85ae01c 100644
--- a/luascrypt.c
+++ b/luascrypt.c
@@ -22,26 +22,6 @@
#include "base64.h"
-static void
-luascrypt_salt_gen(char *salt, int saltlen)
-{
- int fd;
- /* We'd go with libscrypt's implementation, but since libscrypt's salt
- * generation is time based, we cannot fully trust it to generate
- * unique salts so to improve our chances we assume we have urandom
- * and fall back to libscrypt's implementation if we don't. Since the
- * libscrypt implementation is fast, call it, and then overwrite it
- * if we can...
- */
- libscrypt_salt_gen(salt, saltlen);
-
- fd = open("/dev/urandom", O_RDONLY);
- if (fd >= 0) {
- read(fd, salt, saltlen); /* Ignore errors in these two calls */
- close(fd); /* Since we have our fallback. */
- }
-}
-
static int
luascrypt_hash_password(lua_State *L)
{
@@ -71,7 +51,7 @@ luascrypt_hash_password(lua_State *L)
"N is too large (limited to 2^15)");
}
- luascrypt_salt_gen(salt, sizeof(salt));
+ libscrypt_salt_gen((uint8_t *) salt, sizeof(salt));
if (libscrypt_scrypt((uint8_t*)passwd, passwd_len,
(uint8_t*)salt, sizeof(salt),
--
2.13.0