4 . $(dirname $0)/conf.sh
8 rnd=`mktemp $base.XXXXXX` || exit 1
9 keyfile1=`mktemp $base.XXXXXX` || exit 1
10 keyfile2=`mktemp $base.XXXXXX` || exit 1
11 keyfile3=`mktemp $base.XXXXXX` || exit 1
12 keyfile4=`mktemp $base.XXXXXX` || exit 1
13 keyfile5=`mktemp $base.XXXXXX` || exit 1
14 mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1
18 dd if=/dev/random of=${rnd} bs=512 count=${sectors} >/dev/null 2>&1
19 hash1=`dd if=${rnd} bs=512 count=${sectors} 2>/dev/null | md5`
20 dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1
21 dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1
22 dd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1
23 dd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1
24 dd if=/dev/random of=${keyfile5} bs=512 count=16 >/dev/null 2>&1
26 geli init -B none -P -K $keyfile1 md${no}
27 geli attach -p -k $keyfile1 md${no}
29 dd if=${rnd} of=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null
31 hash2=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
33 # Change current key (0) for attached provider.
34 geli setkey -P -K $keyfile2 md${no}
42 # We cannot use keyfile1 anymore.
43 geli attach -p -k $keyfile1 md${no} 2>/dev/null
50 # Attach with new key.
51 geli attach -p -k $keyfile2 md${no}
57 hash3=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
59 # Change key 1 for attached provider.
60 geli setkey -n 1 -P -K $keyfile3 md${no}
69 geli attach -p -k $keyfile3 md${no}
75 hash4=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
78 # Change current (1) key for detached provider.
79 geli setkey -p -k $keyfile3 -P -K $keyfile4 md${no}
86 # We cannot use keyfile3 anymore.
87 geli attach -p -k $keyfile3 md${no} 2>/dev/null
95 geli attach -p -k $keyfile4 md${no}
101 hash5=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
104 # Change key 0 for detached provider.
105 geli setkey -n 0 -p -k $keyfile4 -P -K $keyfile5 md${no}
106 if [ $? -eq 0 ]; then
112 # We cannot use keyfile2 anymore.
113 geli attach -p -k $keyfile2 md${no} 2>/dev/null
114 if [ $? -ne 0 ]; then
121 geli attach -p -k $keyfile5 md${no}
122 if [ $? -eq 0 ]; then
127 hash6=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
130 if [ ${hash1} = ${hash2} ]; then
135 if [ ${hash1} = ${hash3} ]; then
140 if [ ${hash1} = ${hash4} ]; then
145 if [ ${hash1} = ${hash5} ]; then
150 if [ ${hash1} = ${hash6} ]; then
156 rm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4 $keyfile5