From 2c148512bf02c9f04fc629188e3920be3d44f6d4 Mon Sep 17 00:00:00 2001 From: Simon Schmid Date: Sun, 27 Oct 2024 14:30:34 +0100 Subject: [PATCH] Improve entropy in password generation by reducing read size --- src/pw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pw b/src/pw index 6b9e547..28c607d 100755 --- a/src/pw +++ b/src/pw @@ -189,7 +189,7 @@ pw::gen() { local password="" class="${2:-"${PW_GEN_CLASS}"}" while (( "${#password}" != length )); do # alpine tr does not support [:graph:], use sed instead - password+=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | LC_CTYPE=C LC_ALL=C tr -d '\0[:space:]' | LC_CTYPE=C LC_ALL=C sed "s/[^${class}]//g" | head -c $(( length - ${#password} )) || true) + password+=$(dd if=/dev/urandom bs=$(( length / 64 + 1 )) count=1 2>/dev/null | LC_CTYPE=C LC_ALL=C tr -d '\0[:space:]' | LC_CTYPE=C LC_ALL=C sed "s/[^${class}]//g" | head -c $(( length - ${#password} ))) done pw::output "${password}" }