#!/bin/bash
-CRYPTSETUP=../src/cryptsetup
+[ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
+CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
# try to validate using loop-AES losetup/kernel if available
LOSETUP_AES=/losetup-aes.old
function dmremove() { # device
udevadm settle >/dev/null 2>&1
- dmsetup remove $1 >/dev/null 2>&1
+ dmsetup remove --retry $1 >/dev/null 2>&1
}
function remove_mapping()
function fail()
{
+ echo "FAILED backtrace:"
+ while caller $frame; do ((frame++)); done
remove_mapping
- echo "FAILED"
exit 2
}
function skip()
{
[ -n "$1" ] && echo "$1"
- exit 0
+ exit 77
}
function prepare()
[ -b /dev/mapper/$DEV_NAME ] || fail
}
+function get_offset_params() # $offset
+{
+ offset=$1
+ if [ "${offset:0:1}" = "@" ] ; then
+ echo "-o $((${offset:1} / 512)) -p 0"
+ else
+ echo "-o $((offset / 512))"
+ fi
+}
+
function get_expsum() # $offset
{
case $1 in
0)
echo "31e00e0e4c233c89051cd748122fde2c98db0121ca09ba93a3820817ea037bc5"
;;
- 8192)
+ @8192 | 8192)
echo "bfd94392d1dd8f5d477251d21b3c736e177a4945cd4937847fc7bace82996aed"
;;
- 8388608)
+ @8388608 | 8388608)
echo "33838fe36928a929bd7971bed7e82bd426c88193fcd692c2e6f1b9c9bfecd4d6"
;;
*) fail
esac
}
-function check_sum() # $key $keysize $offset
+function check_sum() # $key $keysize $offset [stdin|keyfile]
{
# Fill device with zeroes and reopen it
dd if=/dev/zero of=/dev/mapper/$DEV_NAME bs=1k $LOOP_DD_PARAM >/dev/null 2>&1
sync
dmremove $DEV_NAME
- EXPSUM=$(get_expsum $offset)
- $CRYPTSETUP loopaesOpen $LOOPDEV $DEV_NAME -s $2 --key-file $1 -o $3 >/dev/null 2>&1
+ EXPSUM=$(get_expsum $3)
+ if [ "$4" == "stdin" ] ; then
+ cat $1 | $CRYPTSETUP loopaesOpen $LOOPDEV $DEV_NAME -s $2 --key-file - $(get_offset_params $3) >/dev/null 2>&1
+ else
+ $CRYPTSETUP loopaesOpen $LOOPDEV $DEV_NAME -s $2 --key-file $1 $(get_offset_params $3) >/dev/null 2>&1
+ fi
ret=$?
VSUM=$(sha256sum /dev/mapper/$DEV_NAME | cut -d' ' -f 1)
if [ $ret -eq 0 -a "$VSUM" = "$EXPSUM" ] ; then
- echo -n "[OK]"
+ echo -n "[$4:OK]"
else
- echo "[FAIL]"
- echo " Expecting $EXPSUM got $VSUM."
+ echo "[$4:FAIL]"
+ [ "$VSUM" != "$EXPSUM" ] && echo " Expecting $EXPSUM got $VSUM."
fail
fi
}
echo "[OK]"
else
echo "[FAIL]"
- echo " Expecting $EXPSUM got $VSUM (loop-AES)."
+ [ "$VSUM" != "$EXPSUM" ] && echo " Expecting $EXPSUM got $VSUM (loop-AES)."
fail
fi
losetup -d $LOOPDEV >/dev/null 2>&1
[ $(id -u) != 0 ] && skip "WARNING: You must be root to run this test, test skipped."
[ -z "$LOOPDEV" ] && skip "Cannot find free loop device, test skipped."
-which uuencode >/dev/null || skip "WARNING: test require uuencode binary, test skipped."
+which uuencode >/dev/null 2>&1 || skip "WARNING: test require uuencode binary, test skipped."
check_version || skip "Probably old kernel, test skipped."
# loop-AES tests
KEY_SIZES="128 256"
KEY_FILES="$KEYv1 $KEYv2 $KEYv3"
-DEV_OFFSET="0 8192 8388608"
+DEV_OFFSET="0 8192 @8192 8388608 @8388608"
for key_size in $KEY_SIZES ; do
for key in $KEY_FILES ; do
for offset in $DEV_OFFSET ; do
- offset_sec=$(($offset / 512))
prepare "Open loop-AES $key / AES-$key_size / offset $offset"
- $CRYPTSETUP loopaesOpen $LOOPDEV $DEV_NAME -s $key_size --key-file $key -o $offset_sec || fail
+ $CRYPTSETUP loopaesOpen $LOOPDEV $DEV_NAME \
+ -s $key_size --key-file $key $(get_offset_params $offset) \
+ 2>/dev/null
+ [ $? -ne 0 ] && echo "[SKIPPED]" && continue
check_exists
- check_sum $key $key_size $offset_sec
+ check_sum $key $key_size $offset keyfile
+ $CRYPTSETUP loopaesClose $DEV_NAME || fail
+ check_sum $key $key_size $offset stdin
$CRYPTSETUP loopaesClose $DEV_NAME || fail
check_sum_losetup $key AES$key_size $offset
done