Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# wolfPSA is already a manifest module (e.g. CI, where
# zephyr-test.sh injects it into the manifest), to avoid
# registering it twice.
# MODULE_CONFIG_ARGS extra west-build args for psa_consumer_mod

set -u

Expand All @@ -37,10 +38,13 @@ EXTRA_MODULE_ARG="${EXTRA_MODULE_ARG--DEXTRA_ZEPHYR_MODULES=${WOLFPSA_ROOT}}"
# psa_consumer_st reruns the consumer with CONFIG_WOLFPSA_THREAD_SAFE=n so the
# single-threaded baseline path (SINGLE_THREADED, no-op lock macros) is built
# and run in CI, not just the default thread-safe (=y) path.
# psa_consumer_mod reruns it on the wolfSSL module's own config, plus
# MODULE_CONFIG_ARGS (CI sets CONFIG_WOLFPSA_AES_FAST=y for wolfSSL 5.9.4).
TARGETS="
psa_smoke|${WOLFPSA_ROOT}/zephyr/samples/psa_smoke|sample
psa_consumer|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest
psa_consumer_st|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest|-DCONFIG_WOLFPSA_THREAD_SAFE=n
psa_consumer_mod|${WOLFPSA_ROOT}/zephyr/tests/psa_consumer|ztest|-DEXTRA_CONF_FILE=module_config.conf ${MODULE_CONFIG_ARGS:-}
psa_concurrency|${WOLFPSA_ROOT}/zephyr/tests/psa_concurrency|ztest
psa_entropy|${WOLFPSA_ROOT}/zephyr/tests/psa_entropy|ztest
psa_transform|${WOLFPSA_ROOT}/zephyr/tests/psa_transform|ztest
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/zephyr-4.x/zephyr-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -z, --zephyr <version> Zephyr version tag (>= v4.3.0)
# --wolfssl-repo <url> wolfSSL repo URL (default: wolfSSL/wolfssl)
# --wolfssl-ref <ref> wolfSSL revision (default: master)
# --module-config-args <args> extra west-build args for psa_consumer_mod
# -h, --help Show this help
#
# Examples:
Expand All @@ -35,6 +36,7 @@ WOLFPSA_BRANCH="master"
ZEPHYR_VERSION="v4.4.0"
WOLFSSL_REPO="https://github.com/wolfSSL/wolfssl"
WOLFSSL_REF="master"
MODULE_CONFIG_ARGS=""

GHCR="ghcr.io/zephyrproject-rtos/zephyr-build"

Expand Down Expand Up @@ -64,6 +66,7 @@ while [[ $# -gt 0 ]]; do
-z|--zephyr) ZEPHYR_VERSION="$2"; shift 2 ;;
--wolfssl-repo) WOLFSSL_REPO="$2"; shift 2 ;;
--wolfssl-ref) WOLFSSL_REF="$2"; shift 2 ;;
--module-config-args) MODULE_CONFIG_ARGS="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
Expand All @@ -89,6 +92,7 @@ WOLFPSA_REPO="__WOLFPSA_REPO__"
WOLFPSA_BRANCH="__WOLFPSA_BRANCH__"
WOLFSSL_REPO="__WOLFSSL_REPO__"
WOLFSSL_REF="__WOLFSSL_REF__"
MODULE_CONFIG_ARGS="__MODULE_CONFIG_ARGS__"

cd /workdir

Expand Down Expand Up @@ -128,7 +132,7 @@ fi
# Both modules are in the manifest now, so the runner must NOT also add wolfPSA
# via EXTRA_ZEPHYR_MODULES.
echo "==> [container] Running the wolfPSA test suite..."
EXTRA_MODULE_ARG="" \
EXTRA_MODULE_ARG="" MODULE_CONFIG_ARGS="${MODULE_CONFIG_ARGS}" \
bash modules/crypto/wolfPSA/.github/scripts/run-tests.sh
INNER_SCRIPT
)
Expand All @@ -138,6 +142,7 @@ BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFPSA_REPO__/$WOLFPSA_REPO}"
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFPSA_BRANCH__/$WOLFPSA_BRANCH}"
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_REPO__/$WOLFSSL_REPO}"
BUILD_SCRIPT="${BUILD_SCRIPT//__WOLFSSL_REF__/$WOLFSSL_REF}"
BUILD_SCRIPT="${BUILD_SCRIPT//__MODULE_CONFIG_ARGS__/$MODULE_CONFIG_ARGS}"

