1309466Sngie#	$NetBSD: t_opencrypto.sh,v 1.6 2015/12/26 07:10:03 pgoyette Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2014 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngie# Start a rumpserver, load required modules, and set requires sysctl vars
29272343Sngie
30272343Sngiestart_rump() {
31272343Sngie	rump_libs="-l rumpvfs -l rumpdev -l rumpdev_opencrypto"
32272343Sngie	rump_libs="${rump_libs} -l rumpkern_z -l rumpkern_crypto"
33272343Sngie
34272343Sngie	rump_server ${rump_libs} ${RUMP_SERVER} || \
35272343Sngie	    return 1
36272343Sngie
37272343Sngie	rump.sysctl -w kern.cryptodevallowsoft=-1 && \
38272343Sngie	    return 0
39272343Sngie
40272343Sngie	rump.halt
41272343Sngie
42272343Sngie	return 1
43272343Sngie}
44272343Sngie
45272343Sngiecommon_head() {
46272343Sngie	atf_set	descr		"$1"
47272343Sngie	atf_set	timeout		10
48272343Sngie	atf_set	require.progs	rump_server	rump.sysctl	rump.halt
49272343Sngie}
50272343Sngie
51272343Sngiecommon_body() {
52272343Sngie	local status
53272343Sngie
54272343Sngie	start_rump || atf_skip "Cannot set-up rump environment"
55272343Sngie	LD_PRELOAD="/usr/lib/librumphijack.so" ; export LD_PRELOAD
56272343Sngie	RUMPHIJACK="blanket=/dev/crypto" ; export RUMPHIJACK
57272343Sngie	$(atf_get_srcdir)/$1
58272343Sngie	status=$?
59272343Sngie	unset RUMPHIJACK
60272343Sngie	unset LD_PRELOAD
61272343Sngie	if [ $status -ne 0 ] ; then
62272343Sngie		atf_fail "$1 returned non-zero status, check output/error"
63272343Sngie	fi
64272343Sngie}
65272343Sngie
66272343Sngiecommon_cleanup() {
67272343Sngie	unset RUMPHIJACK
68272343Sngie	unset LD_PRELOAD
69272343Sngie	rump.halt
70272343Sngie}
71272343Sngie
72272343Sngieatf_test_case arc4 cleanup
73272343Sngiearc4_head() {
74272343Sngie	common_head "Test ARC4 crypto"
75272343Sngie}
76272343Sngie
77272343Sngiearc4_body() {
78272343Sngie	atf_skip "ARC4 not implemented by swcrypto"
79272343Sngie	common_body h_arc4
80272343Sngie}
81272343Sngie
82272343Sngiearc4_cleanup() {
83309466Sngie	# No cleanup required since test is skipped.  Trying to run rump.halt
84309466Sngie	# at this point fails, causing the ATF environment to erroneously
85309466Sngie	# report a failed test!
86309466Sngie	#
87309466Sngie	# common_cleanup
88272343Sngie}
89272343Sngie
90272343Sngieatf_test_case camellia cleanup
91272343Sngiecamellia_head() {
92272343Sngie	common_head "Test CAMELLIA_CBC crypto"
93272343Sngie}
94272343Sngie
95272343Sngiecamellia_body() {
96272343Sngie	common_body h_camellia
97272343Sngie}
98272343Sngie
99272343Sngiecamellia_cleanup() {
100272343Sngie	common_cleanup
101272343Sngie}
102272343Sngie
103272343Sngieatf_test_case cbcdes cleanup
104272343Sngiecbcdes_head() {
105309466Sngie	common_head "Test DES_CBC crypto"
106272343Sngie}
107272343Sngie
108272343Sngiecbcdes_body() {
109272343Sngie	common_body h_cbcdes
110272343Sngie}
111272343Sngie
112272343Sngiecbcdes_cleanup() {
113272343Sngie	common_cleanup
114272343Sngie}
115272343Sngie
116272343Sngieatf_test_case comp cleanup
117272343Sngiecomp_head() {
118272343Sngie	common_head "Test GZIP_COMP Compression"
119272343Sngie}
120272343Sngie
121272343Sngiecomp_body() {
122272343Sngie	common_body h_comp
123272343Sngie}
124272343Sngie
125272343Sngiecomp_cleanup() {
126272343Sngie	common_cleanup
127272343Sngie}
128272343Sngie
129272343Sngieatf_test_case comp_deflate cleanup
130272343Sngiecomp_deflate_head() {
131272343Sngie	common_head "Test DEFLATE_COMP Compression"
132272343Sngie}
133272343Sngie
134272343Sngiecomp_deflate_body() {
135272343Sngie	common_body h_comp_zlib
136272343Sngie}
137272343Sngie
138272343Sngiecomp_deflate_cleanup() {
139272343Sngie	common_cleanup
140272343Sngie}
141272343Sngie
142272343Sngieatf_test_case comp_zlib_rnd cleanup
143272343Sngiecomp_zlib_rnd_head() {
144272343Sngie	common_head "Test DEFLATE_COMP Compression with random data"
145272343Sngie}
146272343Sngie
147272343Sngiecomp_zlib_rnd_body() {
148272343Sngie	common_body h_comp_zlib_rnd
149272343Sngie}
150272343Sngie
151272343Sngiecomp_zlib_rnd_cleanup() {
152272343Sngie	common_cleanup
153272343Sngie}
154272343Sngie
155272343Sngieatf_test_case aesctr1 cleanup
156272343Sngieaesctr1_head() {
157272343Sngie	common_head "Test AES_CTR crypto"
158272343Sngie}
159272343Sngie
160272343Sngieaesctr1_body() {
161272343Sngie	common_body h_aesctr1
162272343Sngie}
163272343Sngie
164272343Sngieaesctr1_cleanup() {
165272343Sngie	common_cleanup
166272343Sngie}
167272343Sngie
168272343Sngieatf_test_case aesctr2 cleanup
169272343Sngieaesctr2_head() {
170272343Sngie	common_head "Test AES_CTR crypto"
171272343Sngie}
172272343Sngie
173272343Sngieaesctr2_body() {
174272343Sngie	common_body h_aesctr2
175272343Sngie}
176272343Sngie
177272343Sngieaesctr2_cleanup() {
178272343Sngie	common_cleanup
179272343Sngie}
180272343Sngie
181272343Sngieatf_test_case gcm cleanup
182272343Sngiegcm_head() {
183272343Sngie	common_head "Test AES_GCM_16 crypto"
184272343Sngie}
185272343Sngie
186272343Sngiegcm_body() {
187272343Sngie	common_body h_gcm
188272343Sngie}
189272343Sngie
190272343Sngiegcm_cleanup() {
191272343Sngie	common_cleanup
192272343Sngie}
193272343Sngie
194272343Sngieatf_test_case md5 cleanup
195272343Sngiemd5_head() {
196272343Sngie	common_head "Test MD5 crypto"
197272343Sngie}
198272343Sngie
199272343Sngiemd5_body() {
200272343Sngie	common_body h_md5
201272343Sngie}
202272343Sngie
203272343Sngiemd5_cleanup() {
204272343Sngie	common_cleanup
205272343Sngie}
206272343Sngie
207272343Sngieatf_test_case md5_hmac cleanup
208272343Sngiemd5_hmac_head() {
209272343Sngie	common_head "Test MD5_HMAC crypto"
210272343Sngie}
211272343Sngie
212272343Sngiemd5_hmac_body() {
213272343Sngie	common_body h_md5hmac
214272343Sngie}
215272343Sngie
216272343Sngiemd5_hmac_cleanup() {
217272343Sngie	common_cleanup
218272343Sngie}
219272343Sngie
220272343Sngieatf_test_case null cleanup
221272343Sngienull_head() {
222272343Sngie	common_head "Test NULL_CBC crypto"
223272343Sngie}
224272343Sngie
225272343Sngienull_body() {
226272343Sngie	common_body h_null
227272343Sngie}
228272343Sngie
229272343Sngienull_cleanup() {
230272343Sngie	common_cleanup
231272343Sngie}
232272343Sngie
233272343Sngieatf_test_case sha1_hmac cleanup
234272343Sngiesha1_hmac_head() {
235272343Sngie	common_head "Test SHA1_HMAC crypto"
236272343Sngie}
237272343Sngie
238272343Sngiesha1_hmac_body() {
239272343Sngie	common_body h_sha1hmac
240272343Sngie}
241272343Sngie
242272343Sngiesha1_hmac_cleanup() {
243272343Sngie	common_cleanup
244272343Sngie}
245272343Sngie
246272343Sngieatf_test_case xcbcmac cleanup
247272343Sngiexcbcmac_head() {
248272343Sngie	common_head "Test XCBC_MAC_96 crypto"
249272343Sngie}
250272343Sngie
251272343Sngiexcbcmac_body() {
252272343Sngie	common_body h_xcbcmac
253272343Sngie}
254272343Sngie
255272343Sngiexcbcmac_cleanup() {
256272343Sngie	common_cleanup
257272343Sngie}
258272343Sngie
259272343Sngieatf_init_test_cases() {
260272343Sngie	RUMP_SERVER="unix://t_opencrypto_socket" ; export RUMP_SERVER
261272343Sngie
262272343Sngie	atf_add_test_case arc4
263272343Sngie	atf_add_test_case camellia
264272343Sngie	atf_add_test_case cbcdes
265272343Sngie	atf_add_test_case comp
266272343Sngie	atf_add_test_case comp_deflate
267272343Sngie	atf_add_test_case comp_zlib_rnd
268272343Sngie	atf_add_test_case aesctr1
269272343Sngie	atf_add_test_case aesctr2
270272343Sngie	atf_add_test_case gcm
271272343Sngie	atf_add_test_case md5
272272343Sngie	atf_add_test_case md5_hmac
273272343Sngie	atf_add_test_case null
274272343Sngie	atf_add_test_case sha1_hmac
275272343Sngie	atf_add_test_case xcbcmac
276272343Sngie}
277