1 1.11 riastrad # $NetBSD: t_opencrypto.sh,v 1.11 2025/04/18 23:35:31 riastradh Exp $ 2 1.1 pgoyette # 3 1.1 pgoyette # Copyright (c) 2014 The NetBSD Foundation, Inc. 4 1.1 pgoyette # All rights reserved. 5 1.1 pgoyette # 6 1.1 pgoyette # Redistribution and use in source and binary forms, with or without 7 1.1 pgoyette # modification, are permitted provided that the following conditions 8 1.1 pgoyette # are met: 9 1.1 pgoyette # 1. Redistributions of source code must retain the above copyright 10 1.1 pgoyette # notice, this list of conditions and the following disclaimer. 11 1.1 pgoyette # 2. Redistributions in binary form must reproduce the above copyright 12 1.1 pgoyette # notice, this list of conditions and the following disclaimer in the 13 1.1 pgoyette # documentation and/or other materials provided with the distribution. 14 1.1 pgoyette # 15 1.1 pgoyette # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 1.1 pgoyette # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 1.1 pgoyette # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 1.1 pgoyette # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 1.1 pgoyette # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 1.1 pgoyette # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 1.1 pgoyette # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 1.1 pgoyette # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 1.1 pgoyette # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 1.1 pgoyette # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 1.1 pgoyette # POSSIBILITY OF SUCH DAMAGE. 26 1.1 pgoyette # 27 1.1 pgoyette 28 1.1 pgoyette # Start a rumpserver, load required modules, and set requires sysctl vars 29 1.1 pgoyette 30 1.1 pgoyette start_rump() { 31 1.1 pgoyette rump_libs="-l rumpvfs -l rumpdev -l rumpdev_opencrypto" 32 1.1 pgoyette rump_libs="${rump_libs} -l rumpkern_z -l rumpkern_crypto" 33 1.1 pgoyette 34 1.1 pgoyette rump_server ${rump_libs} ${RUMP_SERVER} || \ 35 1.1 pgoyette return 1 36 1.1 pgoyette 37 1.1 pgoyette rump.sysctl -w kern.cryptodevallowsoft=-1 && \ 38 1.1 pgoyette return 0 39 1.1 pgoyette 40 1.1 pgoyette rump.halt 41 1.1 pgoyette 42 1.1 pgoyette return 1 43 1.1 pgoyette } 44 1.1 pgoyette 45 1.1 pgoyette common_head() { 46 1.1 pgoyette atf_set descr "$1" 47 1.1 pgoyette atf_set timeout 10 48 1.1 pgoyette atf_set require.progs rump_server rump.sysctl rump.halt 49 1.1 pgoyette } 50 1.1 pgoyette 51 1.1 pgoyette common_body() { 52 1.1 pgoyette local status 53 1.1 pgoyette 54 1.1 pgoyette start_rump || atf_skip "Cannot set-up rump environment" 55 1.1 pgoyette LD_PRELOAD="/usr/lib/librumphijack.so" ; export LD_PRELOAD 56 1.1 pgoyette RUMPHIJACK="blanket=/dev/crypto" ; export RUMPHIJACK 57 1.1 pgoyette $(atf_get_srcdir)/$1 58 1.1 pgoyette status=$? 59 1.1 pgoyette unset RUMPHIJACK 60 1.1 pgoyette unset LD_PRELOAD 61 1.1 pgoyette if [ $status -ne 0 ] ; then 62 1.1 pgoyette atf_fail "$1 returned non-zero status, check output/error" 63 1.1 pgoyette fi 64 1.1 pgoyette } 65 1.1 pgoyette 66 1.1 pgoyette common_cleanup() { 67 1.1 pgoyette unset RUMPHIJACK 68 1.1 pgoyette unset LD_PRELOAD 69 1.1 pgoyette rump.halt 70 1.1 pgoyette } 71 1.1 pgoyette 72 1.1 pgoyette atf_test_case arc4 cleanup 73 1.1 pgoyette arc4_head() { 74 1.1 pgoyette common_head "Test ARC4 crypto" 75 1.1 pgoyette } 76 1.1 pgoyette 77 1.1 pgoyette arc4_body() { 78 1.2 pgoyette atf_skip "ARC4 not implemented by swcrypto" 79 1.1 pgoyette common_body h_arc4 80 1.1 pgoyette } 81 1.1 pgoyette 82 1.1 pgoyette arc4_cleanup() { 83 1.6 pgoyette # No cleanup required since test is skipped. Trying to run rump.halt 84 1.6 pgoyette # at this point fails, causing the ATF environment to erroneously 85 1.6 pgoyette # report a failed test! 86 1.6 pgoyette # 87 1.6 pgoyette # common_cleanup 88 1.1 pgoyette } 89 1.1 pgoyette 90 1.1 pgoyette atf_test_case camellia cleanup 91 1.1 pgoyette camellia_head() { 92 1.1 pgoyette common_head "Test CAMELLIA_CBC crypto" 93 1.1 pgoyette } 94 1.1 pgoyette 95 1.1 pgoyette camellia_body() { 96 1.1 pgoyette common_body h_camellia 97 1.1 pgoyette } 98 1.1 pgoyette 99 1.1 pgoyette camellia_cleanup() { 100 1.1 pgoyette common_cleanup 101 1.1 pgoyette } 102 1.1 pgoyette 103 1.1 pgoyette atf_test_case cbcdes cleanup 104 1.1 pgoyette cbcdes_head() { 105 1.5 prlw1 common_head "Test DES_CBC crypto" 106 1.1 pgoyette } 107 1.1 pgoyette 108 1.1 pgoyette cbcdes_body() { 109 1.1 pgoyette common_body h_cbcdes 110 1.1 pgoyette } 111 1.1 pgoyette 112 1.1 pgoyette cbcdes_cleanup() { 113 1.1 pgoyette common_cleanup 114 1.1 pgoyette } 115 1.1 pgoyette 116 1.7 knakahar atf_test_case cbc3des cleanup 117 1.7 knakahar cbc3des_head() { 118 1.7 knakahar common_head "Test 3DES_CBC crypto" 119 1.7 knakahar } 120 1.7 knakahar 121 1.7 knakahar cbc3des_body() { 122 1.7 knakahar common_body h_cbc3des 123 1.7 knakahar } 124 1.7 knakahar 125 1.7 knakahar cbc3des_cleanup() { 126 1.7 knakahar common_cleanup 127 1.7 knakahar } 128 1.7 knakahar 129 1.1 pgoyette atf_test_case comp cleanup 130 1.1 pgoyette comp_head() { 131 1.1 pgoyette common_head "Test GZIP_COMP Compression" 132 1.1 pgoyette } 133 1.1 pgoyette 134 1.1 pgoyette comp_body() { 135 1.1 pgoyette common_body h_comp 136 1.1 pgoyette } 137 1.1 pgoyette 138 1.1 pgoyette comp_cleanup() { 139 1.1 pgoyette common_cleanup 140 1.1 pgoyette } 141 1.1 pgoyette 142 1.1 pgoyette atf_test_case comp_deflate cleanup 143 1.1 pgoyette comp_deflate_head() { 144 1.1 pgoyette common_head "Test DEFLATE_COMP Compression" 145 1.1 pgoyette } 146 1.1 pgoyette 147 1.1 pgoyette comp_deflate_body() { 148 1.1 pgoyette common_body h_comp_zlib 149 1.1 pgoyette } 150 1.1 pgoyette 151 1.1 pgoyette comp_deflate_cleanup() { 152 1.1 pgoyette common_cleanup 153 1.1 pgoyette } 154 1.1 pgoyette 155 1.1 pgoyette atf_test_case comp_zlib_rnd cleanup 156 1.1 pgoyette comp_zlib_rnd_head() { 157 1.1 pgoyette common_head "Test DEFLATE_COMP Compression with random data" 158 1.1 pgoyette } 159 1.1 pgoyette 160 1.1 pgoyette comp_zlib_rnd_body() { 161 1.1 pgoyette common_body h_comp_zlib_rnd 162 1.1 pgoyette } 163 1.1 pgoyette 164 1.1 pgoyette comp_zlib_rnd_cleanup() { 165 1.1 pgoyette common_cleanup 166 1.1 pgoyette } 167 1.1 pgoyette 168 1.1 pgoyette atf_test_case aesctr1 cleanup 169 1.1 pgoyette aesctr1_head() { 170 1.1 pgoyette common_head "Test AES_CTR crypto" 171 1.1 pgoyette } 172 1.1 pgoyette 173 1.1 pgoyette aesctr1_body() { 174 1.1 pgoyette common_body h_aesctr1 175 1.1 pgoyette } 176 1.1 pgoyette 177 1.1 pgoyette aesctr1_cleanup() { 178 1.1 pgoyette common_cleanup 179 1.1 pgoyette } 180 1.1 pgoyette 181 1.1 pgoyette atf_test_case aesctr2 cleanup 182 1.1 pgoyette aesctr2_head() { 183 1.1 pgoyette common_head "Test AES_CTR crypto" 184 1.1 pgoyette } 185 1.1 pgoyette 186 1.1 pgoyette aesctr2_body() { 187 1.1 pgoyette common_body h_aesctr2 188 1.1 pgoyette } 189 1.1 pgoyette 190 1.1 pgoyette aesctr2_cleanup() { 191 1.1 pgoyette common_cleanup 192 1.1 pgoyette } 193 1.1 pgoyette 194 1.7 knakahar atf_test_case aescbc cleanup 195 1.7 knakahar aescbc_head() { 196 1.7 knakahar common_head "Test AES_CBC crypto" 197 1.7 knakahar } 198 1.7 knakahar 199 1.7 knakahar aescbc_body() { 200 1.7 knakahar common_body h_aescbc 201 1.7 knakahar } 202 1.7 knakahar 203 1.7 knakahar aescbc_cleanup() { 204 1.7 knakahar common_cleanup 205 1.7 knakahar } 206 1.7 knakahar 207 1.1 pgoyette atf_test_case gcm cleanup 208 1.1 pgoyette gcm_head() { 209 1.1 pgoyette common_head "Test AES_GCM_16 crypto" 210 1.1 pgoyette } 211 1.1 pgoyette 212 1.1 pgoyette gcm_body() { 213 1.1 pgoyette common_body h_gcm 214 1.1 pgoyette } 215 1.1 pgoyette 216 1.1 pgoyette gcm_cleanup() { 217 1.1 pgoyette common_cleanup 218 1.1 pgoyette } 219 1.1 pgoyette 220 1.1 pgoyette atf_test_case md5 cleanup 221 1.1 pgoyette md5_head() { 222 1.1 pgoyette common_head "Test MD5 crypto" 223 1.1 pgoyette } 224 1.1 pgoyette 225 1.1 pgoyette md5_body() { 226 1.1 pgoyette common_body h_md5 227 1.1 pgoyette } 228 1.1 pgoyette 229 1.1 pgoyette md5_cleanup() { 230 1.1 pgoyette common_cleanup 231 1.1 pgoyette } 232 1.1 pgoyette 233 1.1 pgoyette atf_test_case md5_hmac cleanup 234 1.1 pgoyette md5_hmac_head() { 235 1.1 pgoyette common_head "Test MD5_HMAC crypto" 236 1.1 pgoyette } 237 1.1 pgoyette 238 1.1 pgoyette md5_hmac_body() { 239 1.1 pgoyette common_body h_md5hmac 240 1.1 pgoyette } 241 1.1 pgoyette 242 1.1 pgoyette md5_hmac_cleanup() { 243 1.1 pgoyette common_cleanup 244 1.1 pgoyette } 245 1.1 pgoyette 246 1.1 pgoyette atf_test_case null cleanup 247 1.1 pgoyette null_head() { 248 1.1 pgoyette common_head "Test NULL_CBC crypto" 249 1.1 pgoyette } 250 1.1 pgoyette 251 1.1 pgoyette null_body() { 252 1.1 pgoyette common_body h_null 253 1.1 pgoyette } 254 1.1 pgoyette 255 1.1 pgoyette null_cleanup() { 256 1.1 pgoyette common_cleanup 257 1.1 pgoyette } 258 1.1 pgoyette 259 1.4 pgoyette atf_test_case sha1_hmac cleanup 260 1.4 pgoyette sha1_hmac_head() { 261 1.4 pgoyette common_head "Test SHA1_HMAC crypto" 262 1.4 pgoyette } 263 1.4 pgoyette 264 1.4 pgoyette sha1_hmac_body() { 265 1.4 pgoyette common_body h_sha1hmac 266 1.4 pgoyette } 267 1.4 pgoyette 268 1.4 pgoyette sha1_hmac_cleanup() { 269 1.4 pgoyette common_cleanup 270 1.4 pgoyette } 271 1.4 pgoyette 272 1.9 hikaru atf_test_case sha2_hmac cleanup 273 1.9 hikaru sha2_hmac_head() { 274 1.9 hikaru common_head "Test SHA2_HMAC crypto" 275 1.9 hikaru } 276 1.9 hikaru 277 1.9 hikaru sha2_hmac_body() { 278 1.9 hikaru common_body h_sha2hmac 279 1.9 hikaru } 280 1.9 hikaru 281 1.9 hikaru sha2_hmac_cleanup() { 282 1.9 hikaru common_cleanup 283 1.9 hikaru } 284 1.9 hikaru 285 1.1 pgoyette atf_test_case xcbcmac cleanup 286 1.1 pgoyette xcbcmac_head() { 287 1.1 pgoyette common_head "Test XCBC_MAC_96 crypto" 288 1.1 pgoyette } 289 1.1 pgoyette 290 1.1 pgoyette xcbcmac_body() { 291 1.1 pgoyette common_body h_xcbcmac 292 1.1 pgoyette } 293 1.1 pgoyette 294 1.1 pgoyette xcbcmac_cleanup() { 295 1.1 pgoyette common_cleanup 296 1.1 pgoyette } 297 1.1 pgoyette 298 1.8 knakahar atf_test_case ioctl cleanup 299 1.8 knakahar ioctl_head() { 300 1.8 knakahar common_head "Test ioctl for /dev/crypto" 301 1.8 knakahar } 302 1.8 knakahar 303 1.8 knakahar ioctl_body() { 304 1.10 riastrad case `uname -p` in 305 1.11 riastrad sparc) atf_expect_fail "PR port-sparc/59311:" \ 306 1.10 riastrad " t_opencrypto:ioctl test is failing" 307 1.10 riastrad ;; 308 1.10 riastrad esac 309 1.8 knakahar common_body h_ioctl 310 1.8 knakahar } 311 1.8 knakahar 312 1.8 knakahar ioctl_cleanup() { 313 1.8 knakahar common_cleanup 314 1.8 knakahar } 315 1.8 knakahar 316 1.1 pgoyette atf_init_test_cases() { 317 1.1 pgoyette RUMP_SERVER="unix://t_opencrypto_socket" ; export RUMP_SERVER 318 1.1 pgoyette 319 1.1 pgoyette atf_add_test_case arc4 320 1.1 pgoyette atf_add_test_case camellia 321 1.1 pgoyette atf_add_test_case cbcdes 322 1.7 knakahar atf_add_test_case cbc3des 323 1.1 pgoyette atf_add_test_case comp 324 1.1 pgoyette atf_add_test_case comp_deflate 325 1.1 pgoyette atf_add_test_case comp_zlib_rnd 326 1.1 pgoyette atf_add_test_case aesctr1 327 1.1 pgoyette atf_add_test_case aesctr2 328 1.7 knakahar atf_add_test_case aescbc 329 1.1 pgoyette atf_add_test_case gcm 330 1.1 pgoyette atf_add_test_case md5 331 1.1 pgoyette atf_add_test_case md5_hmac 332 1.1 pgoyette atf_add_test_case null 333 1.4 pgoyette atf_add_test_case sha1_hmac 334 1.9 hikaru atf_add_test_case sha2_hmac 335 1.1 pgoyette atf_add_test_case xcbcmac 336 1.8 knakahar atf_add_test_case ioctl 337 1.1 pgoyette } 338