xref: /freebsd/tests/sys/geom/class/eli/conf.sh (revision d0b2dbfa)
1#!/bin/sh
2
3class="eli"
4base=$(atf_get ident)
5MAX_SECSIZE=8192
6
7attach_md()
8{
9	local test_md
10
11	test_md=$(mdconfig -a "$@") || atf_fail "failed to allocate md(4)"
12	echo $test_md >> $TEST_MDS_FILE || exit
13	echo $test_md
14}
15
16# Execute `func` for each combination of cipher, sectorsize, and hmac algo
17# `func` usage should be:
18# func <cipher> <aalgo> <secsize>
19for_each_geli_config() {
20	func=$1
21	backing_filename=$2
22
23	# Double the sector size to allow for the HMACs' storage space.
24	osecsize=$(( $MAX_SECSIZE * 2 ))
25	# geli needs 512B for the label.
26	bytes=`expr $osecsize \* $sectors + 512`b
27
28	if [ -n "$backing_filename" ]; then
29		# Use a file-backed md(4) device, so we can deliberatly corrupt
30		# it without detaching the geli device first.
31		truncate -s $bytes backing_file
32		md=$(attach_md -t vnode -f backing_file)
33	else
34		md=$(attach_md -t malloc -s $bytes)
35	fi
36
37	for cipher in aes-xts:128 aes-xts:256 \
38	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
39	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
40		ealgo=${cipher%%:*}
41		keylen=${cipher##*:}
42		for aalgo in hmac/sha1 hmac/ripemd160 hmac/sha256 \
43		    hmac/sha384 hmac/sha512; do
44			for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
45				${func} $cipher $aalgo $secsize
46				geli detach ${md} 2>/dev/null
47			done
48		done
49	done
50}
51
52# Execute `func` for each combination of cipher, and sectorsize, with no hmac
53# `func` usage should be:
54# func <cipher> <secsize>
55for_each_geli_config_nointegrity() {
56	func=$1
57
58	# geli needs 512B for the label.
59	bytes=`expr $MAX_SECSIZE \* $sectors + 512`b
60	md=$(attach_md -t malloc -s $bytes)
61	for cipher in aes-xts:128 aes-xts:256 \
62	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
63	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
64		ealgo=${cipher%%:*}
65		keylen=${cipher##*:}
66		for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
67			${func} $cipher $secsize
68			geli detach ${md} 2>/dev/null
69		done
70	done
71}
72
73geli_test_cleanup()
74{
75	if [ -f "$TEST_MDS_FILE" ]; then
76		while read md; do
77			[ -c /dev/${md}.eli ] && \
78				geli detach $md.eli 2>/dev/null
79			mdconfig -d -u $md 2>/dev/null
80		done < $TEST_MDS_FILE
81	fi
82	true
83}
84
85geli_test_setup()
86{
87	geom_atf_test_setup
88}
89
90ATF_TEST=true
91. `dirname $0`/../geom_subr.sh
92