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
82 changes: 82 additions & 0 deletions .github/workflows/build-config-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build Config Matrix

on:
push:
pull_request:

jobs:
build-config-matrix:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: baseline
modifiers: ""
- name: md5
modifiers: "-WOLFSSL_MD5 +NO_MD5"
- name: ripemd
modifiers: "-WOLFSSL_RIPEMD"
- name: sha1
modifiers: "+NO_SHA"
- name: sha224
modifiers: "-WOLFSSL_SHA224"
- name: sha384
modifiers: "-WOLFSSL_SHA384"
- name: sha512-family
modifiers: "-WOLFSSL_SHA512 -WOLFSSL_SHA384 -HAVE_ED25519 -WOLFSSL_ED25519_STREAMING_VERIFY -HAVE_ED448 -WOLFSSL_ED448_STREAMING_VERIFY +NO_SHA512"
- name: sha3-ed448
modifiers: "-WOLFSSL_SHA3 -HAVE_ED448 -WOLFSSL_ED448_STREAMING_VERIFY"
- name: des3
modifiers: "-WOLFSSL_DES3 -WOLFSSL_DES_ECB +NO_DES3"
- name: aes-gcm
modifiers: "-HAVE_AESGCM"
- name: aes-ccm
modifiers: "-HAVE_AESCCM"
- name: aes-ctr
modifiers: "-WOLFSSL_AES_COUNTER"
- name: aes-cfb
modifiers: "-WOLFSSL_AES_CFB"
- name: aes-ofb
modifiers: "-WOLFSSL_AES_OFB"
- name: aes-ecb
modifiers: "-HAVE_AES_ECB"
- name: des-ecb
modifiers: "-WOLFSSL_DES_ECB"
- name: cmac
modifiers: "-WOLFSSL_CMAC"
- name: chacha20-poly1305
modifiers: "-HAVE_CHACHA -HAVE_POLY1305"
Comment thread
danielinux marked this conversation as resolved.
- name: curve25519
modifiers: "-HAVE_CURVE25519"
- name: ed25519
modifiers: "-HAVE_ED25519 -WOLFSSL_ED25519_STREAMING_VERIFY"
- name: curve448
modifiers: "-HAVE_CURVE448"
- name: ed448
modifiers: "-HAVE_ED448 -WOLFSSL_ED448_STREAMING_VERIFY"
- name: hkdf
modifiers: "-HAVE_HKDF -HAVE_ECC_ENCRYPT"
- name: tls-prf
modifiers: "-WOLFSSL_HAVE_PRF"
- name: pbkdf2
modifiers: "-HAVE_PBKDF2 +NO_PBKDF2"
- name: ecc384
modifiers: "-WOLFSSL_SP_384 -HAVE_ECC384"
- name: rsa-1024
Comment thread
danielinux marked this conversation as resolved.
modifiers: "-WOLFSSL_SP_1024 -RSA_MIN_SIZE +RSA_MIN_SIZE=2048"

steps:
- name: Check out wolfPSA
uses: actions/checkout@v4

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Clone sibling wolfSSL
run: git clone --depth 1 https://github.com/wolfSSL/wolfssl ../wolfssl
Comment thread
danielinux marked this conversation as resolved.

