Pass read/write CRx registers to userspace
[freebsd-src/fkvm-freebsd.git] / tools / regression / geom_eli / setkey.t
blob611471a19be8ccfb76fc3fdcea3e978bf0e1a906
1 #!/bin/sh
2 # $FreeBSD$
4 base=`basename $0`
5 no=45
6 sectors=100
7 rnd=`mktemp /tmp/$base.XXXXXX` || exit 1
8 keyfile1=`mktemp /tmp/$base.XXXXXX` || exit 1
9 keyfile2=`mktemp /tmp/$base.XXXXXX` || exit 1
10 keyfile3=`mktemp /tmp/$base.XXXXXX` || exit 1
11 keyfile4=`mktemp /tmp/$base.XXXXXX` || exit 1
12 keyfile5=`mktemp /tmp/$base.XXXXXX` || exit 1
13 mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1
15 echo "1..16"
17 dd if=/dev/random of=${rnd} bs=512 count=${sectors} >/dev/null 2>&1
18 hash1=`dd if=${rnd} bs=512 count=${sectors} 2>/dev/null | md5`
19 dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1
20 dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1
21 dd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1
22 dd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1
23 dd if=/dev/random of=${keyfile5} bs=512 count=16 >/dev/null 2>&1
25 geli init -B none -P -K $keyfile1 md${no}
26 geli attach -p -k $keyfile1 md${no}
28 dd if=${rnd} of=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null
29 rm -f $rnd
30 hash2=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
32 # Change current key (0) for attached provider.
33 geli setkey -P -K $keyfile2 md${no}
34 if [ $? -eq 0 ]; then
35 echo "ok 1"
36 else
37 echo "not ok 1"
39 geli detach md${no}
41 # We cannot use keyfile1 anymore.
42 geli attach -p -k $keyfile1 md${no} 2>/dev/null
43 if [ $? -ne 0 ]; then
44 echo "ok 2"
45 else
46 echo "not ok 2"
49 # Attach with new key.
50 geli attach -p -k $keyfile2 md${no}
51 if [ $? -eq 0 ]; then
52 echo "ok 3"
53 else
54 echo "not ok 3"
56 hash3=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
58 # Change key 1 for attached provider.
59 geli setkey -n 1 -P -K $keyfile3 md${no}
60 if [ $? -eq 0 ]; then
61 echo "ok 4"
62 else
63 echo "not ok 4"
65 geli detach md${no}
67 # Attach with key 1.
68 geli attach -p -k $keyfile3 md${no}
69 if [ $? -eq 0 ]; then
70 echo "ok 5"
71 else
72 echo "not ok 5"
74 hash4=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
75 geli detach md${no}
77 # Change current (1) key for detached provider.
78 geli setkey -p -k $keyfile3 -P -K $keyfile4 md${no}
79 if [ $? -eq 0 ]; then
80 echo "ok 6"
81 else
82 echo "not ok 6"
85 # We cannot use keyfile3 anymore.
86 geli attach -p -k $keyfile3 md${no} 2>/dev/null
87 if [ $? -ne 0 ]; then
88 echo "ok 7"
89 else
90 echo "not ok 7"
93 # Attach with key 1.
94 geli attach -p -k $keyfile4 md${no}
95 if [ $? -eq 0 ]; then
96 echo "ok 8"
97 else
98 echo "not ok 8"
100 hash5=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
101 geli detach md${no}
103 # Change key 0 for detached provider.
104 geli setkey -n 0 -p -k $keyfile4 -P -K $keyfile5 md${no}
105 if [ $? -eq 0 ]; then
106 echo "ok 9"
107 else
108 echo "not ok 9"
111 # We cannot use keyfile2 anymore.
112 geli attach -p -k $keyfile2 md${no} 2>/dev/null
113 if [ $? -ne 0 ]; then
114 echo "ok 10"
115 else
116 echo "not ok 10"
119 # Attach with key 0.
120 geli attach -p -k $keyfile5 md${no}
121 if [ $? -eq 0 ]; then
122 echo "ok 11"
123 else
124 echo "not ok 11"
126 hash6=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
127 geli detach md${no}
129 if [ ${hash1} = ${hash2} ]; then
130 echo "ok 12"
131 else
132 echo "not ok 12"
134 if [ ${hash1} = ${hash3} ]; then
135 echo "ok 13"
136 else
137 echo "not ok 13"
139 if [ ${hash1} = ${hash4} ]; then
140 echo "ok 14"
141 else
142 echo "not ok 14"
144 if [ ${hash1} = ${hash5} ]; then
145 echo "ok 15"
146 else
147 echo "not ok 15"
149 if [ ${hash1} = ${hash6} ]; then
150 echo "ok 16"
151 else
152 echo "not ok 16"
155 mdconfig -d -u $no
156 rm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4 $keyfile5