integrity-copy.t revision 182452
121308Sache#!/bin/sh
221308Sache# $FreeBSD: head/tools/regression/geom_eli/integrity-copy.t 182452 2008-08-29 18:10:18Z pjd $
3157184Sache
421308Sachebase=`basename $0`
521308Sacheno=45
621308Sachesectors=100
721308Sachekeyfile=`mktemp /tmp/$base.XXXXXX` || exit 1
821308Sachesector=`mktemp /tmp/$base.XXXXXX` || exit 1
921308Sache
1021308Sacheecho "1..2640"
1121308Sache
1221308Sachei=1
1321308Sachefor cipher in aes:0 aes:128 aes:192 aes:256 \
1421308Sache    3des:0 3des:192 \
1521308Sache    blowfish:0 blowfish:128 blowfish:160 blowfish:192 blowfish:224 \
1621308Sache    blowfish:256 blowfish:288 blowfish:320 blowfish:352 blowfish:384 \
1721308Sache    blowfish:416 blowfish:448 \
1821308Sache    camellia:0 camellia:128 camellia:192 camellia:256; do
1921308Sache	ealgo=${cipher%%:*}
2021308Sache	keylen=${cipher##*:}
2158310Sache	for aalgo in hmac/md5 hmac/sha1 hmac/ripemd160 hmac/sha256 hmac/sha384 hmac/sha512; do
2221308Sache		for secsize in 512 1024 2048 4096 8192; do
2321308Sache			#mdconfig -a -t malloc -s `expr $secsize \* 2 + 512`b -u $no || exit 1
24136644Sache			mdconfig -a -t malloc -s $sectors -u $no || exit 1
25136644Sache
26136644Sache			dd if=/dev/random of=${keyfile} bs=512 count=16 >/dev/null 2>&1
27136644Sache
2821308Sache			geli init -B none -a $aalgo -e $ealgo -l $keylen -P -K $keyfile -s $secsize md${no} 2>/dev/null
2921308Sache			geli attach -p -k $keyfile md${no}
3021308Sache
3121308Sache			dd if=/dev/random of=/dev/md${no}.eli bs=${secsize} count=1 >/dev/null 2>&1
3221308Sache
3321308Sache			dd if=/dev/md${no}.eli bs=${secsize} count=1 >/dev/null 2>&1
3421308Sache			if [ $? -eq 0 ]; then
3521308Sache				echo "ok $i - small 1 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
3621308Sache			else
3721308Sache				echo "not ok $i - small 1 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
3821308Sache			fi
3921308Sache			i=$((i+1))
4021308Sache
4121308Sache			geli detach md${no}
4221308Sache			# Copy first small sector to the second small sector.
4321308Sache			# This should be detected as corruption.
4421308Sache			dd if=/dev/md${no} of=${sector} bs=512 count=1 >/dev/null 2>&1
4521308Sache			dd if=${sector} of=/dev/md${no} bs=512 count=1 seek=1 >/dev/null 2>&1
4621308Sache			geli attach -p -k $keyfile md${no}
4721308Sache
4821308Sache			dd if=/dev/md${no}.eli of=/dev/null bs=${secsize} count=1 >/dev/null 2>&1
4921308Sache			if [ $? -ne 0 ]; then
5021308Sache				echo "ok $i - small 2 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
5121308Sache			else
5221308Sache				echo "not ok $i - small 2 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
5321308Sache			fi
5421308Sache			i=$((i+1))
5521308Sache
5621308Sache			ms=`diskinfo /dev/md${no} | awk '{print $3 - 512}'`
5721308Sache			ns=`diskinfo /dev/md${no}.eli | awk '{print $4}'`
5821308Sache			usecsize=`echo "($ms / $ns) - (($ms / $ns) % 512)" | bc`
5921308Sache
6021308Sache			dd if=/dev/random of=/dev/md${no}.eli bs=${secsize} count=2 >/dev/null 2>&1
6121308Sache
6221308Sache			dd if=/dev/md${no}.eli bs=${secsize} count=2 >/dev/null 2>&1
6321308Sache			if [ $? -eq 0 ]; then
6421308Sache				echo "ok $i - big 1 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
6521308Sache			else
6621308Sache				echo "not ok $i - big 1 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
6721308Sache			fi
6821308Sache			i=$((i+1))
6921308Sache
70119610Sache			geli detach md${no}
7121308Sache			# Copy first big sector to the second big sector.
7221308Sache			# This should be detected as corruption.
7321308Sache			dd if=/dev/md${no} of=${sector} bs=${usecsize} count=1 >/dev/null 2>&1
7421308Sache			dd if=${sector} of=/dev/md${no} bs=${usecsize} count=1 seek=1 >/dev/null 2>&1
7558310Sache			geli attach -p -k $keyfile md${no}
7658310Sache
7758310Sache			dd if=/dev/md${no}.eli of=/dev/null bs=${secsize} count=2 >/dev/null 2>&1
7858310Sache			if [ $? -ne 0 ]; then
7921308Sache				echo "ok $i - big 2 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
8021308Sache			else
8121308Sache				echo "not ok $i - big 2 aalgo=${aalgo} ealgo=${ealgo} keylen=${keylen} sec=${secsize}"
8221308Sache			fi
8321308Sache			i=$((i+1))
8421308Sache
8521308Sache			geli detach md${no}
8675406Sache			mdconfig -d -u $no
8721308Sache		done
8875406Sache	done
8921308Sachedone
9075406Sache
9175406Sacherm -f $keyfile $sector
92119610Sache