cleanup() { docker rm -f "${CONTAINER_NAME}" 2>/dev/null || true; }
trap cleanup EXIT
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/build-config-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
modifiers: "-HAVE_AES_ECB +WOLFPSA_NO_AES_BITSLICED +WOLFSSL_AES_TOUCH_LINES"
- name: aes-fast
modifiers: "+WOLFPSA_NO_AES_BITSLICED +WOLFPSA_AES_FAST"
- name: aes-fast-gcm-table
modifiers: "+WOLFPSA_NO_AES_BITSLICED +WOLFPSA_AES_FAST +GCM_TABLE_4BIT"
- name: aes-ctr
modifiers: "-WOLFSSL_AES_COUNTER"
- name: aes-cfb
Expand Down Expand Up @@ -116,3 +118,20 @@ jobs:
# Fail on undefined symbols
LDFLAGS: -Wl,-z,defs
run: ./build-test/build-variant.sh "${{ matrix.config.name }}" ${{ matrix.config.modifiers }}

psa-config-policy:
name: psa_config.h policy / wolfSSL ${{ matrix.wolfssl-ref }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
wolfssl-ref: [ master, v5.9.4-stable ]
steps:
- name: Check out wolfPSA
uses: actions/checkout@v4

- name: Clone sibling wolfSSL
run: git clone --depth 1 --branch ${{ matrix.wolfssl-ref }} https://github.com/wolfSSL/wolfssl ../wolfssl

- name: Check accepted and refused configurations
run: ./build-test/psa-config-policy.sh ../wolfssl
8 changes: 7 additions & 1 deletion .github/workflows/zephyr-4.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
exclude:
- zephyr-ref: v4.5.0
wolfssl-ref: v5.9.4-stable
# wolfSSL 5.9.4's module config hard-codes GCM_SMALL, which wolfPSA
# accepts only with its waiver.
include:
- wolfssl-ref: v5.9.4-stable
module-config-args: -DCONFIG_WOLFPSA_AES_FAST=y
steps:
- name: Checkout wolfPSA CI driver
uses: actions/checkout@v5
Expand Down Expand Up @@ -62,4 +67,5 @@ jobs:
-r "${{ steps.src.outputs.repo }}" \
-b "${{ steps.src.outputs.ref }}" \
-z "${{ matrix.zephyr-ref }}" \
--wolfssl-ref "${{ matrix.wolfssl-ref }}"
--wolfssl-ref "${{ matrix.wolfssl-ref }}" \
--module-config-args "${{ matrix.module-config-args }}"
136 changes: 136 additions & 0 deletions build-test/psa-config-policy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/sh
#
# Preprocess src/psa_config.h against a wolfSSL tree and check which AES and
# GHASH configurations it accepts and refuses.
#
# Usage: build-test/psa-config-policy.sh [WOLFSSL_PATH]

set -u

repo_root="$(cd "$(dirname "$0")/.." && pwd)"
wolfssl="${1:-${repo_root}/../wolfssl}"
cc="${CC:-cc}"
fails=0

# wolfcrypt/fips.h ships only with a FIPS bundle; an empty one lets the
# HAVE_FIPS cases preprocess against a plain wolfSSL tree.
stub="$(mktemp -d)"
trap 'rm -rf "${stub}"' EXIT
mkdir -p "${stub}/wolfssl/wolfcrypt"
: > "${stub}/wolfssl/wolfcrypt/fips.h"

# check <"pass" | fragment of the expected wolfPSA #error> [-DFLAG ...]
check() {
want="$1"
shift
out="$(echo '#include "psa_config.h"' | "${cc}" -x c -fsyntax-only \
-I"${repo_root}/build-test" -I"${repo_root}/src" -I"${stub}" \
-I"${wolfssl}" \
-DWOLFSSL_USER_SETTINGS -DHAVE_AESGCM -DHAVE_AES_ECB "$@" - 2>&1)"
rc=$?
if [ "${want}" = "pass" ]; then
[ "${rc}" -eq 0 ] && ok=1 || ok=0
else
case "${out}" in
*"wolfPSA: ${want}"*) ok=1 ;;
*) ok=0 ;;
esac
fi
if [ "${ok}" -eq 1 ]; then
echo "ok $*"
else
echo "FAIL expected '${want}': $*"
echo "${out}" | grep -m3 "error"
fails=$((fails + 1))
fi
}

