11#! /bin/bash
2+ # aes-cmd-test.sh
3+ # AES encryption test for wolfProvider
4+ #
5+ # Copyright (C) 2006-2024 wolfSSL Inc.
6+ #
7+ # This file is part of wolfProvider.
8+ #
9+ # wolfProvider is free software; you can redistribute it and/or modify
10+ # it under the terms of the GNU General Public License as published by
11+ # the Free Software Foundation; either version 3 of the License, or
12+ # (at your option) any later version.
13+ #
14+ # wolfProvider is distributed in the hope that it will be useful,
15+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ # GNU General Public License for more details.
18+ #
19+ # You should have received a copy of the GNU General Public License
20+ # along with this program; if not, write to the Free Software
21+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
222
323# Set up environment
424SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
@@ -16,8 +36,17 @@ source "${UTILS_DIR}/utils-wolfprovider.sh"
1636# Initialize the environment
1737init_wolfprov
1838
19- # Fail flag
39+ # Fail flags
2040FAIL=0
41+ FORCE_FAIL=0
42+ FORCE_FAIL_PASSED=0
43+
44+ # Check for force fail parameter
45+ if [ " $1 " = " WOLFPROV_FORCE_FAIL=1" ]; then
46+ export WOLFPROV_FORCE_FAIL=1
47+ FORCE_FAIL=1
48+ echo -e " \nForce fail mode enabled for AES tests"
49+ fi
2150
2251# Verify wolfProvider is properly loaded
2352echo -e " \nVerifying wolfProvider configuration:"
@@ -27,7 +56,7 @@ if ! $OPENSSL_BIN list -providers | grep -q "wolf"; then
2756 $OPENSSL_BIN list -providers
2857 FAIL=1
2958else
30- echo " [PASS] wolfProvider is properly configured"
59+ echo " wolfProvider is properly configured"
3160fi
3261
3362# Print environment for verification
@@ -40,6 +69,14 @@ echo "OPENSSL_BIN: ${OPENSSL_BIN}"
4069mkdir -p aes_outputs
4170echo " This is test data for AES encryption testing." > test.txt
4271
72+ # Helper function to handle force fail checks
73+ check_force_fail () {
74+ if [ $FORCE_FAIL -eq 1 ]; then
75+ echo " [PASS] Test passed when force fail was enabled"
76+ FORCE_FAIL_PASSED=1
77+ fi
78+ }
79+
4380# Arrays for test configurations
4481KEY_SIZES=(" 128" " 192" " 256" )
4582# Only include modes supported by wolfProvider
@@ -83,6 +120,7 @@ for key_size in "${KEY_SIZES[@]}"; do
83120 if [ $FAIL -eq 0 ]; then
84121 if cmp -s " test.txt" " $dec_file " ; then
85122 echo " [PASS] Interop AES-${key_size} -${mode} : OpenSSL encrypt, wolfProvider decrypt"
123+ check_force_fail
86124 else
87125 echo " [FAIL] Interop AES-${key_size} -${mode} : OpenSSL encrypt, wolfProvider decrypt"
88126 FAIL=1
@@ -111,6 +149,7 @@ for key_size in "${KEY_SIZES[@]}"; do
111149 if [ $FAIL -eq 0 ]; then
112150 if cmp -s " test.txt" " $dec_file " ; then
113151 echo " [PASS] Interop AES-${key_size} -${mode} : wolfProvider encrypt, OpenSSL decrypt"
152+ check_force_fail
114153 else
115154 echo " [FAIL] Interop AES-${key_size} -${mode} : wolfProvider encrypt, OpenSSL decrypt"
116155 FAIL=1
@@ -121,11 +160,22 @@ for key_size in "${KEY_SIZES[@]}"; do
121160 done
122161done
123162
124- # Change end of script to check FAIL flag
125- if [ $FAIL -eq 0 ]; then
126- echo -e " \n=== All AES tests completed successfully ==="
127- exit 0
163+ if [ $FORCE_FAIL -eq 1 ]; then
164+ if [ $FORCE_FAIL_PASSED -eq 1 ]; then
165+ echo -e " \n=== AES Tests Failed With Force Fail Enabled ==="
166+ echo " ERROR: Some tests passed when they should have failed"
167+ exit 1
168+ else
169+ echo -e " \n=== AES Tests Passed With Force Fail Enabled ==="
170+ echo " SUCCESS: All tests failed as expected"
171+ exit 0
172+ fi
128173else
129- echo -e " \n=== AES tests completed with failures ==="
130- exit 1
174+ if [ $FAIL -eq 0 ]; then
175+ echo -e " \n=== All AES tests completed successfully ==="
176+ exit 0
177+ else
178+ echo -e " \n=== AES tests completed with failures ==="
179+ exit 1
180+ fi
131181fi
0 commit comments