- name: Build ${{ matrix.name }}
run: ./build-test/build-variant.sh "${{ matrix.name }}" ${{ matrix.modifiers }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ wolfcrypt-benchmark/wolfcrypt-psa-benchmark
wolfcrypt-psa-benchmark
.store/
*.log
.codex
106 changes: 106 additions & 0 deletions build-test/build-variant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/sh
#
# Build a wolfPSA variant with a baseline set of wolfcrypt-native defines,
# optionally modified by lane-specific +/- tokens.
#
# Usage: build-variant.sh <lane-name> [modifier ...]
#
# A modifier is one of:
# +FLAG add -DFLAG to the compile flags
# +FLAG=VALUE add -DFLAG=VALUE
# -FLAG remove -DFLAG (or -DFLAG=...) from the baseline
#
# The baseline below must list every wolfcrypt-native knob wolfPSA needs for
# a full build. Keep the names in sync with wolfssl/wolfcrypt/settings.h.

set -eu

script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
repo_root=$(CDPATH= cd -- "${script_dir}/.." && pwd)
variant_name=${1:?usage: build-variant.sh <lane-name> [modifier ...]}
shift

# Baseline — every feature enabled. Listed one per line for easy grep/edit.
BASELINE="
WOLFSSL_SP_MATH_ALL
WOLFSSL_HAVE_SP_RSA
WOLFSSL_HAVE_SP_ECC
HAVE_SP_ECC
WOLFSSL_KEY_GEN
WC_NO_HARDEN
HAVE_ECC
HAVE_ECC_KEY_EXPORT
HAVE_ECC_KEY_IMPORT
WOLFSSL_ECDSA_DETERMINISTIC_K
WC_RSA_PSS
WOLFSSL_PSS_SALT_LEN_DISCOVER
WOLFSSL_RSA_OAEP
WOLFSSL_SP_1024
RSA_MIN_SIZE=1024
WOLFSSL_SP_384
HAVE_ECC384
WOLFSSL_HAVE_PRF
HAVE_HKDF
HAVE_ECC_ENCRYPT
HAVE_PBKDF2
WOLFSSL_MD5
WOLFSSL_RIPEMD
WOLFSSL_SHA224
WOLFSSL_SHA384
WOLFSSL_SHA512
WOLFSSL_SHA3
WOLFSSL_DES3
WOLFSSL_DES_ECB
HAVE_AESGCM
HAVE_AESCCM
HAVE_AES_ECB
WOLFSSL_AES_COUNTER
WOLFSSL_AES_CFB
WOLFSSL_AES_OFB
WOLFSSL_CMAC
HAVE_CHACHA
HAVE_POLY1305
HAVE_CURVE25519
HAVE_ED25519
WOLFSSL_ED25519_STREAMING_VERIFY
HAVE_CURVE448
HAVE_ED448
WOLFSSL_ED448_STREAMING_VERIFY
"

flags="${BASELINE}"

for mod in "$@"; do
case "${mod}" in
+*)
token=${mod#+}
flags="${flags}
${token}"
;;
-*)
name=${mod#-}
# Drop any line that is either exactly "name" or "name=...".
flags=$(printf '%s\n' "${flags}" | awk -v n="${name}" '
$0 == n { next }
index($0, n "=") == 1 { next }
{ print }')
;;
*)
printf 'build-variant.sh: unknown modifier %s\n' "${mod}" >&2
exit 2
;;
esac
done

cppflags="-DWOLFSSL_USER_SETTINGS"
for tok in ${flags}; do
[ -z "${tok}" ] && continue
cppflags="${cppflags} -D${tok}"
done

make -C "${repo_root}" clean BUILD_DIR="${repo_root}/build-test/out/${variant_name}" >/dev/null
make -C "${repo_root}" \
BUILD_DIR="${repo_root}/build-test/out/${variant_name}" \
USER_SETTINGS_PATH="${repo_root}/build-test" \
WOLFSSL_CPPFLAGS="${cppflags}" \
libwolfpsa.a
35 changes: 35 additions & 0 deletions build-test/user_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* user_settings.h
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#ifndef WOLFSSL_USER_SETTINGS_H
#define WOLFSSL_USER_SETTINGS_H

/* The build-config-matrix harness drives every algorithm feature via
* wolfcrypt-native defines passed on the compiler command line by
* build-test/build-variant.sh. This file only sets up invariants that are
* always required (or always forbidden) regardless of the lane. */

#define WOLFCRYPT_ONLY
#define SINGLE_THREADED
#define WOLFSSL_PSA_ENGINE
#define NO_DSA

#endif /* WOLFSSL_USER_SETTINGS_H */
45 changes: 45 additions & 0 deletions src/psa_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ static psa_status_t wolfpsa_aead_setup(psa_aead_operation_t *operation,
if (!PSA_ALG_IS_AEAD(alg) || PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM_STAR_NO_TAG)) {
return PSA_ERROR_NOT_SUPPORTED;
}
#ifndef HAVE_AESGCM
if (PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_GCM)) {
return PSA_ERROR_NOT_SUPPORTED;
}
#endif
#ifndef HAVE_AESCCM
if (PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM)) {
return PSA_ERROR_NOT_SUPPORTED;
}
#endif
#if !defined(HAVE_CHACHA) || !defined(HAVE_POLY1305)
if (PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CHACHA20_POLY1305)) {
return PSA_ERROR_NOT_SUPPORTED;
}
#endif

