be98722ac3cb01d11439479787ae42ee787a453f
[platform/upstream/cryptsetup.git] / tests / generators / generate-luks2-invalid-checksum-both-hdrs.img.sh
1 #!/bin/bash
2
3 . lib.sh
4
5 #
6 # *** Description ***
7 #
8 # generate header with bad checksum in both binary headerer
9 #
10
11 # $1 full target dir
12 # $2 full source luks2 image
13
14 function prepare()
15 {
16         cp $SRC_IMG $TGT_IMG
17         test -d $TMPDIR || mkdir $TMPDIR
18         read_luks2_bin_hdr1 $TGT_IMG $TMPDIR/hdr1
19 }
20
21 function generate()
22 {
23         chks0=$(echo "Arbitrary chosen string: D'oh!" | calc_sha256_checksum_stdin)
24         chks1=$(echo "D'oh!: arbitrary chosen string" | calc_sha256_checksum_stdin)
25         write_checksum $chks0 $TGT_IMG
26         write_checksum $chks1 $TMPDIR/hdr1
27         write_luks2_bin_hdr1 $TMPDIR/hdr1 $TGT_IMG
28 }
29
30 function check()
31 {
32         chks_res0=$(read_sha256_checksum $TGT_IMG)
33         chks_res1=$(read_sha256_checksum $TMPDIR/hdr1)
34         test "$chks0" = "$chks_res0" || exit 2
35         test "$chks1" = "$chks_res1" || exit 2
36 }
37
38 function cleanup()
39 {
40         rm -f $TMPDIR/*
41         rm -fd $TMPDIR
42 }
43
44 test $# -eq 2 || exit 1
45
46 TGT_IMG=$1/$(test_img_name $0)
47 SRC_IMG=$2
48
49 prepare
50 generate
51 check
52 cleanup