1293436Sngie#!/bin/sh
2293436Sngie# $FreeBSD: stable/11/tests/sys/geom/class/eli/conf.sh 348588 2019-06-03 21:04:23Z jhb $
3293436Sngie
4293436Sngieclass="eli"
5328811Sasomersbase=$(atf_get ident)
6328811SasomersMAX_SECSIZE=8192
7293436Sngie
8328811Sasomersattach_md()
9328811Sasomers{
10328811Sasomers	local test_md
11293436Sngie
12328811Sasomers	test_md=$(mdconfig -a "$@") || atf_fail "failed to allocate md(4)"
13328811Sasomers	echo $test_md >> $TEST_MDS_FILE || exit
14328811Sasomers	echo $test_md
15328811Sasomers}
16328811Sasomers
17312829Sasomers# Execute `func` for each combination of cipher, sectorsize, and hmac algo
18312829Sasomers# `func` usage should be:
19312829Sasomers# func <cipher> <aalgo> <secsize>
20312829Sasomersfor_each_geli_config() {
21312829Sasomers	func=$1
22328811Sasomers	backing_filename=$2
23312829Sasomers
24328811Sasomers	# Double the sector size to allow for the HMACs' storage space.
25328811Sasomers	osecsize=$(( $MAX_SECSIZE * 2 ))
26328811Sasomers	# geli needs 512B for the label.
27328811Sasomers	bytes=`expr $osecsize \* $sectors + 512`b
28328811Sasomers
29328811Sasomers	if [ -n "$backing_filename" ]; then
30328811Sasomers		# Use a file-backed md(4) device, so we can deliberatly corrupt
31328811Sasomers		# it without detaching the geli device first.
32328811Sasomers		truncate -s $bytes backing_file
33328811Sasomers		md=$(attach_md -t vnode -f backing_file)
34328811Sasomers	else
35328811Sasomers		md=$(attach_md -t malloc -s $bytes)
36328811Sasomers	fi
37328811Sasomers
38312829Sasomers	for cipher in aes-xts:128 aes-xts:256 \
39312829Sasomers	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
40312829Sasomers	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
41312829Sasomers		ealgo=${cipher%%:*}
42312829Sasomers		keylen=${cipher##*:}
43348588Sjhb		for aalgo in hmac/sha1 hmac/ripemd160 hmac/sha256 \
44312829Sasomers		    hmac/sha384 hmac/sha512; do
45328811Sasomers			for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
46312829Sasomers				${func} $cipher $aalgo $secsize
47328811Sasomers				geli detach ${md} 2>/dev/null
48312829Sasomers			done
49312829Sasomers		done
50312829Sasomers	done
51312829Sasomers}
52312829Sasomers
53312829Sasomers# Execute `func` for each combination of cipher, and sectorsize, with no hmac
54312829Sasomers# `func` usage should be:
55312829Sasomers# func <cipher> <secsize>
56312829Sasomersfor_each_geli_config_nointegrity() {
57312829Sasomers	func=$1
58312829Sasomers
59328811Sasomers	# geli needs 512B for the label.
60328811Sasomers	bytes=`expr $MAX_SECSIZE \* $sectors + 512`b
61328811Sasomers	md=$(attach_md -t malloc -s $bytes)
62312829Sasomers	for cipher in aes-xts:128 aes-xts:256 \
63312829Sasomers	    aes-cbc:128 aes-cbc:192 aes-cbc:256 \
64312829Sasomers	    camellia-cbc:128 camellia-cbc:192 camellia-cbc:256; do
65312829Sasomers		ealgo=${cipher%%:*}
66312829Sasomers		keylen=${cipher##*:}
67328811Sasomers		for secsize in 512 1024 2048 4096 $MAX_SECSIZE; do
68328811Sasomers			${func} $cipher $secsize
69328811Sasomers			geli detach ${md} 2>/dev/null
70312829Sasomers		done
71312829Sasomers	done
72312829Sasomers}
73312829Sasomers
74293436Sngiegeli_test_cleanup()
75293436Sngie{
76328811Sasomers	if [ -f "$TEST_MDS_FILE" ]; then
77328811Sasomers		while read md; do
78328811Sasomers			[ -c /dev/${md}.eli ] && \
79328811Sasomers				geli detach $md.eli 2>/dev/null
80328811Sasomers			mdconfig -d -u $md 2>/dev/null
81328811Sasomers		done < $TEST_MDS_FILE
82328811Sasomers	fi
83328811Sasomers	true
84293436Sngie}
85293436Sngie
86345394Sasomersgeli_test_setup()
87345394Sasomers{
88345394Sasomers	geom_atf_test_setup
89345394Sasomers}
90345394Sasomers
91345394SasomersATF_TEST=true
92293436Sngie. `dirname $0`/../geom_subr.sh
93