3 # Test mode compatibility, check input + kernel and cryptsetup cipher status
5 CRYPTSETUP=../src/cryptsetup
7 HEADER_IMG=mode-test.img
10 # cipher-chainmode-ivopts:ivmode
11 CIPHERS="aes twofish serpent"
13 IVMODES="null benbi plain plain64 essiv:sha256"
15 LOOPDEV=$(losetup -f 2>/dev/null)
18 udevadm settle >/dev/null 2>&1
19 dmsetup remove $1 >/dev/null 2>&1
23 for dev in $(dmsetup status --target crypt | sed s/\:\ .*// | grep "^$DEV_NAME"_); do
27 [ -b /dev/mapper/$DEV_NAME ] && dmremove $DEV_NAME
28 losetup -d $LOOPDEV >/dev/null 2>&1
29 rm -f $HEADER_IMG >/dev/null 2>&1
34 [ -n "$1" ] && echo "$1"
41 [ -n "$1" ] && echo "$1"
46 dd if=/dev/zero of=$HEADER_IMG bs=1M count=6 >/dev/null 2>&1
48 losetup $LOOPDEV $HEADER_IMG >/dev/null 2>&1
49 dmsetup create $DEV_NAME --table "0 10240 linear $LOOPDEV 8" >/dev/null 2>&1
52 dmcrypt_check() # device outstring
54 X=$(dmsetup table $1 2>/dev/null | sed 's/.*: //' | cut -d' ' -f 4)
59 echo " Expecting $2 got $X."
63 X=$($CRYPTSETUP status $1 | grep cipher: | sed s/\.\*cipher:\\s*//)
68 echo " Expecting $2 got $X."
75 dmcrypt_check_sum() # cipher device outstring
77 EXPSUM="c036cbb7553a909f8b8877d4461924307f27ecb66cff928eeeafd569c3887e29"
78 # Fill device with zeroes and reopen it
79 dd if=/dev/zero of=/dev/mapper/$2 bs=1M count=6 >/dev/null 2>&1
83 echo $PASSWORD | $CRYPTSETUP create -h sha256 -c $1 -s 256 $2 /dev/mapper/$DEV_NAME >/dev/null 2>&1
85 VSUM=$(sha256sum /dev/mapper/$2 | cut -d' ' -f 1)
86 if [ $ret -eq 0 -a "$VSUM" = "$EXPSUM" ] ; then
90 echo " Expecting $EXPSUM got $VSUM."
100 [ -z "$OUT" ] && OUT=$1
103 echo $PASSWORD | $CRYPTSETUP create -h sha256 -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1
104 if [ $? -eq 0 ] ; then
106 dmcrypt_check "$DEV_NAME"_"$1" $OUT
111 echo $PASSWORD | $CRYPTSETUP luksFormat -i 1 -c $1 -s 256 /dev/mapper/$DEV_NAME >/dev/null 2>&1
112 if [ $? -eq 0 ] ; then
114 echo $PASSWORD | $CRYPTSETUP luksOpen /dev/mapper/$DEV_NAME "$DEV_NAME"_"$1" >/dev/null 2>&1
115 dmcrypt_check "$DEV_NAME"_"$1" $OUT
118 # repeated device creation must return the same checksum
119 echo $PASSWORD | $CRYPTSETUP create -h sha256 -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1
120 if [ $? -eq 0 ] ; then
121 echo -n -e " CHECKSUM:"
122 dmcrypt_check_sum "$1" "$DEV_NAME"_"$1"
127 [ $(id -u) != 0 ] && skip "WARNING: You must be root to run this test, test skipped."
128 [ -z "$LOOPDEV" ] && skip "Cannot find free loop device, test skipped."
132 # compatibility modes
133 dmcrypt aes aes-cbc-plain
134 dmcrypt aes-plain aes-cbc-plain
137 dmcrypt null cipher_null-ecb
138 dmcrypt cipher_null cipher_null-cbc-plain
139 dmcrypt cipher_null-ecb
141 # codebook doesn't support IV at all
142 for cipher in $CIPHERS ; do
143 dmcrypt "$cipher-ecb"
146 for cipher in $CIPHERS ; do
147 for mode in $MODES ; do
148 for ivmode in $IVMODES ; do
149 dmcrypt "$cipher-$mode-$ivmode"