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