f0ca01ae9409125c9dd6c58081c3d2c116a14388
[platform/upstream/cryptsetup.git] / tests / generators / generate-luks2-invalid-checksum-hdr1.img.sh
1 #!/bin/bash
2
3 . lib.sh
4
5 #
6 # *** Description ***
7 #
8 # generate header with bad checksum in secondary binary header
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         chks=$(echo "Arbitrary chosen string: D'oh!" | calc_sha256_checksum_stdin)
24         write_checksum $chks $TMPDIR/hdr1
25         write_luks2_bin_hdr1 $TMPDIR/hdr1 $TGT_IMG
26 }
27
28 function check()
29 {
30         chks_res=$(read_sha256_checksum $TMPDIR/hdr1)
31         test "$chks" = "$chks_res" || exit 2
32 }
33
34 function cleanup()
35 {
36         rm -f $TMPDIR/*
37         rm -fd $TMPDIR
38 }
39
40 test $# -eq 2 || exit 1
41
42 TGT_IMG=$1/$(test_img_name $0)
43 SRC_IMG=$2
44
45 prepare
46 generate
47 check
48 cleanup