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