Makefile: Add security compiling option (RELRO, SC, and FORTIFY)
[platform/upstream/cryptsetup.git] / tests / luks1-compat-test
1 #!/bin/bash
2
3 # check luks1 images parsing
4
5 # NOTE: if image with whirlpool hash fails, check
6 # that you are not using old gcrypt with flawed whirlpool
7 # (see cryptsetup debug output)
8
9 CRYPTSETUP=../src/cryptsetup
10 TST_DIR=luks1-images
11 MAP=luks1tst
12 KEYFILE=keyfile1
13
14 function remove_mapping()
15 {
16         [ -b /dev/mapper/$MAP ] && dmsetup remove $MAP
17 }
18
19 function fail()
20 {
21         [ -n "$1" ] && echo "$1"
22         echo " [FAILED]"
23         remove_mapping
24         exit 2
25 }
26
27 function skip()
28 {
29         [ -n "$1" ] && echo "$1"
30         echo "Test skipped."
31         exit 0
32 }
33
34 function test_one()
35 {
36         $CRYPTSETUP benchmark -c "$1" -s "$2" | grep -v "#" || skip
37 }
38
39 function test_required()
40 {
41         which lsblk >/dev/null 2>&1 || skip "WARNING: lsblk tool required."
42
43         echo "REQUIRED KDF TEST"
44         $CRYPTSETUP benchmark -h whirlpool | grep "N/A" && skip
45
46         echo "REQUIRED CIPHERS TEST"
47         echo "#  Algorithm | Key |  Encryption |  Decryption"
48
49         test_one aes-xts 256
50         test_one twofish-xts 256
51         test_one serpent-xts 256
52         test_one aes-cbc 256
53         test_one aes-lrw 256
54 }
55
56 export LANG=C
57
58 if [ $(id -u) != 0 ]; then
59         echo "WARNING: You must be root to run activation part of test, test skipped."
60         exit 0
61 fi
62
63 test_required
64 [ ! -d $TST_DIR ] && tar xjf luks1-images.tar.bz2
65
66 echo "ACTIVATION FS UUID CHECK"
67 for file in $(ls $TST_DIR/luks1_*) ; do
68         echo -n " $file"
69         $CRYPTSETUP luksOpen -d $TST_DIR/$KEYFILE $file $MAP 2>/dev/null
70         ret=$?
71         # ignore missing whirlpool (pwd failed is exit code 2)
72         [ $ret -eq 1 ] && (echo $file | grep -q -e "whirlpool") && echo " [N/A]" && continue
73         [ $ret -ne 0 ] && fail
74         $CRYPTSETUP status $MAP >/dev/null || fail
75         $CRYPTSETUP status /dev/mapper/$MAP >/dev/null || fail
76         UUID=$(lsblk -n -o UUID /dev/mapper/$MAP)
77         $CRYPTSETUP remove $MAP || fail
78         [ "$UUID" != "DEAD-BABE" ] && fail "UUID check failed."
79         echo " [OK]"
80 done