Add password hash test for create command.
authorMilan Broz <gmazyland@gmail.com>
Fri, 10 Dec 2010 15:36:41 +0000 (15:36 +0000)
committerMilan Broz <gmazyland@gmail.com>
Fri, 10 Dec 2010 15:36:41 +0000 (15:36 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@401 36d66b0a-2a48-0410-832c-cd162a569da5

tests/Makefile.am
tests/password-hash-test [new file with mode: 0755]

index 324207e..5c08842 100644 (file)
@@ -1,6 +1,6 @@
-TESTS = api-test compat-test align-test mode-test
+TESTS = api-test compat-test align-test mode-test password-hash-test
 
-EXTRA_DIST = compatimage.img.bz2 align-test compat-test mode-test
+EXTRA_DIST = compatimage.img.bz2 align-test compat-test mode-test password-hash-test
 
 differ_SOURCES = differ.c
 differ_CFLAGS = -Wall -O2
diff --git a/tests/password-hash-test b/tests/password-hash-test
new file mode 100755 (executable)
index 0000000..dcb54c6
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+# check hash processing in create command
+
+CRYPTSETUP=../src/cryptsetup
+DEV_NAME=dmc_test
+KEY_FILE=keyfile
+
+DEV2=$DEV_NAME"_x"
+
+cleanup() {
+       [ -b /dev/mapper/$DEV2 ] && dmsetup remove $DEV2
+       udevadm settle 2>/dev/null 2>&1
+       [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
+       rm -f $KEY_FILE
+       exit $1
+}
+
+crypt_key() # hash keysize pwd/file name outkey
+{
+       DEV2=$DEV_NAME"_x"
+       MODE=aes-cbc-essiv:sha256
+       [ $2 -gt 256 ] && MODE=aes-xts-plain
+
+       case "$3" in
+       pwd)
+               echo -e -n "$4" | $CRYPTSETUP create -c $MODE -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+               ;;
+       stdin)
+               echo -e -n "$4" | $CRYPTSETUP create -c $MODE -d "-" -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+               ;;
+       file)
+               $CRYPTSETUP create -c $MODE -d $4 -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+               ;;
+       *)
+               fail
+               ;;
+       esac
+
+       VKEY=$(dmsetup table $DEV2 --showkeys 2>/dev/null | cut -d' '  -f 5)
+       echo -n "HASH: $1 KSIZE: $2 / $3"
+       if [ "$VKEY" != "$5" ] ; then
+               echo " [FAILED]"
+               echo "expected: $5"
+               echo "real key: $VKEY"
+               cleanup 100
+       fi
+       echo " [OK]"
+       dmsetup remove $DEV2
+}
+
+if [ $(id -u) != 0 ]; then
+       echo "WARNING: You must be root to run this test, test skipped."
+       exit 0
+fi
+
+dmsetup create $DEV_NAME --table "0 10240 zero" >/dev/null 2>&1
+
+crypt_key ripemd160   0 pwd "xxx" aeb26d1f69eb6dddfb9381eed4d7299f091e99aa5d3ff06866d4ce9f620f7aca
+crypt_key ripemd160 256 pwd "xxx" aeb26d1f69eb6dddfb9381eed4d7299f091e99aa5d3ff06866d4ce9f620f7aca
+crypt_key ripemd160 128 pwd "xxx" aeb26d1f69eb6dddfb9381eed4d7299f
+crypt_key sha1      256 pwd "xxx" b60d121b438a380c343d5ec3c2037564b82ffef30b1e0a6ad9af7a73aa91c197
+crypt_key sha1      128 pwd "xxx" b60d121b438a380c343d5ec3c2037564
+crypt_key sha256    256 pwd "xxx" cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860
+crypt_key sha256    128 pwd "xxx" cd2eb0837c9b4c962c22d2ff8b5441b7
+
+crypt_key ripemd160   0 stdin "xxx"   aeb26d1f69eb6dddfb9381eed4d7299f091e99aa5d3ff06866d4ce9f620f7aca
+crypt_key ripemd160 256 stdin "xxx\n" 625ce2a8dbdf08f1de400dba7ab9fab246f2a55ad6136e6cafd6703732dab8cf
+
+# with keyfile, hash is ignored
+crypt_key ripemd160 256 file /dev/zero 0000000000000000000000000000000000000000000000000000000000000000
+crypt_key sha256    256 file /dev/zero 0000000000000000000000000000000000000000000000000000000000000000
+
+# key file, 80 chars
+echo -n -e "0123456789abcdef\n\x01\x00\x03\xff\xff\r\xff\xff\n\r" \
+          "2352j3rkjhadcfasc823rqaw7e1 3dq sdq3d 2dkjqw3h2=====" >$KEY_FILE
+KEY_FILE_HEX="303132333435363738396162636465660a010003ffff0dffff0a0d20323335326a33726b6a686164636661736338323372716177376531203364712073647133"
+
+crypt_key ripemd160 256 file $KEY_FILE ${KEY_FILE_HEX:0:64}
+crypt_key sha256    256 file $KEY_FILE ${KEY_FILE_HEX:0:64}
+crypt_key sha256    128 file $KEY_FILE ${KEY_FILE_HEX:0:32}
+crypt_key sha256    512 file $KEY_FILE $KEY_FILE_HEX
+
+cleanup 0