"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/tests/tcrypt-compat-test" (13 Jan 2022, 5958 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "tcrypt-compat-test": 2.3.6_vs_2.4.0.

    1 #!/bin/bash
    2 
    3 # check tcrypt images parsing
    4 
    5 [ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
    6 CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
    7 TST_DIR=tcrypt-images
    8 MAP=tctst
    9 PASSWORD="aaaaaaaaaaaa"
   10 PASSWORD_HIDDEN="bbbbbbbbbbbb"
   11 PASSWORD_72C="aaaaaaaaaaaabbbbbbbbbbbbccccccccccccddddddddddddeeeeeeeeeeeeffffffffffff"
   12 PIM=1234
   13 
   14 CRYPTSETUP_VALGRIND=../.libs/cryptsetup
   15 CRYPTSETUP_LIB_VALGRIND=../.libs
   16 
   17 [ -z "$srcdir" ] && srcdir="."
   18 
   19 function remove_mapping()
   20 {
   21     [ -b /dev/mapper/$MAP ] && dmsetup remove --retry $MAP
   22     [ -b /dev/mapper/"$MAP"_1 ] && dmsetup remove --retry "$MAP"_1
   23     [ -b /dev/mapper/"$MAP"_2 ] && dmsetup remove --retry "$MAP"_2
   24     rm -rf $TST_DIR
   25 }
   26 
   27 function fail()
   28 {
   29     [ -n "$1" ] && echo "$1"
   30     echo " [FAILED]"
   31     echo "FAILED backtrace:"
   32     while caller $frame; do ((frame++)); done
   33     remove_mapping
   34     exit 2
   35 }
   36 
   37 function skip()
   38 {
   39     [ -n "$1" ] && echo "$1"
   40     echo "Test skipped."
   41     remove_mapping
   42     exit 77
   43 }
   44 
   45 function test_one() # cipher mode keysize rm_pattern
   46 {
   47     $CRYPTSETUP benchmark -c "$1-$2" -s "$3" >/dev/null 2>&1
   48     if [ $? -ne 0 ] ; then
   49         echo "$1-$2 [N/A]"
   50         IMGS=$(ls $TST_DIR/[tv]c* | grep "$4")
   51         [ -n "$IMGS" ] && rm $IMGS
   52         #echo $IMGS
   53     else
   54         echo "$1-$2 [OK]"
   55     fi
   56 }
   57 
   58 function test_kdf() # hash
   59 {
   60     $CRYPTSETUP benchmark -h "$1" >/dev/null 2>&1
   61     if [ $? -ne 0 ] ; then
   62         echo "pbkdf2-$1 [N/A]"
   63         IMGS=$(ls $TST_DIR/[tv]c* | grep "$1")
   64         [ -n "$IMGS" ] && rm $IMGS
   65     else
   66         echo "pbkdf2-$1 [OK]"
   67     fi
   68 }
   69 
   70 function test_required()
   71 {
   72     which lsblk >/dev/null 2>&1 || skip "WARNING: lsblk tool required."
   73 
   74     echo "REQUIRED KDF TEST"
   75     test_kdf sha256
   76     test_kdf sha512
   77     test_kdf ripemd160
   78     test_kdf whirlpool
   79     test_kdf stribog512
   80 
   81     echo "REQUIRED CIPHERS TEST"
   82     test_one aes cbc 256 cbc-aes
   83     test_one aes lrw 384 lrw-aes
   84     test_one aes xts 512 xts-aes
   85 
   86     test_one twofish ecb 256 twofish
   87     test_one twofish cbc 256 cbc-twofish
   88     test_one twofish lrw 384 lrw-twofish
   89     test_one twofish xts 512 xts-twofish
   90 
   91     test_one serpent ecb 256 serpent
   92     test_one serpent cbc 256 cbc-serpent
   93     test_one serpent lrw 384 lrw-serpent
   94     test_one serpent xts 512 xts-serpent
   95 
   96     test_one blowfish cbc 256 blowfish
   97 
   98     test_one des3_ede cbc 192 des3_ede
   99     test_one cast5 cbc 128 cast5
  100 
  101     test_one camellia xts 512 camellia
  102     test_one kuznyechik xts 512 kuznyechik
  103 
  104     ls $TST_DIR/[tv]c* >/dev/null 2>&1 || skip "No remaining images."
  105 }
  106 
  107 function valgrind_setup()
  108 {
  109     which valgrind >/dev/null 2>&1 || fail "Cannot find valgrind."
  110     [ ! -f $CRYPTSETUP_VALGRIND ] && fail "Unable to get location of cryptsetup executable."
  111     export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH"
  112 }
  113 
  114 function valgrind_run()
  115 {
  116     INFOSTRING="$(basename ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" ./valg.sh ${CRYPTSETUP_VALGRIND} "$@"
  117 }
  118 
  119 export LANG=C
  120 [ ! -d $TST_DIR ] && tar xJf $srcdir/tcrypt-images.tar.xz --no-same-owner
  121 
  122 [ -n "$VALG" ] && valgrind_setup && CRYPTSETUP=valgrind_run
  123 
  124 test_required
  125 
  126 echo "HEADER CHECK"
  127 for file in $(ls $TST_DIR/[tv]c_* $TST_DIR/vcpim_* $TST_DIR/sys_[tv]c_*) ; do
  128     echo -n " $file"
  129     PIM_OPT=""
  130     [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
  131     SYS_OPT=""
  132     [[ $file =~ sys_.* ]] && SYS_OPT="--tcrypt-system"
  133     echo $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT $file >/dev/null || fail
  134     if [[ $file =~ .*-sha512-xts-aes$ ]] ; then
  135         echo $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h sha512 -c aes $file >/dev/null || fail
  136         echo $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h xxxx $file 2>/dev/null && fail
  137         echo $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h sha512 -c xxx $file 2>/dev/null && fail
  138     fi
  139     echo " [OK]"
  140 done
  141 
  142 echo "HEADER CHECK (TCRYPT only)"
  143 for file in $(ls $TST_DIR/vc_* $TST_DIR/vcpim_*) ; do
  144     echo -n " $file"
  145     PIM_OPT=""
  146     [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
  147     echo $PASSWORD | $CRYPTSETUP tcryptDump --disable-veracrypt $PIM_OPT $file >/dev/null 2>&1 && fail
  148     echo " [OK]"
  149 done
  150 
  151 echo "HEADER CHECK (HIDDEN)"
  152 for file in $(ls $TST_DIR/[tv]c_*-hidden) ; do
  153     echo -n " $file (hidden)"
  154     echo $PASSWORD_HIDDEN | $CRYPTSETUP tcryptDump --tcrypt-hidden $file >/dev/null || fail
  155     echo " [OK]"
  156 done
  157 
  158 echo "HEADER KEYFILES CHECK"
  159 for file in $(ls $TST_DIR/[tv]ck_*) ; do
  160     echo -n " $file"
  161     PWD=$PASSWORD
  162     [[ $file =~ vck_1_nopw.* ]] && PWD=""
  163     [[ $file =~ vck_1_pw72.* ]] && PWD=$PASSWORD_72C
  164     echo $PWD | $CRYPTSETUP tcryptDump -d $TST_DIR/keyfile1 -d $TST_DIR/keyfile2 $file >/dev/null || fail
  165     echo " [OK]"
  166 done
  167 
  168 
  169 if [ $(id -u) != 0 ]; then
  170     echo "WARNING: You must be root to run activation part of test, test skipped."
  171     remove_mapping
  172     exit 0
  173 fi
  174 
  175 echo "ACTIVATION FS UUID CHECK"
  176 for file in $(ls $TST_DIR/[tv]c_* $TST_DIR/vcpim_* $TST_DIR/sys_[tv]c_*) ; do
  177     echo -n " $file"
  178     PIM_OPT=""
  179     [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
  180     SYS_OPT=""
  181     [[ $file =~ sys_.* ]] && SYS_OPT="--tcrypt-system"
  182     out=$(echo $PASSWORD | $CRYPTSETUP tcryptOpen $SYS_OPT $PIM_OPT -r $file $MAP 2>&1)
  183     ret=$?
  184     [ $ret -eq 1 ] && ( echo "$out" | grep -q -e "TCRYPT legacy mode" ) && echo " [N/A]" && continue
  185     [ $ret -eq 1 ] && ( echo "$out" | grep -q -e "TCRYPT compatible mapping" ) && echo " [N/A]" && continue
  186     [ $ret -ne 0 ] && fail
  187     $CRYPTSETUP status $MAP >/dev/null || fail
  188     $CRYPTSETUP status /dev/mapper/$MAP >/dev/null || fail
  189     UUID=$(lsblk -n -o UUID /dev/mapper/$MAP)
  190     $CRYPTSETUP remove $MAP || fail
  191     [ "$UUID" != "DEAD-BABE" ] && fail "UUID check failed."
  192     echo " [OK]"
  193 done
  194 
  195 echo "ACTIVATION FS UUID (HIDDEN) CHECK"
  196 for file in $(ls $TST_DIR/[tv]c_*-hidden) ; do
  197     echo -n " $file"
  198     out=$(echo $PASSWORD_HIDDEN | $CRYPTSETUP tcryptOpen -r $file $MAP --tcrypt-hidden 2>&1)
  199     ret=$?
  200     [ $ret -eq 1 ] && ( echo "$out" | grep -q -e "TCRYPT legacy mode" ) && echo " [N/A]" && continue
  201     [ $ret -eq 1 ] && ( echo "$out" | grep -q -e "TCRYPT compatible mapping" ) && echo " [N/A]" && continue
  202     [ $ret -ne 0 ] && fail
  203     UUID=$(lsblk -n -o UUID /dev/mapper/$MAP)
  204     $CRYPTSETUP remove $MAP || fail
  205     [ "$UUID" != "CAFE-BABE" ] && fail "UUID check failed."
  206     echo " [OK]"
  207 done
  208 
  209 remove_mapping
  210 exit 0