nettle-pbkdf2-test 634 Bytes
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3 4 5 6 7 8 9 10 11
#! /bin/sh

if [ -z "$srcdir" ] ; then
  srcdir=`pwd`
fi

test_pbkdf2 () {
    password="$1"
    salt="$2"
    iters="$3"
    expected="$4"
12 13 14
    # Relies on division rounding down; breaks if
    # $expected contains more than one space.
    length=`expr "$expected" : '.*' / 2`
Niels Möller's avatar
Niels Möller committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    printf "%s" "$password" | $EMULATOR ../tools/nettle-pbkdf2 \
	-i "$iters" -l "$length" "$salt" > test1.out
    echo "$expected" > test2.out

    if cmp test1.out test2.out ; then
	true
    else
	exit 1;
    fi
}

test_pbkdf2 passwd salt 1 "55ac046e56e3089f ec1691c22544b605"
test_pbkdf2 Password NaCl 80000 "4ddcd8f60b98be21 830cee5ef22701f9"

exit 0