diff options
Diffstat (limited to 'usergen')
| -rwxr-xr-x | usergen | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -7,6 +7,16 @@ usage() echo "$0 <dir>" } +to_hex() +{ + od -An -t x1 | tr -d ' ' +} + +to_bin() +{ + sed -e 's,\([0-9a-f]\{2\}\),\\\\\\x\1,g' | xargs printf +} + if [ $# != 1 ]; then usage >&2 exit 1 @@ -44,17 +54,17 @@ echo "Quota, in MiB (leave empty for unlimited quota):" >&2 read -r QUOTA QUOTA="$(printf '%d' "$QUOTA")" -PWD=$(printf '%s' "$PWD" | xxd -p | tr -d '\n') -SALT=$(openssl rand 32 | xxd -p | tr -d '\n') -KEY=$(openssl rand 32 | xxd -p | tr -d '\n') -PWD=$(printf '%s%s' $SALT "$PWD") +PWD=$(printf '%s' "$PWD" | to_hex) +SALT=$(openssl rand -hex 32) +KEY=$(openssl rand -hex 32) +PWD=$(printf '%s%s' "$SALT" "$PWD") ROUNDS=1000 for i in $(seq $ROUNDS) do printf "\r%d/$ROUNDS" $i >&2 - PWD=$(printf '%s' "$PWD" | xxd -p -r | sha256sum | cut -d' ' -f1) + PWD=$(printf '%s' "$PWD" | to_bin | sha256sum | cut -d' ' -f1) done echo >&2 |
