From e8e805dfd3fc937e63795e2118a68db7a73c7521 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Sun, 19 Dec 2010 21:17:36 +0000 Subject: [PATCH] Add simple checksum test. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@402 36d66b0a-2a48-0410-832c-cd162a569da5 --- tests/mode-test | 54 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/mode-test b/tests/mode-test index 41872ef..9a8fe61 100755 --- a/tests/mode-test +++ b/tests/mode-test @@ -1,11 +1,7 @@ #!/bin/bash - # # Test mode compatibility, check input + kernel and cryptsetup cipher status # -# FIXME: add checkum test of data -# - CRYPTSETUP=../src/cryptsetup DEV_NAME=dmc_test LOOPDEV=/dev/loop5 @@ -46,46 +42,74 @@ dmcrypt_check() # device outstring { X=$(dmsetup table $1 2>/dev/null | cut -d' ' -f 4) if [ $X = $2 ] ; then - echo -n "OK]" + echo -n "[table OK]" else - echo -n "FAIL]" + echo "[table FAIL]" echo " Expecting $2 got $X." fail fi X=$($CRYPTSETUP status $1 | grep cipher | sed s/\.\*cipher:\\s*//) if [ $X = $2 ] ; then - echo " [OK]" + echo -n "[status OK]" else - echo " [FAIL]" + echo "[status FAIL]" echo " Expecting $2 got $X." fail fi + + dmsetup remove $1 >/dev/null 2>&1 +} + +dmcrypt_check_sum() # cipher device outstring +{ + EXPSUM="c036cbb7553a909f8b8877d4461924307f27ecb66cff928eeeafd569c3887e29" + # Fill device with zeroes and reopen it + dd if=/dev/zero of=/dev/mapper/$2 bs=1M count=6 >/dev/null 2>&1 + sync + dmsetup remove $2 + echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 $2 /dev/mapper/$DEV_NAME >/dev/null 2>&1 + ret=$? + VSUM=$(sha256sum /dev/mapper/$2 | cut -d' ' -f 1) + if [ $ret -eq 0 -a "$VSUM" = "$EXPSUM" ] ; then + echo -n "[OK]" + else + echo "[FAIL]" + echo " Expecting $EXPSUM got $VSUM." + fail + fi + + dmsetup remove $2 >/dev/null 2>&1 } dmcrypt() { OUT=$2 [ -z "$OUT" ] && OUT=$1 + printf "%-25s" "$1" - echo -n -e "TESTING(PLAIN): $1 [" echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1 if [ $? -eq 0 ] ; then + echo -n -e "PLAIN:" dmcrypt_check "$DEV_NAME"_"$1" $OUT - dmsetup remove "$DEV_NAME"_"$1" >/dev/null 2>&1 else - echo "SKIPPED]" + echo -n "[n/a]" fi - echo -n -e "TESTING(LUKS): $1 [" echo $PASSWORD | $CRYPTSETUP luksFormat -i 1 -c $1 -s 256 /dev/mapper/$DEV_NAME >/dev/null 2>&1 if [ $? -eq 0 ] ; then + echo -n -e " LUKS:" echo $PASSWORD | $CRYPTSETUP luksOpen /dev/mapper/$DEV_NAME "$DEV_NAME"_"$1" >/dev/null 2>&1 dmcrypt_check "$DEV_NAME"_"$1" $OUT - dmsetup remove "$DEV_NAME"_"$1" >/dev/null 2>&1 - else - echo "SKIPPED]" fi + + # repeated device creation must return the same checksum + echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1 + if [ $? -eq 0 ] ; then + echo -n -e " CHECKSUM:" + dmcrypt_check_sum "$1" "$DEV_NAME"_"$1" + fi + echo } if [ $(id -u) != 0 ]; then -- 2.7.4