#!/bin/sh -1#2# Copyright (c) 2014 The FreeBSD Foundation3# All rights reserved.4# Copyright 2019 Enji Cooper5#6# This software was developed by John-Mark Gurney under7# the sponsorship from the FreeBSD Foundation.8# Redistribution and use in source and binary forms, with or without9# modification, are permitted provided that the following conditions10# are met:11# 1. Redistributions of source code must retain the above copyright12# notice, this list of conditions and the following disclaimer.13# 2. Redistributions in binary form must reproduce the above copyright14# notice, this list of conditions and the following disclaimer in the15# documentation and/or other materials provided with the distribution.16#17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27# SUCH DAMAGE.28#29#3031: ${PYTHON=python3}3233if [ ! -d /usr/local/share/nist-kat ]; then34echo "1..0 # SKIP: nist-kat package not installed for test vectors"35exit 036fi3738if ! $PYTHON -c "from dpkt import dpkt"; then39echo "1..0 # SKIP: py-dpkt package not installed"40exit 041fi4243loaded_modules=44cleanup_tests()45{46trap - EXIT INT TERM4748set +e4950if [ -n "$oldcdas" ]; then51sysctl "$oldcdas" 2>/dev/null52fi5354# Unload modules in reverse order55for loaded_module in $(echo $loaded_modules | tr ' ' '\n' | sort -r); do56kldunload $loaded_module57done58}59trap cleanup_tests EXIT INT TERM6061cpu_type="$(uname -p)"62cpu_module=6364case ${cpu_type} in65aarch64)66cpu_module="nexus/armv8crypto nexus/ossl"67;;68amd64|i386)69cpu_module="nexus/aesni nexus/ossl"70;;71esac7273for required_module in $cpu_module cryptodev; do74if ! kldstat -q -m $required_module; then75module_to_load=${required_module#nexus/}76if ! kldload ${module_to_load}; then77echo "1..0 # SKIP: could not load ${module_to_load}"78exit 079fi80loaded_modules="$loaded_modules $required_module"81fi82done8384cdas_sysctl=kern.crypto.allow_soft85if ! oldcdas=$(sysctl -e $cdas_sysctl); then86echo "1..0 # SKIP: could not resolve sysctl: $cdas_sysctl"87exit 088fi89if ! sysctl $cdas_sysctl=1; then90echo "1..0 # SKIP: could not enable /dev/crypto access via $cdas_sysctl sysctl."91exit 092fi9394echo "1..1"95if "$PYTHON" $(dirname $0)/cryptotest.py $CRYPTOTEST_ARGS; then96echo "ok 1"97else98echo "not ok 1"99fi100101102