ghash="GHASH is not constant time:"
nobs="-DWOLFPSA_NO_AES_BITSLICED"
hwaes="-DWOLF_CRYPTO_CB -DWOLF_CRYPTO_CB_ONLY_AES"
# Backends that every FIPS aes.c, FIPS v5 on, and none of them carry.
hwall="-DWOLFSSL_PIC32MZ_CRYPT"
hwv5="-DWOLFSSL_DEVCRYPTO_AES"
hwnofips="-DWOLFSSL_PSOC6_CRYPTO"
fips2="-DHAVE_FIPS -DHAVE_FIPS_VERSION=2 -DHAVE_FIPS_VERSION_MAJOR=2"
fips5="-DHAVE_FIPS -DHAVE_FIPS_VERSION=5 -DHAVE_FIPS_VERSION_MAJOR=5"
fips6="-DHAVE_FIPS -DHAVE_FIPS_VERSION=6 -DHAVE_FIPS_VERSION_MAJOR=6"
neon="-DWOLFSSL_ARMASM -D__aarch64__ -DWOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP"
a32="-DWOLFSSL_ARMASM -U__aarch64__ -DWOLFSSL_AES_TOUCH_LINES"
t2="${a32} -DWOLFSSL_ARMASM_THUMB2"
nohw="${a32} -DWOLFSSL_ARMASM_NO_HW_CRYPTO"
nogcm="-UHAVE_AESGCM"
if grep -q WC_AES_TOUCH_LINES_C_CORE "${wolfssl}/wolfcrypt/src/aes.c"; then
a32_nogcm="pass"
else
a32_nogcm="the Arm AES assembly"
fi

check pass
check pass ${nobs} -DWOLFSSL_AES_TOUCH_LINES
check pass ${nobs} ${hwaes}
check "the AES backend is not constant time" ${nobs}
check "the AES backend is not constant time" ${nobs} -DWOLFPSA_AES_HW_BACKEND
check "${ghash}" ${nobs} ${hwaes} -DGCM_TABLE
check "${ghash}" -DGCM_SMALL
check "${ghash}" -DGCM_WORD32
check "${ghash}" -DGCM_TABLE
check "${ghash}" -DGCM_TABLE -DWOLFPSA_GHASH_HW_BACKEND
check "${ghash}" -DGCM_TABLE_4BIT
check "${ghash}" -DAES_GCM_GMULT_NCT
check "GHASH is not constant time without a 64-bit type" -DNO_64BIT
check "the Arm AES assembly" -DWOLFSSL_ARMASM
check pass ${nobs} ${neon}
check pass ${nobs} ${neon} -DGCM_TABLE_4BIT
check pass ${nobs} ${neon} -DGCM_TABLE
check "the Arm AES assembly" ${nobs} ${neon} -U__aarch64__
check "the Arm AES assembly" ${nobs} ${neon} -DWOLFSSL_ARMASM_NO_NEON
check "the Arm AES assembly" ${nobs} ${neon} ${fips6}
check "the Arm AES assembly" ${nobs} -DWOLFSSL_ARMASM -DWOLFPSA_ARM64_NEON_CT
check "${ghash}" ${nobs} ${neon} -DGCM_SMALL
check "${a32_nogcm}" ${nobs} ${t2} ${nogcm}
check "${a32_nogcm}" ${nobs} ${nohw} ${nogcm}
check "the Arm AES assembly" ${nobs} ${t2}
check "the Arm AES assembly" ${nobs} ${nohw}
check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} ${fips6}
check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} -UWOLFSSL_AES_TOUCH_LINES
check "the Arm AES assembly" ${nobs} ${a32} ${nogcm}
check "the Arm AES assembly" ${nobs} ${t2} ${nogcm} -D__aarch64__
check "the Arm AES assembly" ${nobs} -DWOLFSSL_ARMASM -U__aarch64__ \
-DWOLFPSA_ARM32_TOUCH_LINES_CT ${nogcm}
check "the PowerPC AES assembly" -DWOLFSSL_PPC64_ASM
check "the PowerPC AES assembly" -DWOLFSSL_PPC32_ASM
check "the RISC-V assembly" -DWOLFSSL_RISCV_ASM
check "the RISC-V assembly" ${nobs} ${hwaes} -DWOLFSSL_RISCV_ASM
check "the RISC-V assembly" -DWOLFSSL_RISCV_ASM -DWOLFPSA_RISCV_CRYPTO_CT
check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM
check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM
check pass ${nobs} -DWOLFSSL_RISCV_ASM -DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM \
-DGCM_TABLE_4BIT
check pass ${nobs} ${hwnofips}