status = wolfpsa_aead_check_key(key, usage, alg, &attributes,
&key_data, &key_data_length);
Expand All @@ -238,12 +253,14 @@ static psa_status_t wolfpsa_aead_setup(psa_aead_operation_t *operation,
return PSA_ERROR_INVALID_ARGUMENT;
}
ctx->direction = (usage == PSA_KEY_USAGE_ENCRYPT) ? 1 : 0;
#ifdef HAVE_AESCCM
if (PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM) &&
wc_AesCcmCheckTagSize((int)ctx->tag_length) != 0) {
wolfpsa_forcezero_free_key_data(key_data, key_data_length);
XFREE(ctx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return PSA_ERROR_INVALID_ARGUMENT;
}
#endif

ctx->key = (uint8_t *)XMALLOC(key_data_length, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
Expand Down Expand Up @@ -471,7 +488,9 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
size_t *tag_length)
{
int ret;
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
size_t chacha_ciphertext_size = 0;
#endif
const uint8_t *input;
const uint8_t *aad;

Expand All @@ -490,12 +509,14 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
return PSA_ERROR_INVALID_ARGUMENT;
}

#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_CHACHA20_POLY1305)) {
if (ctx->input_length > SIZE_MAX - ctx->tag_length) {
return PSA_ERROR_BUFFER_TOO_SMALL;
}
chacha_ciphertext_size = ctx->input_length + ctx->tag_length;
}
#endif

if (ciphertext_size < ctx->input_length) {
return PSA_ERROR_BUFFER_TOO_SMALL;
Expand All @@ -514,6 +535,7 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
aad = wolfpsa_aead_nonnull_data(ctx->aad, ctx->aad_length);

if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_GCM)) {
#ifdef HAVE_AESGCM
Aes aes;
ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
if (ret == 0) {
Expand All @@ -531,8 +553,12 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
if (ret != 0) {
return wc_error_to_psa_status(ret);
}
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_CCM)) {
#ifdef HAVE_AESCCM
Aes aes;
if (wc_AesCcmCheckTagSize((int)ctx->tag_length) != 0) {
return PSA_ERROR_NOT_SUPPORTED;
Expand All @@ -553,8 +579,12 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
if (ret != 0) {
return wc_error_to_psa_status(ret);
}
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_CHACHA20_POLY1305)) {
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
size_t out_len = 0;
uint8_t *tmp = (uint8_t *)XMALLOC(chacha_ciphertext_size, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
Expand All @@ -581,6 +611,9 @@ static psa_status_t wolfpsa_aead_encrypt_final(wolfpsa_aead_ctx_t *ctx,
XMEMCPY(tag, tmp + ctx->input_length, ctx->tag_length);
wc_ForceZero(tmp, chacha_ciphertext_size);
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else {
return PSA_ERROR_NOT_SUPPORTED;
Expand Down Expand Up @@ -639,6 +672,7 @@ static psa_status_t wolfpsa_aead_decrypt_final(wolfpsa_aead_ctx_t *ctx,
aad = wolfpsa_aead_nonnull_data(ctx->aad, ctx->aad_length);

if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_GCM)) {
#ifdef HAVE_AESGCM
Aes aes;
ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
if (ret == 0) {
Expand All @@ -659,8 +693,12 @@ static psa_status_t wolfpsa_aead_decrypt_final(wolfpsa_aead_ctx_t *ctx,
if (ret != 0) {
return wc_error_to_psa_status(ret);
}
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_CCM)) {
#ifdef HAVE_AESCCM
Aes aes;
if (wc_AesCcmCheckTagSize((int)tag_length) != 0) {
return PSA_ERROR_INVALID_SIGNATURE;
Expand All @@ -684,8 +722,12 @@ static psa_status_t wolfpsa_aead_decrypt_final(wolfpsa_aead_ctx_t *ctx,
if (ret != 0) {
return wc_error_to_psa_status(ret);
}
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else if (PSA_ALG_AEAD_EQUAL(ctx->alg, PSA_ALG_CHACHA20_POLY1305)) {
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
size_t out_len = 0;
uint8_t *ciphertext = ctx->input;
size_t ciphertext_len;
Expand Down Expand Up @@ -713,6 +755,9 @@ static psa_status_t wolfpsa_aead_decrypt_final(wolfpsa_aead_ctx_t *ctx,
}
*plaintext_length = out_len;
return PSA_SUCCESS;
#else
return PSA_ERROR_NOT_SUPPORTED;
#endif
}
else {
return PSA_ERROR_NOT_SUPPORTED;
Expand Down
Loading
Loading