MODES="cbc lrw xts"
IVMODES="null benbi plain plain64 essiv:sha256"
+dmremove() { # device
+ udevadm settle 2>/dev/null 2>&1
+ dmsetup remove $1 2>/dev/null 2>&1
+}
+
cleanup() {
for dev in $(dmsetup status --target crypt | sed s/\:\ .*// | grep "^$DEV_NAME"_); do
- dmsetup remove $dev
+ dmremove $dev
done
- udevadm settle 2>/dev/null 2>&1
sleep 2
- [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
+ [ -b /dev/mapper/$DEV_NAME ] && dmremove $DEV_NAME
losetup -d $LOOPDEV >/dev/null 2>&1
rm -f $HEADER_IMG >/dev/null 2>&1
}
fail
fi
- dmsetup remove $1 >/dev/null 2>&1
+ dmremove $1
}
dmcrypt_check_sum() # cipher device outstring
# 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
+ dmremove $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)
fail
fi
- dmsetup remove $2 >/dev/null 2>&1
+ dmremove $2
}
dmcrypt()
DEV2=$DEV_NAME"_x"
-cleanup() {
- [ -b /dev/mapper/$DEV2 ] && dmsetup remove $DEV2
+dmremove() { # device
udevadm settle 2>/dev/null 2>&1
- [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
+ dmsetup remove $1 2>/dev/null 2>&1
+}
+
+cleanup() {
+ [ -b /dev/mapper/$DEV2 ] && dmremove $DEV2
+ [ -b /dev/mapper/$DEV_NAME ] && dmremove $DEV_NAME
rm -f $KEY_FILE
exit $1
}
MODE=aes-cbc-essiv:sha256
[ $2 -gt 256 ] && MODE=aes-xts-plain
+ echo -n "HASH: $1 KSIZE: $2 / $3"
case "$3" in
pwd)
- echo -e -n "$4" | $CRYPTSETUP create -c $MODE -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+ echo -e -n "$4" | $CRYPTSETUP create -c $MODE -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
+ ret=$?
;;
stdin)
- echo -e -n "$4" | $CRYPTSETUP create -c $MODE -d "-" -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+ echo -e -n "$4" | $CRYPTSETUP create -c $MODE -d "-" -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
+ ret=$?
;;
file)
- $CRYPTSETUP create -c $MODE -d $4 -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME
+ $CRYPTSETUP create -c $MODE -d $4 -h $1 -s $2 $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
+ ret=$?
;;
*)
fail
;;
esac
+ if [ $ret -ne 0 ] ; then
+ echo " [n/a]"
+ return
+ fi
+
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
+ else
+ echo " [OK]"
fi
- echo " [OK]"
- dmsetup remove $DEV2
+
+ dmremove $DEV2
}
if [ $(id -u) != 0 ]; then