Skip to content
Open
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
135 changes: 135 additions & 0 deletions .github/workflows/nuvoton-m2354-compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: "Nuvoton M2354 port"

# Keeps the Nuvoton NuMicro M2354 crypto callback port compiling against the
# real vendor BSP. The port has no autotools option and is not built by any
# other job: an application compiles wolfcrypt/src/port/nuvoton/*.c into its own
# project, the same way wolfcrypt/src/port/st/stm32.c is carried. Without this
# guard a header rename in the BSP, or a refactor in aes.c, ecc.c or cryptocb.h,
# would break the port silently until someone next built for the board.
#
# Nothing is faked. arm-none-eabi-gcc is a plain apt package and the BSP is a
# public GitHub repository, so both legs compile against the genuine Nuvoton
# StdDriver headers at a pinned commit.
#
# secure WOLFSSL_NUVOTON_SECURE, the whole port including nuvoton_hw.c
# nonsecure WOLFSSL_NUVOTON_NSC, where nuvoton_hw.c compiles to nothing
# and the cmse_nonsecure_entry veneers supply the symbols
#
# The runnable example, including those veneers, lives in wolfssl-examples
# under embedded/nuvoton_m2354. Functional correctness is validated on a
# NuMaker-M2354, not here; see wolfcrypt/src/port/nuvoton/README.md.

# START OF COMMON SECTION
on:
push:
branches: [ 'master', 'main', 'release/**' ]
paths:
- 'wolfcrypt/src/port/nuvoton/**'
- 'wolfssl/wolfcrypt/port/nuvoton/**'
- '.github/workflows/nuvoton-m2354-compile.yml'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [ '**' ]
paths:
- 'wolfcrypt/src/**'
- 'wolfssl/wolfcrypt/**'
- '.github/workflows/nuvoton-m2354-compile.yml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
# END OF COMMON SECTION

env:
# Pinned so a BSP change cannot break a PR that did not touch the port. Bump
# it deliberately.
BSP_REF: 3d423be763edabe1d8b3f27dea363b69e787f8f9

jobs:
compile:
name: ${{ matrix.leg }} (Cortex-M23)
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- leg: secure
world: WOLFSSL_NUVOTON_SECURE
- leg: nonsecure
world: WOLFSSL_NUVOTON_NSC
steps:
- uses: actions/checkout@v4
name: Checkout wolfSSL

- name: Install the toolchain
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-none-eabi

- name: Checkout the Nuvoton M2354 BSP
run: |
set -e
# The full repository is around 256 MB and almost none of it is
# needed, so take one commit and only the driver tree.
git clone --filter=blob:none --no-checkout --sparse \
https://github.com/OpenNuvoton/M2354BSP "$GITHUB_WORKSPACE/M2354BSP"
cd "$GITHUB_WORKSPACE/M2354BSP"
git sparse-checkout set \
Library/StdDriver/inc Library/Device Library/CMSIS
git fetch --depth 1 origin "$BSP_REF"
git checkout "$BSP_REF"

- name: Compile the port
run: |
set -e
BSP="$GITHUB_WORKSPACE/M2354BSP"
mkdir -p "$GITHUB_WORKSPACE/cfg"

# Minimal configuration: enough to reach every engine in the port.
# The example in wolfssl-examples carries a realistic one.
cat > "$GITHUB_WORKSPACE/cfg/user_settings.h" <<'EOF'
#ifndef CI_USER_SETTINGS_H
#define CI_USER_SETTINGS_H
#define WOLFSSL_NUVOTON_M2354
#define SINGLE_THREADED
#define NO_FILESYSTEM
#define WOLFSSL_SMALL_STACK
#define WOLFSSL_SHA224
#define WOLFSSL_SHA384
#define WOLFSSL_SHA512
#define HAVE_HASHDRBG
#define HAVE_AES_CBC
#define HAVE_AES_ECB
#define WOLFSSL_AES_DIRECT
#define WOLFSSL_AES_COUNTER
#define HAVE_AESGCM
#define HAVE_ECC
#define HAVE_ECC_DHE
#define HAVE_ECC_SIGN
#define HAVE_ECC_VERIFY
#define HAVE_ECC384
#define WOLFSSL_KEY_GEN
#define TFM_TIMING_RESISTANT
#define ECC_TIMING_RESISTANT
#define WC_RSA_BLINDING
#endif
EOF

CFLAGS="-mcpu=cortex-m23 -mthumb -Os -Wall -Wextra -Werror -c"
CFLAGS="$CFLAGS -I. -I$GITHUB_WORKSPACE/cfg -DWOLFSSL_USER_SETTINGS"
CFLAGS="$CFLAGS -D${{ matrix.world }}"
CFLAGS="$CFLAGS -I$BSP/Library/StdDriver/inc"
CFLAGS="$CFLAGS -I$BSP/Library/Device/Nuvoton/M2354/Include"
CFLAGS="$CFLAGS -I$BSP/Library/CMSIS/Include"