check "AES in FIPS modules before v6" ${fips5}
check "GHASH in FIPS v2 is not constant time" ${fips2} ${nobs} ${hwall}
check "AES in FIPS modules before v6" ${fips2} ${nobs} ${hwv5}
check "GHASH in FIPS v5 is constant time only under" ${fips5} ${nobs} ${hwv5}
check pass ${fips5} ${nobs} ${hwv5} -DAES_GCM_GMULT_CT
check "AES in FIPS modules before v6" ${fips5} ${nobs} ${hwaes} \
-DAES_GCM_GMULT_CT
check pass ${fips6}
check pass ${fips6} ${nobs} ${hwv5}
check "the AES backend is not constant time" ${fips6} ${nobs} ${hwaes}
check "the RISC-V assembly" ${fips5} ${nobs} -DWOLFSSL_RISCV_ASM \
-DWOLFSSL_RISCV_SCALAR_CRYPTO_ASM -DAES_GCM_GMULT_CT
check "the RISC-V assembly" ${fips6} -DWOLFSSL_RISCV_ASM \
-DWOLFSSL_RISCV_VECTOR_CRYPTO_ASM
check pass -DWOLFPSA_AES_FAST ${fips2}
check pass -DWOLFPSA_AES_FAST ${fips5}

# WOLFPSA_AES_FAST waives each of the refusals above.
for flag in GCM_SMALL GCM_WORD32 GCM_TABLE GCM_TABLE_4BIT AES_GCM_GMULT_NCT \
NO_64BIT WOLFSSL_ARMASM WOLFSSL_PPC64_ASM WOLFSSL_PPC32_ASM \
WOLFSSL_RISCV_ASM; do
check pass -DWOLFPSA_AES_FAST "-D${flag}"
done

[ "${fails}" -eq 0 ]
99 changes: 86 additions & 13 deletions src/psa_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define WOLFPSA_CONFIG_H

#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/version.h>

#if defined(WOLFSSL_PSA_ENGINE) && !defined(NO_AES)

Expand All @@ -38,10 +40,11 @@
* at W = 64 down to 1,920 at W = 8
* WOLFSSL_AES_TOUCH_LINES every lookup touches each cache line of the
* table; sizeof(Aes) is unchanged
* a hardware AES core the list below, which compiles no software
* tables. WOLFSSL_AESNI and WOLFSSL_ESP32_CRYPT
* are absent: both keep the T-table core as a
* runtime fallback
* a listed backend the list below: hardware AES cores, the RISC-V
* AES instructions and the AArch64 NEON core, none
* with a table in memory. WOLFSSL_AESNI and
* WOLFSSL_ESP32_CRYPT are absent: both keep the
* T-table core as a runtime fallback
* WOLFPSA_AES_FAST waives the check and accepts the T-table core:
* faster, not constant time, not PSA compliant
*/
Expand All @@ -50,20 +53,90 @@
* outside would otherwise satisfy the policy check below on any build. */
#undef WOLFPSA_AES_HW_BACKEND

#if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM) || \
defined(FREESCALE_LTC) || defined(FREESCALE_MMCAU) || \
defined(WOLFSSL_SILABS_SE_ACCEL) || defined(WOLFSSL_PSOC6_CRYPTO) || \
defined(WOLFSSL_AFALG) || defined(WOLFSSL_DEVCRYPTO_AES) || \
/* FIPS v2 and v5 have no RISC-V AES, and the older port in v6 runs a branching
* GHASH unless its carry-less multiply macros are also set. */
#undef WOLFPSA_RISCV_CRYPTO_CT
#if defined(WOLFSSL_RISCV_ASM) && \
Comment thread
padelsbach marked this conversation as resolved.
Resolved
(defined(WOLFSSL_RISCV_SCALAR_CRYPTO_ASM) || \
defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM)) && !defined(HAVE_FIPS)
#define WOLFPSA_RISCV_CRYPTO_CT
#endif

