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