xref: /freebsd/tests/sys/geom/class/eli/conf.sh (revision 96950419f15510287080c557174e0d8409f06956)
109d98641SEnji Cooper#!/bin/sh
209d98641SEnji Cooper
309d98641SEnji Cooperclass="eli"
4f397a004SAlan Somersbase=$(atf_get ident)
55dce212dSAlan SomersMAX_SECSIZE=8192
6f397a004SAlan Somers
7f397a004SAlan Somersattach_md()
8f397a004SAlan Somers{
9*96950419SGleb Smirnoff	local _md
10*96950419SGleb Smirnoff	local rv=$1
11*96950419SGleb Smirnoff	shift
12f397a004SAlan Somers
13ea823622SWarner Losh	[ -c /dev/mdctl ] || atf_skip "no /dev/mdctl to create md devices"
14*96950419SGleb Smirnoff	_md=$(mdconfig -a "$@") || atf_fail "failed to allocate md(4)"
15*96950419SGleb Smirnoff	echo $_md >> $TEST_MDS_FILE || exit
16*96950419SGleb Smirnoff	eval "${rv}='${_md}'"
17f397a004SAlan Somers}
1809d98641SEnji Cooper
19f92ce022SAlan Somers# Execute `func` for each combination of cipher, sectorsize, and hmac algo
20f92ce022SAlan Somers# `func` usage should be:
21f92ce022SAlan Somers# func <cipher> <aalgo> <secsize>
22f92ce022SAlan Somersfor_each_geli_config() {
23f92ce022SAlan Somers	func=$1
241d23aa6eSAlan Somers	backing_filename=$2
25f92ce022SAlan Somers
265dce212dSAlan Somers	# Double the sector size to allow for the HMACs' storage space.
275dce212dSAlan Somers	osecsize=$(( $MAX_SECSIZE * 2 ))
285dce212dSAlan Somers	# geli needs 512B for the label.
295dce212dSAlan Somers	bytes=`expr $osecsize \* $sectors + 512`b
301d23aa6eSAlan Somers
311d23aa6eSAlan Somers	if [ -n "$backing_filename" ]; then
321d23aa6eSAlan Somers		# Use a file-backed md(4) device, so we can deliberatly corrupt
331d23aa6eSAlan Somers		# it without detaching the geli device first.
341d23aa6eSAlan Somers		truncate -s $bytes backing_file
35*96950419SGleb Smirnoff		attach_md md -t vnode -f backing_file
361d23aa6eSAlan Somers	else
37*96950419SGleb Smirnoff		attach_md md -t malloc -s $bytes
381d23aa6eSAlan Somers	fi
391d23aa6eSAlan Somers
40f92ce022SAlan Somers	for cipher in aes-xts:128 aes-xts:256 \
41f92ce022SAlan Somers	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
42f92ce022SAlan Somers	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
43f92ce022SAlan Somers		ealgo=${cipher%%:*}
44f92ce022SAlan Somers		keylen=${cipher##*:}
45dff3f7f8SLi-Wen Hsu		for aalgo in hmac/sha1 hmac/ripemd160 hmac/sha256 \
46f92ce022SAlan Somers		    hmac/sha384 hmac/sha512; do
475dce212dSAlan Somers			for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
48f92ce022SAlan Somers				${func} $cipher $aalgo $secsize
492e23c411SAlan Somers				geli detach ${md} 2>/dev/null
50f92ce022SAlan Somers			done
51f92ce022SAlan Somers		done
52f92ce022SAlan Somers	done
53f92ce022SAlan Somers}
54f92ce022SAlan Somers
55f92ce022SAlan Somers# Execute `func` for each combination of cipher, and sectorsize, with no hmac
56f92ce022SAlan Somers# `func` usage should be:
57f92ce022SAlan Somers# func <cipher> <secsize>
58f92ce022SAlan Somersfor_each_geli_config_nointegrity() {
59f92ce022SAlan Somers	func=$1
60f92ce022SAlan Somers
615dce212dSAlan Somers	# geli needs 512B for the label.
625dce212dSAlan Somers	bytes=`expr $MAX_SECSIZE \* $sectors + 512`b
63*96950419SGleb Smirnoff	attach_md md -t malloc -s $bytes
64f92ce022SAlan Somers	for cipher in aes-xts:128 aes-xts:256 \
65f92ce022SAlan Somers	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
66f92ce022SAlan Somers	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
67f92ce022SAlan Somers		ealgo=${cipher%%:*}
68f92ce022SAlan Somers		keylen=${cipher##*:}
695dce212dSAlan Somers		for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
70610b95a1SAlan Somers			${func} $cipher $secsize
712e23c411SAlan Somers			geli detach ${md} 2>/dev/null
72f92ce022SAlan Somers		done
73f92ce022SAlan Somers	done
74f92ce022SAlan Somers}
75f92ce022SAlan Somers
7609d98641SEnji Coopergeli_test_cleanup()
7709d98641SEnji Cooper{
78041999e3SAlan Somers	if [ -f "$TEST_MDS_FILE" ]; then
79041999e3SAlan Somers		while read md; do
80041999e3SAlan Somers			[ -c /dev/${md}.eli ] && \
81041999e3SAlan Somers				geli detach $md.eli 2>/dev/null
82041999e3SAlan Somers			mdconfig -d -u $md 2>/dev/null
83041999e3SAlan Somers		done < $TEST_MDS_FILE
84041999e3SAlan Somers	fi
85f397a004SAlan Somers	true
8609d98641SEnji Cooper}
8709d98641SEnji Cooper
88cf551b8aSAlan Somersgeli_test_setup()
89cf551b8aSAlan Somers{
90cf551b8aSAlan Somers	geom_atf_test_setup
91cf551b8aSAlan Somers}
92cf551b8aSAlan Somers
93cf551b8aSAlan SomersATF_TEST=true
9409d98641SEnji Cooper. `dirname $0`/../geom_subr.sh
95