/* The AArch64 NEON AES and GHASH keep their tables in registers. wolfSSL 5.9.0
* added WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP; no FIPS aes.c up to v6 has it. */
#undef WOLFPSA_ARM64_NEON_CT
#if defined(WOLFSSL_ARMASM) && defined(__aarch64__) && \
!defined(WOLFSSL_ARMASM_NO_NEON) && \
defined(WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP) && !defined(HAVE_FIPS) && \
LIBWOLFSSL_VERSION_HEX >= 0x05009000
#define WOLFPSA_ARM64_NEON_CT
#endif

/* wolfSSL after 5.9.4 (first to define WOLFSSL_AES_TABLE_SECTION) runs this
* AES on the C touch-lines core; its GHASH stays on the table assembly. */
#undef WOLFPSA_ARM32_TOUCH_LINES_CT
#if defined(WOLFSSL_ARMASM) && !defined(__aarch64__) && \
(defined(WOLFSSL_ARMASM_THUMB2) || \
defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) && \
defined(WOLFSSL_AES_TOUCH_LINES) && !defined(HAVE_AESGCM) && \
!defined(HAVE_FIPS) && (defined(WOLFSSL_AES_TABLE_SECTION) || \
LIBWOLFSSL_VERSION_HEX > 0x05009004)
#define WOLFPSA_ARM32_TOUCH_LINES_CT
#endif

/* Grouped by the FIPS aes.c that has them: every version, v5 on, none. */
#if defined(FREESCALE_LTC) || defined(FREESCALE_MMCAU) || \
defined(WOLFSSL_PIC32MZ_CRYPT) || defined(WOLFSSL_NRF51_AES) || \
defined(WOLFSSL_SCE) || defined(HAVE_COLDFIRE_SEC) || \
defined(WOLF_CRYPTO_CB_ONLY_AES)
defined(HAVE_COLDFIRE_SEC) || \
((!defined(HAVE_FIPS) || FIPS_VERSION3_GE(5,0,0)) && \
(defined(WOLFSSL_SILABS_SE_ACCEL) || defined(WOLFSSL_AFALG) || \
defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_SCE))) || \
(!defined(HAVE_FIPS) && \
(defined(WOLFSSL_PSOC6_CRYPTO) || defined(WOLF_CRYPTO_CB_ONLY_AES))) || \
defined(WOLFPSA_RISCV_CRYPTO_CT) || defined(WOLFPSA_ARM64_NEON_CT)
#define WOLFPSA_AES_HW_BACKEND
#endif

#if !defined(WOLFPSA_AES_FAST) && !defined(WC_AES_BITSLICED) && \
!defined(WOLFSSL_AES_TOUCH_LINES) && !defined(WOLFPSA_AES_HW_BACKEND)
#error "wolfPSA: AES backend is not constant time. Select WC_AES_BITSLICED or WOLFSSL_AES_TOUCH_LINES, or define WOLFPSA_AES_FAST to accept the T-table core."
/* These run GHASH in assembly, except GHASH() under GCM_SMALL on AArch64,
* which keeps the branching C GMULT. */
#undef WOLFPSA_GHASH_HW_BACKEND
#if defined(WOLFPSA_RISCV_CRYPTO_CT) || \
(defined(WOLFPSA_ARM64_NEON_CT) && !defined(GCM_SMALL))
#define WOLFPSA_GHASH_HW_BACKEND
#endif