for f in wolfcrypt/src/port/nuvoton/*.c wolfcrypt/src/random.c; do
echo " $f"
# shellcheck disable=SC2086
arm-none-eabi-gcc $CFLAGS -o /dev/null "$f"
done
8 changes: 8 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ WOLFSSL_NO_OCSP_OPTIONAL_CERTS
WOLFSSL_NO_RSA_KEY_CHECK
WOLFSSL_NO_SERVER_GROUPS_EXT
WOLFSSL_NO_SESSION_STATS
WOLFSSL_NO_SHA512_HASHTYPE
WOLFSSL_NO_SIGALG
WOLFSSL_NO_SOCKADDR_UN
WOLFSSL_NO_STRICT_CIPHER_SUITE
Expand All @@ -1046,6 +1047,13 @@ WOLFSSL_NO_TRUSTED_CERTS_VERIFY
WOLFSSL_NO_WORD64_OPS
WOLFSSL_NO_XOR_OPS
WOLFSSL_NRF51_AES
WOLFSSL_NUVOTON_NO_AESCCM
WOLFSSL_NUVOTON_NO_AESGCM
WOLFSSL_NUVOTON_NO_HW_MUTEX
WOLFSSL_NUVOTON_NO_SP_DEFAULT
WOLFSSL_NUVOTON_NSC
WOLFSSL_NUVOTON_NSC_IMPL
WOLFSSL_NUVOTON_RNG_OFFLOAD
WOLFSSL_NXP_CASPER_ECC_MUL2ADD
WOLFSSL_NXP_CASPER_ECC_MULMOD
WOLFSSL_NXP_LPC55S6X
Expand Down
30 changes: 19 additions & 11 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -33997,17 +33997,22 @@ int DecodeECC_DSA_Sig_Ex(const byte* sig, word32 sigLen, mp_int* r, mp_int* s,
#endif


#ifdef WOLFSSL_ASN_TEMPLATE
#if defined(HAVE_ECC) && defined(WOLFSSL_CUSTOM_CURVES)
#ifdef WOLFSSL_ASN_HEX_STRING
/* Convert data to hex string.
*
* Big-endian byte array is converted to big-endian hexadecimal string.
*
* Written for the custom ECC curve parameters, which SEC 1 carries as byte
* arrays and ecc_set_type holds as strings. Hardware ports whose driver takes
* key material the same way reuse it rather than growing their own copy; see
* WOLFSSL_ASN_HEX_STRING in asn.h. Base16_Decode() goes the other way and
* accepts either case, so the two pair up.
*
* @param [in] input Buffer containing data.
* @param [in] inSz Size of data in buffer.
* @param [out] out Buffer to hold hex string.
* @param [out] out Buffer to hold hex string. Needs inSz * 2 + 1 bytes.
*/
static void DataToHexString(const byte* input, word32 inSz, char* out)
void wc_DataToHexString(const byte* input, word32 inSz, char* out)
{
static const char hexChar[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
Expand All @@ -34021,7 +34026,10 @@ static void DataToHexString(const byte* input, word32 inSz, char* out)
/* NUL terminate string. */
out[i * 2] = '\0';
}
#endif /* WOLFSSL_ASN_HEX_STRING */

#ifdef WOLFSSL_ASN_TEMPLATE
#if defined(HAVE_ECC) && defined(WOLFSSL_CUSTOM_CURVES)
#ifndef WOLFSSL_ECC_CURVE_STATIC
/* Convert data to hex string and place in allocated buffer.
*
Expand All @@ -34048,7 +34056,7 @@ static int DataToHexStringAlloc(const byte* input, word32 inSz, char** out,
}
else {
/* Convert to hex string. */
DataToHexString(input, inSz, str);
wc_DataToHexString(input, inSz, str);
*out = str;
}

Expand Down Expand Up @@ -34251,23 +34259,23 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
#else
if (ret == 0) {
/* Base X-ordinate */
DataToHexString(base + 1, (word32)curve->size, (char *)curve->Gx);
wc_DataToHexString(base + 1, (word32)curve->size, (char *)curve->Gx);
/* Base Y-ordinate */
DataToHexString(base + 1 + curve->size, (word32)curve->size, (char *)curve->Gy);
wc_DataToHexString(base + 1 + curve->size, (word32)curve->size, (char *)curve->Gy);
/* Prime */
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.data,
wc_DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.data,
dataASN[ECCSPECIFIEDASN_IDX_PRIME_P].data.ref.length,
(char *)curve->prime);
/* Parameter A */
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.data,
wc_DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.data,
dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.length,
(char *)curve->Af);
/* Parameter B */
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.data,
wc_DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.data,
dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.length,
(char *)curve->Bf);
/* Order of curve */
DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.data,
wc_DataToHexString(dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.data,
dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.length,
(char *)curve->order);
}
Expand Down
9 changes: 9 additions & 0 deletions wolfcrypt/src/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ EXTRA_DIST += wolfcrypt/src/port/ti/ti-aes.c \
wolfcrypt/src/port/silabs/silabs_hash.c \
wolfcrypt/src/port/silabs/silabs_random.c \
wolfcrypt/src/port/silabs/README.md \
wolfcrypt/src/port/nuvoton/nuvoton_hw.h \
wolfcrypt/src/port/nuvoton/nuvoton_hw.c \
wolfcrypt/src/port/nuvoton/nuvoton_cryptocb.c \
wolfcrypt/src/port/nuvoton/nuvoton_cb_rng.c \
wolfcrypt/src/port/nuvoton/nuvoton_cb_hash.c \
wolfcrypt/src/port/nuvoton/nuvoton_cb_cipher.c \
wolfcrypt/src/port/nuvoton/nuvoton_cb_pk.c \
wolfcrypt/src/port/nuvoton/nuvoton_key.c \
wolfcrypt/src/port/nuvoton/README.md \
wolfcrypt/src/port/st/stm32.c \
wolfcrypt/src/port/st/README.md \
wolfcrypt/src/port/st/STM32MP13.md \
Expand Down
Loading
Loading