#ifndef WOLFPSA_AES_FAST
#if defined(WOLFSSL_ARMASM) && !defined(WOLFPSA_ARM64_NEON_CT) && \
!defined(WOLFPSA_ARM32_TOUCH_LINES_CT)
#error "wolfPSA: the Arm AES assembly is not constant time: it falls back to T-table lookups, whose timing depends on the key and data. Outside FIPS, define WOLFSSL_ARMASM_NEON_NO_TABLE_LOOKUP on AArch64 with NEON on (wolfSSL 5.9.0 or later), or WOLFSSL_AES_TOUCH_LINES on 32-bit Thumb-2 or WOLFSSL_ARMASM_NO_HW_CRYPTO without AES-GCM (wolfSSL after 5.9.4); or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif defined(WOLFSSL_PPC64_ASM) || defined(WOLFSSL_PPC32_ASM)
#error "wolfPSA: the PowerPC AES assembly is not constant time: it falls back to T-table lookups, whose timing depends on the key and data. Define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif defined(WOLFSSL_RISCV_ASM) && !defined(WOLFPSA_RISCV_CRYPTO_CT)
#error "wolfPSA: the RISC-V assembly is not constant time without the scalar or vector crypto extension, or in a FIPS module: it uses a T-table AES or a GHASH that branches on the key. Outside FIPS, define WOLFSSL_RISCV_SCALAR_CRYPTO_ASM or WOLFSSL_RISCV_VECTOR_CRYPTO_ASM if the CPU has one; or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \
!defined(WOLFPSA_AES_HW_BACKEND)
#error "wolfPSA: AES in FIPS modules before v6 is not constant time: they have neither WC_AES_BITSLICED nor WOLFSSL_AES_TOUCH_LINES. Use a hardware AES backend, or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif !defined(WC_AES_BITSLICED) && !defined(WOLFSSL_AES_TOUCH_LINES) && \
!defined(WOLFPSA_AES_HW_BACKEND)
#error "wolfPSA: the AES backend is not constant time: the T-table core's timing depends on the key and data. Select WC_AES_BITSLICED (constant time, larger Aes) or WOLFSSL_AES_TOUCH_LINES (constant time, slower), or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#endif

/* Only the 64-bit GHASH built with no GCM method set is masked; FIPS v5 masks
* it only under AES_GCM_GMULT_CT, and FIPS v2 never does. */
#if defined(HAVE_AESGCM) && !defined(WOLFPSA_GHASH_HW_BACKEND)
#if defined(GCM_SMALL) || defined(GCM_WORD32) || defined(GCM_TABLE) || \
defined(GCM_TABLE_4BIT) || defined(AES_GCM_GMULT_NCT)
#error "wolfPSA: GHASH is not constant time: GCM_SMALL and GCM_WORD32 branch on the hash key, and the GCM tables and AES_GCM_GMULT_NCT load from secret-indexed memory. Leave the GCM method unset and AES_GCM_GMULT_NCT undefined for the masked multiply (an LTC part without its GCM engine sets GCM_TABLE itself), or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif !defined(WORD64_AVAILABLE)
#error "wolfPSA: GHASH is not constant time without a 64-bit type: WORD64_AVAILABLE is off (NO_64BIT, or a 16-bit CPU), so wolfCrypt uses a multiply that branches on the hash key. Remove NO_64BIT, or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(5,0,0)
#error "wolfPSA: GHASH in FIPS v2 is not constant time. Define WOLFPSA_AES_FAST to trade the timing leak for speed."
#elif defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && \
!defined(AES_GCM_GMULT_CT)
#error "wolfPSA: GHASH in FIPS v5 is constant time only under AES_GCM_GMULT_CT. Define it, or define WOLFPSA_AES_FAST to trade the timing leak for speed."
#endif
#endif /* HAVE_AESGCM && !WOLFPSA_GHASH_HW_BACKEND */
#endif /* !WOLFPSA_AES_FAST */

#if defined(WOLFPSA_AES_FAST) && \
(defined(WC_AES_BITSLICED) || defined(WOLFSSL_AES_TOUCH_LINES))
Expand Down
6 changes: 4 additions & 2 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ config WOLFPSA_AES_FAST
bool "Accept wolfCrypt's T-table AES core (not constant time)"
help
Define WOLFPSA_AES_FAST, which waives src/psa_config.h's requirement for
an AES backend with no secret-indexed table load, and leaves
WOLFSSL_AES_CONSTANT_TIME off by default.
a constant-time AES backend and GHASH, and leaves
WOLFSSL_AES_CONSTANT_TIME off by default. Builds with the Arm assembly
from the wolfSSL module's settings need it, since that assembly falls
back to a T-table core.

The T-table core is wolfCrypt's fastest software AES, and its access
pattern is key- and state-dependent. Enable this only where that timing
Expand Down
Loading
Loading