1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-24 04:09:07 +03:00

Merge pull request #11563 from miyazakh/f10033_FSPSMgcm

Fixes and tooling for the RA6M4 (Renesas SCE/FSPSM) port
This commit is contained in:
JacobBarthelmeh
2026-10-02 08:31:46 -06:00
committed by GitHub
18 changed files with 1058 additions and 165 deletions

3
.gitignore vendored
View File

@@ -419,6 +419,9 @@ IDE/**/DerivedData
/IDE/Renesas/e2studio/RX72N/EnvisionKit/test/src/smc_gen
/IDE/Renesas/e2studio/RX72N/EnvisionKit/test/generate
/IDE/Renesas/e2studio/RA6M4/wolfssl/script/fsp.ld
/IDE/Renesas/e2studio/RA6M4/test/script/fsp.ld
# QNX CAAM
/IDE/QNX/example-server/server-tls
/IDE/QNX/example-client/client-tls

View File

@@ -132,21 +132,20 @@ The wolfssl Project Summary is listed below and is relevant for every project.
SEGGER_RTT_printf.c
+ To connect RTT block, you can configure RTT viewer configuration based on where RTT block is in a map file.
+ To place RTT block specific area, you can add the following line to `fsp_gen.ld`:
+ To place the RTT control block at a fixed, predictable address, add the following to
`test_RA6M4`'s `script/fsp.ld` (the one copied from `dummy_application` in step 4 above --
not the auto-generated `fsp_gen.ld`, which gets overwritten every time the FSP Configurator
regenerates project content). This file is generated by e2studio per-project and isn't
tracked in this repo, so the block below has to be re-added after any fresh copy:
```
__ram_from_flash$$ :
SECTIONS
{
.txt.rtt_block (READONLY) :
{
__ram_from_flash$$Base = .;__ram_from_flash$$Load = LOADADDR(__ram_from_flash$$);
/* section.ram.from_flash */
*(.ram_from_flash)
/* section.ram.code_from_flash */
*(.txt.rtt_block) /* <-- for SEGGER_RTT control block */
*(.ram_code_from_flash)
*(.data*)
*(vtable)
__ram_from_flash$$Limit = .;
}> RAM AT > FLASH
KEEP(*(.txt.rtt_block))
} > RAM
} INSERT AFTER .data
```
Also, adding the following line to `SEGGER_RTT.c`:
@@ -167,6 +166,10 @@ SEGGER_RTT_CB _SEGGER_RTT __attribute__((section(".txt.rtt_block")));
OR
you can specify "RTT control block" to 0x20000000 0x1000 by Search Range
`build.bat` does this lookup for you: after building `all`, it greps `test_RA6M4.map` for
`_SEGGER_RTT` and prints the address to enter directly into the RTT Viewer's Address field,
so you don't need to open the map file by hand.
## Run Client
1.) Enable TLS_CLIENT definition in wolfssl_demo.h of test_RA6M4 project
@@ -372,6 +375,47 @@ You can update code above to handle AES128 key when you install its key.
3.) Run Benchmark and Crypto Test
## Appendix: command-line build and flash scripts
Once the `wolfssl` and `test` projects have each been built at least once in e2studio (to
generate their makefiles and `ra_gen`), `build.bat` and `debug_run.bat` let you rebuild and
flash from the command line without reopening e2studio.
### build.bat
```
build.bat [clean|crypt|bench|TLSClient|wolfssl]
```
+ *(no arg)* -- incremental build of both projects (`wolfssl` then `test`)
+ `clean` -- clean both projects
+ `crypt` / `bench` / `TLSClient` -- set the corresponding demo mode in `wolfssl_demo.h`
(`CRYPT_TEST` / `BENCHMARK` / `TLS_CLIENT`) before building
+ `wolfssl` -- force a clean rebuild of the files that depend on `user_settings.h` (and other
shared wolfSSL headers); needed after editing them, since the generated makefiles only track
each `.c` file's own mtime, not the headers it includes
After a successful `all` build, it also greps `test_RA6M4.map` for `_SEGGER_RTT` and prints
the RTT control block address (see "Prepare SEGGER_RTT to logging" above).
`MAKE`, `ARM_GCC_BIN`, and `E2_BUSYBOX` are tied to one specific e2studio/toolchain install;
set them in the environment before calling `build.bat` if your install differs from the
defaults baked into the script.
### debug_run.bat
```
debug_run.bat [restart]
```
+ *(no arg)* -- flash `test\Debug\test_RA6M4.srec` via SEGGER J-Link Commander, then reset and
run
+ `restart` -- reset and run the already-flashed target again, without reprogramming
`JLINK_DIR` (the J-Link install directory) and `QC_DELAY_MS` (how long the script keeps the
J-Link connection open after `go`, in ms, before disconnecting) can be overridden in the
environment.
## Support
For support inquiries and questions, please email support@wolfssl.com. Feel free to reach out to info@wolfssl.jp as well.

View File

@@ -0,0 +1,198 @@
@echo off
REM EnableDelayedExpansion is required below: MAKE/ARM_GCC_BIN/E2_BUSYBOX are filesystem
REM paths that may contain literal parens (e.g. "Program Files (x86)"). A parenthesized
REM if-block reads its %VAR% references and substitutes them at block-PARSE time, before
REM any line in the block runs -- so echoing one with %VAR% reintroduces raw, unescaped
REM parens into the block's text and corrupts cmd.exe's block-boundary parsing (that's
REM what broke here: caret-escaping the SET line alone isn't enough, because the escape
REM is consumed once by SET and the stored value has no escaping left for later %-expansions).
REM !VAR! (delayed expansion) instead resolves at each line's execution time, after the
REM block has already been parsed, so it never reintroduces the problem.
setlocal EnableDelayedExpansion
REM --- These paths are tied to a specific e2studio/GNU ARM Embedded install (plugin
REM version, toolchain version, platform ID) and will not exist as-is on a different
REM machine or install. Set MAKE/ARM_GCC_BIN/E2_BUSYBOX in the environment before calling
REM build.bat to override the defaults below for your install. ---
set USING_DEFAULTS=
if not defined MAKE (
set MAKE=C:\Renesas\e2_studio\eclipse\plugins\com.renesas.ide.exttools.gnumake.win32.x86_64_4.3.1.v20240909-0854\mk\make.exe
set USING_DEFAULTS=1
)
REM The default path below has literal parens in "Program Files (x86)". Inside an
REM if-block, cmd.exe's parser stops the block at the FIRST unescaped closing paren it
REM meets -- not a properly nested count -- so an unescaped ")" here would truncate the
REM block right after "(x86" and run the rest of the line as a stray command. Must stay
REM caret-escaped as ^( and ^) below; do not "clean up" this escaping.
if not defined ARM_GCC_BIN (
set ARM_GCC_BIN=C:\Program Files ^(x86^)\Arm GNU Toolchain arm-none-eabi\13.3 rel1\bin
set USING_DEFAULTS=1
)
REM Generated makefiles call BusyBox "rm"/"xargs" directly (not via a shell), so this
REM directory must be on PATH or the clean recipe fails with
REM "process_begin: CreateProcess(NULL, rm ...) failed".
if not defined E2_BUSYBOX (
set E2_BUSYBOX=C:\Renesas\e2_studio\eclipse\plugins\com.renesas.ide.exttools.busybox.win32.x86_64_1.3.6.v20230615-0931\bin
set USING_DEFAULTS=1
)
if defined USING_DEFAULTS (
echo [NOTICE] MAKE/ARM_GCC_BIN/E2_BUSYBOX is not set. Using default paths below;
echo these are tied to one specific e2studio/toolchain install and will likely not
echo exist on a different machine or install. Please adjust the paths for your
echo environment by setting these variables before running build.bat.
echo MAKE = !MAKE!
echo ARM_GCC_BIN = !ARM_GCC_BIN!
echo E2_BUSYBOX = !E2_BUSYBOX!
echo.
pause
)
set PATH=%ARM_GCC_BIN%;%E2_BUSYBOX%;%PATH%
set BASEDIR=%~dp0
set TARGET=all
set MODE=
set FORCE_WOLFSSL_REBUILD=
if /i "%1"=="clean" (
set TARGET=clean
) else if /i "%1"=="crypt" (
set MODE=crypt
) else if /i "%1"=="bench" (
set MODE=bench
) else if /i "%1"=="TLSClient" (
set MODE=TLSClient
) else if /i "%1"=="wolfssl" (
set FORCE_WOLFSSL_REBUILD=1
) else if not "%1"=="" (
echo [ERROR] Unknown argument "%1".
echo Usage: build.bat [clean^|crypt^|bench^|TLSClient^|wolfssl]
echo crypt -^> enables #define CRYPT_TEST in common\wolfssl_demo.h
echo bench -^> enables #define BENCHMARK
echo TLSClient -^> enables #define TLS_CLIENT
echo wolfssl -^> force-rebuild files that depend on user_settings.h
echo ^(and other shared wolfSSL headers^) after editing it.
echo The generated makefiles only track each .c's own
echo mtime, not the headers it includes, so plain
echo incremental "build.bat" silently keeps stale objects;
echo "build.bat clean" catches it too but also nukes and
echo recompiles the untouched SEGGER RTT plumbing, which
echo takes longer than the wolfSSL-facing side alone.
exit /b 1
)
if not "%MODE%"=="" (
echo ============================================================
echo Setting demo mode: %MODE%
echo ============================================================
powershell -NoProfile -ExecutionPolicy Bypass -File "%BASEDIR%set_demo_mode.ps1" -Mode %MODE%
if errorlevel 1 (
echo [ERROR] Failed to set demo mode.
exit /b 1
)
echo.
)
REM --- Both makefile(s) below are generated by e2studio's managed-build system (from
REM .cproject) the first time each project is built there; build.bat only does incremental
REM rebuilds on top of that, it cannot bootstrap them from a truly clean checkout. ---
if not exist "%BASEDIR%wolfssl\Debug\makefile" (
echo [ERROR] "%BASEDIR%wolfssl\Debug\makefile" not found.
echo Open the "wolfssl" project in e2studio and build the "Debug" configuration once
echo ^(Project ^> Build Project^) to generate it, then re-run build.bat.
exit /b 1
)
if not exist "%BASEDIR%test\Debug\makefile" (
echo [ERROR] "%BASEDIR%test\Debug\makefile" not found.
echo Open the "test" project in e2studio and build the "Debug" configuration once
echo ^(Project ^> Build Project^) to generate it, then re-run build.bat.
exit /b 1
)
if not exist "%BASEDIR%wolfssl\ra_gen" (
echo [ERROR] "%BASEDIR%wolfssl\ra_gen" not found.
echo This is generated by e2studio's FSP Configurator from wolfssl's configuration.xml
echo ^(not tracked in git^). Open configuration.xml in e2studio and click "Generate
echo Project Content" once, then re-run build.bat.
exit /b 1
)
REM Below, "if errorlevel 1" (not "if %ERRORLEVEL% neq 0") is required to check the clean
REM step's exit code: %ERRORLEVEL% inside a parenthesized if-block is expanded once when
REM the whole block is parsed, before "%MAKE%" clean has even run, so it would always
REM read as whatever it was beforehand and silently ignore a failed clean. "if errorlevel"
REM is a distinct construct that re-checks the real, current value at that point instead.
if defined FORCE_WOLFSSL_REBUILD (
echo ============================================================
echo wolfssl library [clean rebuild]
echo ============================================================
cd /d "%BASEDIR%wolfssl\Debug"
"%MAKE%" clean
if errorlevel 1 (
echo [ERROR] wolfssl clean failed.
exit /b 1
)
) else (
echo ============================================================
echo wolfssl library [%TARGET%]
echo ============================================================
cd /d "%BASEDIR%wolfssl\Debug"
)
"%MAKE%" %TARGET%
if %ERRORLEVEL% neq 0 (
echo [ERROR] wolfssl build failed.
exit /b %ERRORLEVEL%
)
echo.
if defined FORCE_WOLFSSL_REBUILD (
echo ============================================================
echo test application [selective rebuild: wolfSSL-facing sources only,
echo SEGGER RTT plumbing left untouched]
echo ============================================================
cd /d "%BASEDIR%test\Debug"
for %%F in (
src\test_main.o
src\wolf_client.o
src\wolfssl_sce_unit_test.o
src\sce_tst_thread_entry.o
src\test.o
src\benchmark.o
key_data\key_data_sce.o
) do (
if exist "%%F" del /f /q "%%F"
)
) else (
echo ============================================================
echo test application [%TARGET%]
echo ============================================================
cd /d "%BASEDIR%test\Debug"
)
"%MAKE%" %TARGET%
if %ERRORLEVEL% neq 0 (
echo [ERROR] test build failed.
exit /b %ERRORLEVEL%
)
set MAPFILE=%BASEDIR%test\Debug\test_RA6M4.map
set RTT_ADDR=
REM _SEGGER_RTT is the RTT control block (SEGGER_RTT.c, placed in its own ".txt.rtt_block"
REM section). J-Link RTT Viewer/JLinkGDBServer can auto-search RAM for it, but that's slow
REM and occasionally picks up stale/aliased data; giving it this address directly is faster
REM and unambiguous. Only meaningful after a real link ("all"), not after "clean".
if /i "%TARGET%"=="all" if exist "%MAPFILE%" (
for /f "tokens=1" %%A in ('findstr /c:"_SEGGER_RTT" "%MAPFILE%"') do set RTT_ADDR=%%A
echo.
echo ============================================================
if defined RTT_ADDR (
echo RTT control block ^(_SEGGER_RTT^) address: !RTT_ADDR!
echo Use this in J-Link RTT Viewer / JLinkGDBServer's RTT "Address" field to
echo skip the auto-search.
) else (
echo [WARN] Could not find _SEGGER_RTT in %MAPFILE%.
)
echo ============================================================
)
echo.
echo ============================================================
echo Done.
echo ============================================================
endlocal

View File

@@ -63,18 +63,30 @@
#define XVALIDATEDATE(d, f,t) (0)
#define TFM_TIMING_RESISTANT
#define ECC_TIMING_RESISTANT
#define WC_RSA_BLINDING
#define HAVE_AESGCM
#define GCM_TABLE_4BIT
#define WOLFSSL_SHA512
#define HAVE_ECC
#define HAVE_CURVE25519
#define CURVE25519_SMALL
#define WOLFSSL_SMALL_STACK
#define USE_FAST_MATH
/* SP math (replaces fastmath/TFM): faster and smaller for the fixed key
* sizes used here (RSA 2048, ECC P-256, Curve25519, FFDHE 2048). */
#define SP_WORD_SIZE 32
#define WOLFSSL_SP_MATH
#define WOLFSSL_SP_SMALL
#define WOLFSSL_SP_NO_MALLOC
#define WOLFSSL_SP_NO_DYN_STACK
#define WOLFSSL_SP_NO_3072
#define WOLFSSL_HAVE_SP_RSA
#define WOLFSSL_HAVE_SP_DH
#define WOLFSSL_HAVE_SP_ECC
#define WOLFSSL_SP_ARM_CORTEX_M_ASM
/* static RSA */
#define WOLFSSL_STATIC_RSA
@@ -91,7 +103,7 @@
/* Enable the following definition to use TLS 1.3
* For TLS1.3 use "extended-master" needs to turn on
*/
/* #define WOLFSSL_TLS13 */
#define WOLFSSL_TLS13
#if defined(WOLFSSL_TLS13)
#include <sys/time.h>

View File

@@ -82,7 +82,15 @@ typedef struct tagTestInfo
void sce_test();
void TCPInit();
void wolfSSL_TLS_client_init();
/* TLS_MULTITHREAD_TEST passes this directly to xTaskCreate(), whose
* TaskFunction_t is "void (*)(void*)" -- it must return void there (the task
* always ends itself via vTaskDelete(NULL) instead of returning a value). The
* non-multithread caller invokes it directly and uses the int return code. */
#if defined(TLS_MULTITHREAD_TEST)
void wolfSSL_TLS_client_do(void *pvParam);
#else
int wolfSSL_TLS_client_do(void *pvParam);
#endif
void wolfSSL_TLS_cleanup();
extern WOLFSSL_CTX *client_ctx;

View File

@@ -0,0 +1,115 @@
@echo off
REM EnableDelayedExpansion so "%JLINK%" (built from JLINK_DIR, a user-overridable install
REM path) can be echoed with !JLINK! inside an if-block without risk: if that path ever
REM contains parens (e.g. an override under "Program Files (x86)"), a %VAR%-style
REM reference would substitute them in raw at block-parse time and corrupt cmd.exe's
REM block-boundary parsing -- see build.bat's ARM_GCC_BIN handling, which hit exactly
REM this. !VAR! defers substitution to each line's execution time instead.
setlocal EnableDelayedExpansion
REM --- Flash test_RA6M4.srec and let it run, using SEGGER J-Link Commander (JLink.exe) ---
REM JLINK_DIR is tied to a specific J-Link software install and will not exist as-is on a
REM different machine. Set JLINK_DIR in the environment before calling debug_run.bat to
REM override the default below for your install.
if not defined JLINK_DIR set JLINK_DIR=C:\Program Files\SEGGER\JLink_V852
set JLINK=%JLINK_DIR%\JLink.exe
set BASEDIR=%~dp0
set TARGET_SREC=%BASEDIR%test\Debug\test_RA6M4.srec
set DEVICE=R7FA6M4AF
set JLINK_LOG=%BASEDIR%test_result.log
set JLINK_CMD=%TEMP%\ra6m4_debug_run_%RANDOM%.jlink
REM How long JLink.exe waits (via the command file's own "sleep", in ms) after "g" before
REM "qc" disconnects. Override with QC_DELAY_MS if you need longer/shorter. Some targets'
REM early boot (clock/BSP init, FreeRTOS scheduler start) can behave differently while a
REM debug probe is actively attached vs. standalone; holding the connection open a bit
REM past "go" is a cheap way to rule that class of difference in/out.
REM Default QC_DELAY_MS to 1000ms if not already defined.
if not defined QC_DELAY_MS set QC_DELAY_MS=1000
set MODE=reload
if /i "%1"=="restart" (
set MODE=restart
) else if not "%1"=="" (
echo [ERROR] Unknown argument "%1".
echo Usage: debug_run.bat [restart]
echo ^(no arg^) -^> reload: flash test_RA6M4.srec, then reset and run
echo restart -^> just reset the already-flashed target and run it again,
echo without reprogramming
exit /b 1
)
if not exist "%JLINK%" (
echo [ERROR] JLink.exe not found at "!JLINK!".
echo Set JLINK_DIR to your SEGGER J-Link install directory ^(the folder containing
echo JLink.exe^) and re-run debug_run.bat.
exit /b 1
)
if /i "%MODE%"=="restart" goto :restart_mode
goto :reload_mode
REM --- restart: just reset the already-flashed target, no reprogramming. Kept as
REM top-level (unindented, un-parenthesized) code like the reload path below it --
REM %JLINK_EXIT%/%ERRORLEVEL% are otherwise expanded once at parse time if wrapped in
REM an if-block, before JLink.exe has even run, always reading as stale/empty. ---
:restart_mode
echo [1/1] Restarting target via J-Link ^(no reprogramming; qc delayed !QC_DELAY_MS!ms^)...
echo ============================================================
del "%JLINK_LOG%" > nul 2>&1
(
echo r
echo g
echo sleep !QC_DELAY_MS!
echo qc
) > "%JLINK_CMD%"
"%JLINK%" -device %DEVICE% -if SWD -speed 4000 -autoconnect 1 -ExitOnError 1 -CommandFile "%JLINK_CMD%" -Log "%JLINK_LOG%"
set JLINK_EXIT=%ERRORLEVEL%
del "%JLINK_CMD%" > nul 2>&1
echo ============================================================
if %JLINK_EXIT% neq 0 (
echo [ERROR] JLink.exe exited with code %JLINK_EXIT%
) else (
echo [DONE] Target restarted -- check J-Link RTT Viewer for output.
)
exit /b %JLINK_EXIT%
:reload_mode
if not exist "%TARGET_SREC%" (
echo [ERROR] %TARGET_SREC% not found. Run build.bat first.
exit /b 1
)
echo [1/1] Programming via J-Link, then resetting and running ^(qc delayed !QC_DELAY_MS!ms^)...
echo ============================================================
del "%JLINK_LOG%" > nul 2>&1
REM -device/-if/-speed: matches the SWD/4000kHz settings e2studio's own launch config uses
REM for this project (test_RA6M4Debug.launch: interface.type=SWD, interface.speed=4000).
REM loadfile accepts the .srec directly -- no objcopy step needed, e2studio's GCC ARM
REM managed build already emits it as a post-build step (see test\Debug\makefile's
REM "secondary-outputs" target -> arm-none-eabi-objcopy -O srec).
REM r / loadfile / r / g: reset+halt, program+verify flash, reset again so execution
REM starts clean from the vector table, then go. sleep keeps JLink.exe (and the SWD
REM connection) alive for QC_DELAY_MS before qc quits without re-asserting reset, so the
REM target keeps running standalone after that.
(
echo r
echo loadfile "%TARGET_SREC%"
echo r
echo g
echo sleep !QC_DELAY_MS!
echo qc
) > "%JLINK_CMD%"
"%JLINK%" -device %DEVICE% -if SWD -speed 4000 -autoconnect 1 -ExitOnError 1 -CommandFile "%JLINK_CMD%" -Log "%JLINK_LOG%"
set JLINK_EXIT=%ERRORLEVEL%
del "%JLINK_CMD%" > nul 2>&1
echo ============================================================
if %JLINK_EXIT% neq 0 (
echo [ERROR] JLink.exe exited with code %JLINK_EXIT%
) else (
echo [DONE] Target is running -- check J-Link RTT Viewer for output.
)
exit /b %JLINK_EXIT%

View File

@@ -3,6 +3,9 @@
# All paths should be given relative to the root
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/README.md
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/build.bat
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/debug_run.bat
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/set_demo_mode.ps1
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/wolfssl/.cproject
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/wolfssl/.project
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/.cproject
@@ -19,5 +22,6 @@ EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/common/user_settings.h
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/tools/README.md
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/tools/example_keys/generate_SignedCA.sh
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/tools/example_keys/generate_SignedCA.bat
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/tools/example_keys/rsa_private.pem
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/tools/example_keys/rsa_public.pem

View File

@@ -0,0 +1,85 @@
# set_demo_mode.ps1
#
# Copyright (C) 2006-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 3 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
param(
[Parameter(Mandatory=$true)]
[ValidateSet('crypt', 'bench', 'TLSClient')]
[string]$Mode
)
# NOTE: common/wolfssl_demo.h documents CRYPT_TEST and BENCHMARK as combinable ("can be
# enabled with benchmark/crypt test"), unlike TLS_CLIENT which excludes both. For parity
# with the RX72N Simple demo's build.bat UX (one mode flag selects exactly one macro),
# this script still normalizes all three down to a single selected macro rather than
# offering a combined crypt+bench mode. Hand-edit wolfssl_demo.h if both are needed at once.
$macroMap = [ordered]@{
'crypt' = 'CRYPT_TEST'
'bench' = 'BENCHMARK'
'TLSClient' = 'TLS_CLIENT'
}
$selected = $macroMap[$Mode]
$file = Join-Path $PSScriptRoot 'common\wolfssl_demo.h'
if (-not (Test-Path $file)) {
Write-Error "File not found: $file"
exit 1
}
$content = Get-Content -Raw -Path $file
# Pass 1: normalize all three macros to the uncommented ("#define X") form,
# regardless of their current state, so pass 2's substring replace can't
# double-wrap an already-commented line (e.g. match "#define X" inside
# "/*#define X*/").
foreach ($m in $macroMap.Values) {
$content = $content -replace "/\*[ \t]*#define[ \t]+$m[ \t]*\*/", "#define $m"
}
# Pass 2: comment out every macro except the selected one.
foreach ($m in $macroMap.Values) {
if ($m -ne $selected) {
$content = $content.Replace("#define $m", "/*#define $m*/")
}
}
Set-Content -NoNewline -Path $file -Value $content
Write-Host "[demo mode] $Mode -> #define $selected enabled (others disabled)"
# make's generated dependency (.d) files don't reliably list wolfssl_demo.h as a
# prerequisite for every .c that includes it, so an incremental build can silently relink a
# stale .o (compiled under the old macro) into a fresh-looking test_RA6M4.elf. Force a
# rebuild of exactly the affected files by touching their mtime, rather than doing a full
# clean (slow) or trusting make's dependency tracking (unreliable here).
$srcDirs = @(
(Join-Path $PSScriptRoot 'test\src'),
(Join-Path $PSScriptRoot 'test\key_data'),
(Join-Path $PSScriptRoot 'common')
) | Where-Object { Test-Path $_ }
$dependents = Get-ChildItem -Path $srcDirs -Recurse -Include '*.c','*.h' |
Where-Object { $_.FullName -ne $file } |
Select-String -Pattern 'wolfssl_demo\.h' -List |
Select-Object -ExpandProperty Path
foreach ($dep in $dependents) {
(Get-Item $dep).LastWriteTime = Get-Date
}
Write-Host "[demo mode] Touched $($dependents.Count) dependent source file(s) to force recompilation:"
$dependents | ForEach-Object { Write-Host " $_" }

View File

@@ -72,32 +72,32 @@ const st_user_key_block_data_t g_key_block_data =
* This is used for Root Certificate verify by SCE */
const unsigned char ca_cert_der_sign[] =
{
0x4D, 0x7E, 0xE5, 0x34, 0x04, 0x8F, 0xA6, 0x81, 0x22, 0x8E,
0x2A, 0x9E, 0xEA, 0xBE, 0x1D, 0x0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 0x62, 0xDB, 0xD2, 0x33,
0xE2, 0xF0, 0x8A, 0x42, 0x56, 0x5A, 0x31, 0x5F, 0x58, 0xB2,
0x90, 0x85, 0xEF, 0xB6, 0xB6, 0x59, 0x5E, 0x94, 0x62, 0xB0,
0x20, 0x6B, 0xA5, 0x46, 0xC8, 0x48, 0xA3, 0x17, 0x14, 0x30,
0x11, 0x99, 0x9D, 0x1C, 0x1B, 0xAC, 0x32, 0xA3, 0xA8, 0x1F,
0xBB, 0xC5, 0x34, 0x6A, 0x65, 0x4E, 0x45, 0x8C, 0x5A, 0x7D,
0xE3, 0x00, 0x7E, 0x4D, 0x15, 0xF6, 0xE6, 0x21, 0xEF, 0x36,
0x9E, 0x6A, 0x46, 0x97, 0x17, 0x96, 0xDA, 0x38, 0x1B, 0x3C,
0x95, 0xAC, 0x96, 0x85, 0xC7, 0x7A, 0xD1, 0x84, 0xCF, 0xEA,
0x37, 0x9F, 0x0A, 0xD5, 0xAB, 0xFF, 0xD8, 0x28, 0xDA, 0xAF,
0x84, 0x6F, 0xE2, 0x7A, 0x41, 0x5D, 0x2A, 0xC9, 0x66, 0x04,
0x0D, 0x05, 0x0B, 0x6C, 0xCE, 0x9E, 0x99, 0x43, 0x05, 0x7C,
0xE5, 0x79, 0xBC, 0x36, 0x4A, 0xDD, 0xD9, 0x84, 0x03, 0x8E,
0x1B, 0xA8, 0x83, 0x08, 0x00, 0xD5
};
const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign);
@@ -108,32 +108,32 @@ const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign);
*/
const unsigned char ca_ecc_cert_der_sign[] =
{
0x10, 0xDC, 0xA3, 0x0E, 0xD9, 0xA7, 0x3C, 0xBE, 0x37, 0x6E,
0x34, 0xC1, 0xDB, 0x4E, 0x90, 0x42, 0x05, 0xCC, 0x94, 0x2B,
0xAF, 0x0D, 0xE0, 0xC9, 0xE3, 0x91, 0x5F, 0x57, 0x58, 0x48,
0x44, 0x69, 0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xAF, 0x58, 0x84, 0xF2, 0x91, 0x4C, 0xDC, 0x4A,
0xC8, 0x19, 0x68, 0x54, 0x5C, 0xFC, 0x9C, 0xD7, 0x99, 0x07,
0x24, 0x3A, 0xCC, 0x56, 0xC1, 0xE2, 0x75, 0x11, 0x97, 0x86,
0x5F, 0x64, 0x12, 0x30, 0x34, 0xDB, 0x2E, 0xB1, 0x48, 0xBC,
0xD5, 0x4A, 0x7F, 0x16, 0xE4, 0x91, 0x28, 0x74, 0x3F, 0x8E,
0x30, 0x3E, 0xE5, 0xCE, 0xEB, 0x48, 0x7B, 0xAC, 0x30, 0x6C,
0x0B, 0xA9, 0xD6, 0x9B, 0xE8, 0xEF, 0x5E, 0xEE, 0xE2, 0xC7,
0xDB, 0xFE, 0x5E, 0x3E, 0x17, 0x7D, 0x78, 0x06, 0xAC, 0xAD,
0xAB, 0x1B, 0xFD, 0x48, 0xCA, 0x75, 0x6B, 0xC7, 0x83, 0xDF,
0xDD, 0xEB, 0xE3, 0x7C, 0xB2, 0x22, 0x83, 0xF9, 0x2E, 0x1A,
0xDC, 0x85, 0xDE, 0x49, 0xAC, 0xE4, 0xC0, 0x7E, 0xC6, 0x85,
0xF8, 0x74, 0x8A, 0x85, 0x1C, 0x9C
};
static const int sizeof_ca_ecc_cert_der_sign = sizeof(ca_ecc_cert_der_sign);
const int sizeof_ca_ecc_cert_der_sign = sizeof(ca_ecc_cert_der_sign);
#endif /* USE_CERT_BUFFERS_256 */

View File

@@ -28,11 +28,14 @@
#if defined(WOLFSSL_RENESAS_SCEPROTECT) || \
defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
#include <wolfssl/wolfcrypt/port/Renesas/renesas-fspsm-crypt.h>
/* Always declared: used unconditionally by the CRYPT_TEST/BENCHMARK
* branches of sce_test() below, which are independent of whether the
* TLS_CLIENT branch's multithread demo is also toggled on. */
FSPSM_ST guser_PKCbInfo;
#if defined(TLS_MULTITHREAD_TEST)
/* Only used by the TLS_CLIENT branch's per-task connections. */
FSPSM_ST guser_PKCbInfo_taskA;
FSPSM_ST guser_PKCbInfo_taskB;
#else
FSPSM_ST guser_PKCbInfo;
#endif
#endif
@@ -102,6 +105,49 @@ typedef struct func_args {
void wolfcrypt_test(func_args args);
int benchmark_test(void *args);
#if defined(CRYPT_TEST) || defined(TLS_CLIENT)
#define BUILD_YEAR ( \
((__DATE__)[7] - '0') * 1000 + \
((__DATE__)[8] - '0') * 100 + \
((__DATE__)[9] - '0') * 10 + \
((__DATE__)[10] - '0') * 1 \
)
#define BUILD_MONTH ( \
__DATE__[2] == 'n' ? (__DATE__[1] == 'a' ? 1 : 6) \
: __DATE__[2] == 'b' ? 2 \
: __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 3 : 4) \
: __DATE__[2] == 'y' ? 5 \
: __DATE__[2] == 'l' ? 7 \
: __DATE__[2] == 'g' ? 8 \
: __DATE__[2] == 'p' ? 9 \
: __DATE__[2] == 't' ? 10 \
: __DATE__[2] == 'v' ? 11 \
: 12 \
)
#define BUILD_HOUR ( \
((__TIME__)[0] - '0') * 10 + ((__TIME__)[1] - '0') \
)
#define BUILD_MIN ( \
((__TIME__)[3] - '0') * 10 + ((__TIME__)[4] - '0') \
)
#define BUILD_SEC ( \
((__TIME__)[6] - '0') * 10 + ((__TIME__)[7] - '0') \
)
static time_t build_time_cb(time_t* t)
{
static time_t tick = 0;
time_t buildTime = (time_t)(((BUILD_YEAR - 1970) * 365 + 30 * BUILD_MONTH) *
24 * 60 * 60 + BUILD_HOUR * 60 * 60 + BUILD_MIN * 60 + BUILD_SEC);
/* tick advances each call so time isn't frozen at one instant */
time_t now = buildTime + tick++;
if (t != NULL) {
*t = now;
}
return now;
}
#endif /* defined(CRYPT_TEST) || defined(TLS_CLIENT) */
#ifdef TLS_MULTITHREAD_TEST
static void my_Logging_cb(const int logLevel, const char *const logMessage)
{
@@ -215,6 +261,8 @@ void sce_test(void)
wc_SetTimeCb(build_time_cb);
printf("Start wolfCrypt Test\n");
wolfcrypt_test(args);
printf("End wolfCrypt Test\n");
@@ -323,6 +371,9 @@ void sce_test(void)
#endif
int i = 0;
int ret = 0;
(void)ret;
wc_SetTimeCb(build_time_cb);
printf("\n Start Client Example, ");
printf("\n Connecting to %s\n\n", SERVER_IP);
@@ -352,7 +403,7 @@ void sce_test(void)
printf(" %s connecting to %d port\n", info[j].name, info[j].port);
xReturned = xTaskCreate(wolfSSL_TLS_client_do, info[j].name,
xReturned = xTaskCreate((void (*)(void *))wolfSSL_TLS_client_do, info[j].name,
THREAD_STACK_SIZE, &info[j], 2, NULL);
if (xReturned != pdPASS) {
printf("Failed to create task\n");

View File

@@ -131,7 +131,11 @@ void wolfSSL_TLS_client_init()
#endif
}
#if defined(TLS_MULTITHREAD_TEST)
void wolfSSL_TLS_client_do(void *pvParam)
#else
int wolfSSL_TLS_client_do(void *pvParam)
#endif
{
int ret;
@@ -159,19 +163,36 @@ int wolfSSL_TLS_client_do(void *pvParam)
xRemoteAddress.sin_port = FreeRTOS_htons(p->port);
xRemoteAddress.sin_addr = FreeRTOS_inet_addr(SERVER_IP);
/* Create a FreeRTOS TCP Socket and connect */
xClientSocket = FreeRTOS_socket(FREERTOS_AF_INET,
/* Create a FreeRTOS TCP Socket and connect. The network stack (PHY link,
* ARP for the gateway) isn't necessarily ready the instant this task
* starts, so a connect attempt made too early fails with ETIMEDOUT(-116)
* or ENOTCONN(-128); retry in that case, same as the non-multithreaded
* caller in test_main.c does around its own wolfSSL_TLS_client_do() call.
* A failed socket is closed and recreated each attempt since its state
* after a failed connect isn't reusable. */
{
int TCP_connect_retry = 0;
do {
xClientSocket = FreeRTOS_socket(FREERTOS_AF_INET,
FREERTOS_SOCK_STREAM,
FREERTOS_IPPROTO_TCP);
configASSERT(xClientSocket != FREERTOS_INVALID_SOCKET);
configASSERT(xClientSocket != FREERTOS_INVALID_SOCKET);
FreeRTOS_bind(xClientSocket, NULL, sizeof(xSize));
FreeRTOS_bind(xClientSocket, NULL, sizeof(xSize));
/* Client Socket Connect */
ret = FreeRTOS_connect(xClientSocket,
&xRemoteAddress,
sizeof(xRemoteAddress));
ret = FreeRTOS_connect(xClientSocket,
&xRemoteAddress,
sizeof(xRemoteAddress));
if (ret == FR_SOCKET_SUCCESS) {
break;
}
FreeRTOS_closesocket(xClientSocket);
xClientSocket = NULL;
TCP_connect_retry++;
} while ((ret == -116 || ret == -128) && TCP_connect_retry < 100);
}
if (ret != FR_SOCKET_SUCCESS) {
msg(pcName, i, " Error [%d]: FreeRTOS_connect.\n", ret);
@@ -276,8 +297,9 @@ int wolfSSL_TLS_client_do(void *pvParam)
#ifdef TLS_MULTITHREAD_TEST
xSemaphoreGive(exit_semaph);
vTaskDelete(NULL);
#endif
#else
return ret;
#endif
}
void wolfSSL_TLS_cleanup()

View File

@@ -609,6 +609,117 @@ static void tskAes128_Gcm_Test(void *pvParam)
#endif
#if defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256)
#define SCE_AESGCM_MISALIGNED_SZ 32
/* AES-GCM over misaligned AAD/data buffers, using a real SCE wrapped key
* (unlike the portable aesgcm_misaligned_test(), a plaintext key never
* reaches the SCE hardware path). Regression test for the AAD-alignment
* fix in wc_fspsm_AesGcmEncrypt()/wc_fspsm_AesGcmDecrypt(). */
static int sce_aesgcm_misaligned_test(int prnt, FSPSM_AES_PWKEY aes_key,
word32 keySz, int devId)
{
Aes aes[1];
WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
{
0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b
};
byte input[SCE_AESGCM_MISALIGNED_SZ + WC_AES_BLOCK_SIZE];
byte aad[SCE_AESGCM_MISALIGNED_SZ + WC_AES_BLOCK_SIZE];
byte cipher[SCE_AESGCM_MISALIGNED_SZ + WC_AES_BLOCK_SIZE];
byte plain[SCE_AESGCM_MISALIGNED_SZ + WC_AES_BLOCK_SIZE];
byte tag[WC_AES_BLOCK_SIZE];
byte refCipher[SCE_AESGCM_MISALIGNED_SZ];
byte refTag[WC_AES_BLOCK_SIZE];
int off;
int i;
int ret;
if (prnt) {
printf(keySz == WC_AES_BLOCK_SIZE ?
" sce_aesgcm128_misaligned_test() " :
" sce_aesgcm256_misaligned_test() ");
}
if (wc_AesInit(aes, NULL, devId) != 0) {
ret = -1;
goto out;
}
for (off = 0; off < (int)WC_AES_BLOCK_SIZE; off++) {
byte* p = input + off;
byte* a = aad + off;
byte* c = cipher + off;
byte* d = plain + off;
XMEMSET(input, 0, sizeof(input));
XMEMSET(aad, 0, sizeof(aad));
XMEMSET(cipher, 0, sizeof(cipher));
XMEMSET(plain, 0, sizeof(plain));
XMEMSET(tag, 0, sizeof(tag));
for (i = 0; i < SCE_AESGCM_MISALIGNED_SZ; i++) {
p[i] = (byte)i;
a[i] = (byte)(0x80 + i);
}
if (wc_AesGcmSetKey(aes, (byte*)aes_key, keySz) != 0) {
ret = -2;
goto out;
}
if (wc_AesGcmEncrypt(aes, c, p, SCE_AESGCM_MISALIGNED_SZ, iv,
(word32)sizeof(iv), tag, WC_AES_BLOCK_SIZE, a,
SCE_AESGCM_MISALIGNED_SZ) != 0) {
ret = -3;
goto out;
}
/* The aligned pass sets the expected result for every other
* offset. */
if (off == 0) {
XMEMCPY(refCipher, c, SCE_AESGCM_MISALIGNED_SZ);
XMEMCPY(refTag, tag, WC_AES_BLOCK_SIZE);
}
else if ((XMEMCMP(refCipher, c, SCE_AESGCM_MISALIGNED_SZ) != 0) ||
(XMEMCMP(refTag, tag, WC_AES_BLOCK_SIZE) != 0)) {
ret = -4;
goto out;
}
if (wc_AesGcmSetKey(aes, (byte*)aes_key, keySz) != 0) {
ret = -5;
goto out;
}
if (wc_AesGcmDecrypt(aes, d, c, SCE_AESGCM_MISALIGNED_SZ, iv,
(word32)sizeof(iv), tag, WC_AES_BLOCK_SIZE, a,
SCE_AESGCM_MISALIGNED_SZ) != 0) {
ret = -6;
goto out;
}
if (XMEMCMP(p, d, SCE_AESGCM_MISALIGNED_SZ) != 0) {
ret = -7;
goto out;
}
}
ret = 0;
out:
wc_AesFree(aes);
if (prnt) {
RESULT_STR(ret)
}
return ret;
}
#undef SCE_AESGCM_MISALIGNED_SZ
#endif /* WOLFSSL_AES_128 || WOLFSSL_AES_256 */
#if !defined(NO_RSA)
/* testing rsa sign/verify w/ rsa 2048 bit key */
@@ -875,6 +986,20 @@ int sce_crypt_test()
if (ret == 0) {
ret = sce_aesgcm256_test(1, &g_user_aes256_key_index1, devId);
}
#if defined(WOLFSSL_AES_128)
if (ret == 0) {
ret = sce_aesgcm_misaligned_test(1, &g_user_aes128_key_index1,
WC_AES_BLOCK_SIZE, devId);
}
#endif
#if defined(WOLFSSL_AES_256)
if (ret == 0) {
ret = sce_aesgcm_misaligned_test(1, &g_user_aes256_key_index1,
WC_AES_BLOCK_SIZE*2, devId);
}
#endif
printf(" \n");
if (ret == 0) {
printf(" multi sha thread test\n");

View File

@@ -1,39 +1,106 @@
# Create/Update Signed CA
This document describes how to create/update Signed CA data that is used at an example program.
## Signed CA Creation
### Generate RSA Key pair
```
2048 bit RSA key pair
$ openssl genrsa 2048 2> /dev/null > rsa_private.pem
$ openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem 2> /dev/null
```
### Sign to CA certificate
```
Signed by 2048-bit RSA
$ openssl dgst -sha256 -sign rsa_private.pem -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1-out <signed-CA>.sign <CA-file-for-Signed>
For an example program, it assumes that wolfSSL example CA cert is to be signed.
e.g.
$ openssl dgst -sha256 -sign rsa_private.pem -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1-out Signed-CA.sign /path/for/wolfssl/certs/ca-cert.der
```
### Convert Signed CA to C source
It is able to use `dertoc.pl` to generate c-source data from signed-ca binary data.
```
$ /path/to/wolfssl/scripts/dertoc.pl ./ca-cert.der.sign ca_cert_der_sig example.c
```
## Appendix
### Example Keys
There are multiple example keys for testing in the `example_keys` folder.
```
<example_keys>
|
+----+ rsa_private.pem an example 2048-bit rsa private key for signing CA cert
+ rsa_public.pem an example 2048-bit rsa public key for verifying CA cert
+ generate_signCA.sh an example script to generate signed-certificate data for the example program
```
# Create/Update Signed CA
This document describes how to create/update the "Signed CA" data used by the RA6M4
example program (FSPSM/SCE-backed TLS demo): a wolfSSL example CA certificate, signed
with an RSA-PSS signature over its own DER bytes, then converted to a C byte array for
`#include` into the demo sources.
## Quick start
`example_keys/generate_SignedCA.sh` automates the whole process (sign, verify, convert to
C). A Windows wrapper, `example_keys/generate_SignedCA.bat`, is also provided so it can be
run directly from `cmd.exe`/PowerShell without opening a shell manually.
Requires:
- `openssl` on `PATH`
- `perl` on `PATH` (for `<wolfssl>/scripts/dertoc.pl`)
- On Windows: [Git for Windows](https://git-scm.com/download/win) (its bundled
`bash.exe`/`openssl`/`perl` are what `generate_SignedCA.bat` uses; set `GIT_BASH` to
override the default install path if it's somewhere other than
`C:\Program Files\Git\bin\bash.exe`)
Run from inside `example_keys/` (both scripts write output next to themselves, and the
`wolfssl`-dir argument is a fixed relative path from there):
```
cd example_keys
# Windows
generate_SignedCA.bat RSA # signs .../wolfssl/certs/ca-cert.der
generate_SignedCA.bat ECC # signs .../wolfssl/certs/ca-ecc-cert.der
# Linux/macOS/Git Bash
./generate_SignedCA.sh rsa_private.pem rsa_public.pem \
../../../../../../../wolfssl/certs/ca-cert.der ../../../../../../../wolfssl
./generate_SignedCA.sh rsa_private.pem rsa_public.pem \
../../../../../../../wolfssl/certs/ca-ecc-cert.der ../../../../../../../wolfssl
```
Each run produces, next to the input file's basename:
- `<name>.der.sign` -- the raw RSA-PSS signature bytes
- `<name>.der.c` -- the signature converted to a C byte array (see below)
**The generated C array is named `XXXXXXX`** -- `dertoc.pl` (see below) always names it
from its second argument, and the script always passes the placeholder `XXXXXXX`. Rename
`XXXXXXX`/`sizeof_XXXXXXX` in the output `.c` file to a real symbol (e.g.
`ca_cert_der_sign`, matching what `wc_sce_inform_cert_sign()` expects in
`test/src/test_main.c`) before using it.
## What the script does (manual equivalent)
If you need to customize a step, this is what `generate_SignedCA.sh`/`.bat` runs under
the hood.
### 1. Generate an RSA key pair (one-time; already done for `rsa_private.pem`/`rsa_public.pem`)
```
$ openssl genrsa 2048 2> /dev/null > rsa_private.pem
$ openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem 2> /dev/null
```
### 2. Sign the CA certificate with RSA-PSS
```
$ openssl dgst -sha256 -sign rsa_private.pem \
-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 \
-out <signed-CA>.sign <CA-file-to-sign>
# e.g., signing wolfSSL's example CA cert:
$ openssl dgst -sha256 -sign rsa_private.pem \
-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 \
-out ca-cert.der.sign /path/to/wolfssl/certs/ca-cert.der
```
The script also verifies the signature both ways (`-prverify` with the private key,
`-verify` with the public key) immediately after signing, as a sanity check.
### 3. Convert the signature to a C source file
```
$ /path/to/wolfssl/scripts/dertoc.pl ./ca-cert.der.sign XXXXXXX ca-cert.der.c
```
`dertoc.pl <input-file> <c-array-name> <output.c>` emits:
```c
static const unsigned char <c-array-name>[] = { /* ...hex bytes... */ };
static const int sizeof_<c-array-name> = sizeof(<c-array-name>);
```
## Appendix
### example_keys/ contents
```
example_keys/
+-- rsa_private.pem 2048-bit RSA private key, used to sign CA certs
+-- rsa_public.pem matching public key, used to verify the signature
+-- generate_SignedCA.sh sign + verify + convert to C, in one step (Linux/macOS/Git Bash)
+-- generate_SignedCA.bat Windows cmd.exe/PowerShell wrapper (calls the .sh via Git Bash)
```
Running the script above also writes `<name>.der.sign` and `<name>.der.c` next to it
(e.g. `ca-cert.der.sign`/`ca-cert.der.c`, `ca-ecc-cert.der.sign`/`ca-ecc-cert.der.c`) --
these are generated output, not checked into this tree.

View File

@@ -0,0 +1,41 @@
@echo off
REM EnableDelayedExpansion so GIT_BASH (a user-overridable install path) can be echoed
REM safely inside an if-block -- see build.bat's ARM_GCC_BIN handling for why %VAR%
REM alone is risky there if the path ever contains parens (e.g. "Program Files (x86)").
setlocal EnableDelayedExpansion
REM --- Wrapper so generate_SignedCA.sh can be run directly from cmd.exe/PowerShell,
REM without opening a Git Bash shell manually. Requires Git for Windows (bash.exe,
REM plus its bundled openssl/perl, which the .sh script also needs). Set GIT_BASH in
REM the environment before calling this to override the default install path below. ---
if not defined GIT_BASH set GIT_BASH=C:\Program Files\Git\bin\bash.exe
set BASEDIR=%~dp0
set SCRIPT=%BASEDIR%generate_SignedCA.sh
if not exist "%GIT_BASH%" (
echo [ERROR] Git Bash not found at "!GIT_BASH!".
echo Install Git for Windows ^(https://git-scm.com/download/win^), or set GIT_BASH
echo to your bash.exe path, then re-run.
exit /b 1
)
if not exist "%SCRIPT%" (
echo [ERROR] "%SCRIPT%" not found.
exit /b 1
)
REM Fixed args, matching the .sh script's own header-comment usage examples: only the
REM target .der file (RSA -> ca-cert.der, ECC -> ca-ecc-cert.der) varies with the mode.
set DERFILE=
if /i "%1"=="RSA" (
set DERFILE=ca-cert.der
) else if /i "%1"=="ECC" (
set DERFILE=ca-ecc-cert.der
) else (
echo [ERROR] Usage: generate_SignedCA.bat ^<RSA^|ECC^>
echo RSA -^> signs ../../../../../../../wolfssl/certs/ca-cert.der
echo ECC -^> signs ../../../../../../../wolfssl/certs/ca-ecc-cert.der
exit /b 1
)
"%GIT_BASH%" "%SCRIPT%" rsa_private.pem rsa_public.pem ../../../../../../../wolfssl/certs/!DERFILE! ../../../../../../../wolfssl
exit /b %ERRORLEVEL%

View File

@@ -336,7 +336,11 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
uint8_t* plainBuf = NULL;
uint8_t* cipherBuf = NULL;
uint8_t* aTagBuf = NULL;
uint8_t* aadBuf = NULL;
uint8_t delta;
uint8_t aadDelta;
int initOk = 0;
int updateOk = 0;
const uint8_t* iv_l = NULL;
uint32_t ivSz_l = 0;
@@ -354,6 +358,13 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
return BAD_FUNC_ARG;
}
/* aadDelta below pads authInSz up to a whole AES block; reject sizes
* where authInSz + aadDelta would overflow word32 and under-allocate
* aadBuf relative to the XMEMCPY into it. */
if (authInSz > (word32)WOLFSSL_MAX_32BIT - (WC_AES_BLOCK_SIZE - 1)) {
return BAD_FUNC_ARG;
}
ret = wc_local_AesGcmCheckTagSz(authTagSz);
if (ret != 0)
return ret;
@@ -387,9 +398,23 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
cipherBuf = XMALLOC(sz + delta, aes->heap, DYNAMIC_TYPE_AES);
aTagBuf = XMALLOC(SCE_AES_GCM_AUTH_TAG_SIZE, aes->heap,
DYNAMIC_TYPE_AES);
/* authIn (AAD) is the caller's own buffer and isn't guaranteed to be
* aligned the way SCE requires (e.g. a real TLS record's AAD isn't
* word-aligned) -- bounce it through an aligned buffer like the
* plaintext/ciphertext/tag above, instead of passing it to the
* hardware update call directly. Padded up to a whole number of
* blocks (like cipherBuf) in case the hardware AAD-update routine
* touches memory in block-sized units rather than exactly authInSz
* bytes. */
aadDelta = (authInSz == 0 || (authInSz % WC_AES_BLOCK_SIZE) == 0) ? 0 :
(byte)(WC_AES_BLOCK_SIZE - (authInSz % WC_AES_BLOCK_SIZE));
aadBuf = (authInSz > 0) ?
XMALLOC(authInSz + aadDelta, aes->heap, DYNAMIC_TYPE_AES) :
NULL;
if ((sz > 0 && plainBuf == NULL) ||
((sz + delta) > 0 && cipherBuf == NULL) || aTagBuf == NULL) {
((sz + delta) > 0 && cipherBuf == NULL) || aTagBuf == NULL ||
(authInSz > 0 && aadBuf == NULL)) {
WOLFSSL_MSG("wc_fspsm_AesGcmEncrypt: buffer allocation failed");
ret = -1;
}
@@ -398,6 +423,10 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
XMEMCPY(plainBuf, in, sz);
XMEMSET((void*)cipherBuf, 0, sz + delta);
XMEMSET((void*)authTag, 0, authTagSz);
if (authInSz > 0) {
XMEMSET((void*)aadBuf, 0, authInSz + aadDelta);
XMEMCPY(aadBuf, authIn, authInSz);
}
}
#if defined(WOLFSSL_RENESAS_FSPSM_TLS)
@@ -416,6 +445,7 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aadBuf, aes->heap, DYNAMIC_TYPE_AES);
wc_fspsm_hw_unlock();
return MEMORY_E;
}
@@ -454,62 +484,69 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
}
if (ret == 0) {
/* since generated session key is coupled to iv, no need to pass
* them init func.
*/
ret = initFn(&_handle, key_client_aes, (uint8_t*)iv_l, ivSz_l);
initOk = (ret == FSP_SUCCESS);
if (ret == FSP_SUCCESS) {
/* pass only AAD and it's size before passing cipher text */
#if defined(WOLFSSL_RENESAS_RSIP) &&\
(WOLFSSL_RENESAS_RZFSP_VER >= 220)
ret = _R_RSIP_AES_GCM_ADDUpdate((uint8_t*)authIn, authInSz);
ret = _R_RSIP_AES_GCM_ADDUpdate(aadBuf, authInSz);
#else
ret = updateFn(&_handle, NULL, NULL, 0UL, (uint8_t*)authIn,
ret = updateFn(&_handle, NULL, NULL, 0UL, aadBuf,
authInSz,
&out_len_tmp);
#endif
}
if (ret == FSP_SUCCESS) {
out_len_tmp = 0;
ret = updateFn(&_handle, plainBuf, cipherBuf, sz, NULL, 0UL,
&out_len_tmp);
out_len += out_len_tmp;
}
if (ret != FSP_SUCCESS) {
updateOk = (ret == FSP_SUCCESS);
if (!updateOk) {
WOLFSSL_MSG("R_XXXX_AesXXXGcmEncryptUpdate2: failed");
ret = -1;
}
if (ret == FSP_SUCCESS) {
/* Once R_SCE_AesxxxGcmEncryptInit or R_SCE_AesxxxEncryptUpdate is
* called, R_SCE_AesxxxGcmEncryptFinal must be called regardless of
* the result of the previous call. Otherwise, SCE can not come out
* from its error state and all the trailing APIs will fail.
*/
/* Once R_SCE_AesxxxGcmEncryptInit or R_SCE_AesxxxEncryptUpdate is
* called, R_SCE_AesxxxGcmEncryptFinal must be called regardless of
* the result of the previous call. Otherwise, SCE can not come out
* from its error state and all the trailing APIs will fail. This
* only holds once Init has actually succeeded, though -- if Init
* itself failed, _handle was never populated by the hardware, so
* calling Final on it is undefined behavior instead of a cleanup
* step (this used to happen unconditionally here and could hang
* or crash on an Init failure). */
if (!initOk) {
ret = -1;
}
else {
dataLen = 0;
out_len_tmp = 0;
ret = finalFn(&_handle,
cipherBuf + (sz + delta - WC_AES_BLOCK_SIZE),
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
&out_len_tmp,
#else
&dataLen,
#endif
aTagBuf);
cipherBuf + (sz + delta - WC_AES_BLOCK_SIZE),
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
&out_len_tmp,
#else
&dataLen,
#endif
aTagBuf);
if (ret == FSP_SUCCESS) {
if (ret == FSP_SUCCESS && updateOk) {
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
out_len += out_len_tmp;
dataLen = out_len;
#endif
/* copy encrypted data to out */
/* copy encrypted data to out */
if (sz != dataLen) {
WOLFSSL_MSG("sz is not equal to dataLen!!!!");
ret = -1;
} else {
}
else {
XMEMCPY(out, cipherBuf, dataLen);
/* copy auth tag to caller's buffer */
XMEMCPY((void*)authTag, (void*)aTagBuf,
@@ -517,15 +554,17 @@ int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out,
}
}
else {
WOLFSSL_MSG("R_SCE_AesxxxGcmEncryptFinal: failed");
if (ret != FSP_SUCCESS) {
WOLFSSL_MSG("R_SCE_AesxxxGcmEncryptFinal: failed");
}
ret = -1;
}
}
}
XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aadBuf, aes->heap, DYNAMIC_TYPE_AES);
if (info->internal->keyflgs_tls.bits.session_key_set == 1 &&
key_client_aes != NULL)
XFREE(key_client_aes, aes->heap, DYNAMIC_TYPE_AES);
@@ -571,7 +610,11 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
uint8_t* cipherBuf = NULL;
uint8_t* plainBuf = NULL;
uint8_t* aTagBuf = NULL;
uint8_t* aadBuf = NULL;
uint8_t delta;
uint8_t aadDelta;
int initOk = 0;
int updateOk = 0;
const uint8_t* iv_l = NULL;
uint32_t ivSz_l = 0;
@@ -588,6 +631,13 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
return BAD_FUNC_ARG;
}
/* aadDelta below pads authInSz up to a whole AES block; reject sizes
* where authInSz + aadDelta would overflow word32 and under-allocate
* aadBuf relative to the XMEMCPY into it. */
if (authInSz > (word32)WOLFSSL_MAX_32BIT - (WC_AES_BLOCK_SIZE - 1)) {
return BAD_FUNC_ARG;
}
if (authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ) {
WOLFSSL_MSG("GcmDecrypt authTagSz too small error");
return BAD_FUNC_ARG;
@@ -620,8 +670,20 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
plainBuf = XMALLOC(sz + delta, aes->heap, DYNAMIC_TYPE_AES);
aTagBuf = XMALLOC(SCE_AES_GCM_AUTH_TAG_SIZE, aes->heap,
DYNAMIC_TYPE_AES);
/* authIn (AAD) is the caller's own buffer and isn't guaranteed to be
* aligned the way SCE requires -- bounce it through an aligned
* buffer like the plaintext/ciphertext/tag above. Padded up to a
* whole number of blocks in case the hardware AAD-update routine
* touches memory in block-sized units rather than exactly
* authInSz bytes. */
aadDelta = (authInSz == 0 || (authInSz % WC_AES_BLOCK_SIZE) == 0) ? 0 :
(byte)(WC_AES_BLOCK_SIZE - (authInSz % WC_AES_BLOCK_SIZE));
aadBuf = (authInSz > 0) ?
XMALLOC(authInSz + aadDelta, aes->heap, DYNAMIC_TYPE_AES) :
NULL;
if (plainBuf == NULL || cipherBuf == NULL || aTagBuf == NULL) {
if (plainBuf == NULL || cipherBuf == NULL || aTagBuf == NULL ||
(authInSz > 0 && aadBuf == NULL)) {
ret = -1;
}
@@ -629,6 +691,10 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
XMEMSET((void*)plainBuf, 0, sz);
XMEMCPY(cipherBuf, in, sz);
XMEMCPY(aTagBuf, authTag, authTagSz);
if (authInSz > 0) {
XMEMSET((void*)aadBuf, 0, authInSz + aadDelta);
XMEMCPY(aadBuf, authIn, authInSz);
}
}
#if defined(WOLFSSL_RENESAS_FSPSM_TLS)
if (ret == 0 &&
@@ -646,6 +712,7 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aadBuf, aes->heap, DYNAMIC_TYPE_AES);
wc_fspsm_hw_unlock();
return MEMORY_E;
}
@@ -687,15 +754,15 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
* func. Pass NULL and 0 as 3rd and 4th parameter respectively.
*/
ret = initFn(&_handle, key_server_aes, (uint8_t*)iv_l, ivSz_l);
initOk = (ret == FSP_SUCCESS);
if (ret == FSP_SUCCESS) {
/* pass only AAD and it's size before passing cipher text */
#if defined(WOLFSSL_RENESAS_RSIP) &&\
(WOLFSSL_RENESAS_RZFSP_VER >= 220)
ret = _R_RSIP_AES_GCM_ADDUpdate((uint8_t*)authIn, authInSz);
ret = _R_RSIP_AES_GCM_ADDUpdate(aadBuf, authInSz);
#else
ret = updateFn(&_handle, NULL, NULL, 0UL, (uint8_t*)authIn,
ret = updateFn(&_handle, NULL, NULL, 0UL, aadBuf,
authInSz, &out_len_tmp);
#endif
}
@@ -705,25 +772,37 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
plainBuf, sz, NULL, 0UL, &out_len_tmp);
out_len += out_len_tmp;
}
if (ret != FSP_SUCCESS) {
updateOk = (ret == FSP_SUCCESS);
if (!updateOk) {
WOLFSSL_MSG("R_XXXX_AesXXXGcmDecryptUpdate: failed in decrypt");
ret = -1;
}
if (ret == FSP_SUCCESS) {
/* Once R_SCE_AesxxxGcmDecryptInit or R_SCE_AesxxxGcmDecryptUpdate
* is called, R_SCE_AesxxxGcmDecryptFinal must be called regardless
* of the result of the previous call. Otherwise, SCE can not come
* out from its error state and all the trailing APIs will fail.
* This only holds once Init has actually succeeded, though -- if
* Init itself failed, _handle was never populated by the
* hardware, so calling Final on it is undefined behavior instead
* of a cleanup step. */
if (!initOk) {
ret = -1;
}
else {
dataLen = 0;
out_len_tmp = 0;
ret = finalFn(&_handle,
plainBuf + (sz + delta - WC_AES_BLOCK_SIZE),
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
&out_len_tmp,
#else
&dataLen,
#endif
aTagBuf,
min(16, authTagSz));
plainBuf + (sz + delta - WC_AES_BLOCK_SIZE),
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
&out_len_tmp,
#else
&dataLen,
#endif
aTagBuf, min(16, authTagSz));
if (ret == FSP_SUCCESS) {
if (ret == FSP_SUCCESS && updateOk) {
#if (WOLFSSL_RENESAS_RZFSP_VER >= 220)
out_len += out_len_tmp;
dataLen = out_len;
@@ -737,16 +816,29 @@ int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out,
XMEMCPY(out, plainBuf, dataLen);
}
}
else {
else if (ret != FSP_SUCCESS) {
WOLFSSL_MSG("R_XXXX_AesXXXGcmDecryptFinal: failed");
/* Only map to AES_GCM_AUTH_E
if Update actually succeeded. */
if (updateOk &&
(ret == FSP_ERR_CRYPTO_SCE_AUTHENTICATION ||
ret == FSP_ERR_CRYPTO_AUTHENTICATION_FAILED)) {
ret = AES_GCM_AUTH_E;
}
else {
ret = -1;
}
}
else {
/* Final reported success, but Update had already failed. */
ret = -1;
}
}
}
XFREE(aTagBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES);
XFREE(aadBuf, aes->heap, DYNAMIC_TYPE_AES);
if (info->internal->keyflgs_tls.bits.session_key_set == 1 &&
key_client_aes != NULL)
XFREE(key_client_aes, aes->heap, DYNAMIC_TYPE_AES);

View File

@@ -209,6 +209,12 @@ static int FSPSM_HashCopy(wolfssl_FSPSM_Hash* src, wolfssl_FSPSM_Hash* dst)
return BAD_FUNC_ARG;
}
/* If dst already holds its own msg buffer (e.g. it was Update()'d
* before being used as a Copy() destination), the XMEMCPY below
* overwrites that pointer with src's, leaking the old allocation.
* Free it first. */
FSPSM_HashFree(dst);
XMEMCPY(dst, src, sizeof(wolfssl_FSPSM_Hash));
#if defined(WOLFSSL_RENESAS_SCEPROTECT) || \

View File

@@ -3585,7 +3585,25 @@ int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst)
dst->flags |= WC_HASH_FLAG_ISCOPY;
#endif
#if defined(WOLFSSL_HASH_KEEP)
/* The XMEMCPY(dst, src, sizeof(wc_Sha256)) above copies src->msg as a
* raw pointer value, aliasing dst->msg to the same heap block. For any
* backend that buffers the whole message in sha256->msg (see the
* matching condition in wc_Sha256Free() above), that block later gets
* freed once via src's own Final()/Free() call and a second time via
* dst's -- a double free that silently corrupts the heap a little more
* on every wc_Sha256Copy()+wc_Sha256Free(dst) pair, instead of crashing
* outright. Give dst its own independent copy so the two objects don't
* share ownership of the same allocation. */
#if defined(WOLFSSL_HASH_KEEP) || \
(defined(WOLFSSL_AFALG_HASH) && defined(WOLFSSL_AFALG_HASH_KEEP)) || \
(defined(WOLFSSL_DEVCRYPTO_HASH) && defined(WOLFSSL_DEVCRYPTO_HASH_KEEP)) || \
((defined(WOLFSSL_RENESAS_TSIP_TLS) || \
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)) && \
!defined(NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH)) || \
((defined(WOLFSSL_RENESAS_SCEPROTECT) || \
(defined(WOLFSSL_RENESAS_RSIP) && (WOLFSSL_RENESAS_RZFSP_VER >= 220))) && \
!defined(NO_WOLFSSL_RENESAS_FSPSM_HASH)) || \
defined(WOLFSSL_RENESAS_RX64_HASH)
if (src->msg != NULL) {
dst->msg = (byte*)XMALLOC(src->len, dst->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (dst->msg == NULL)

View File

@@ -23091,7 +23091,8 @@ out:
#endif /* WOLFSSL_AESGCM_SIV */
#if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
!defined(WOLFSSL_XILINX_CRYPT)
!defined(WOLFSSL_XILINX_CRYPT) && \
!defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
/* Number of bytes of data and AAD hashed - a whole number of blocks so the
* bulk GHASH path is taken with the misaligned pointer. */
@@ -23206,7 +23207,7 @@ out:
#undef AESGCM_MISALIGNED_SZ
#endif /* WOLFSSL_AES_128 && !WOLFSSL_AFALG_XILINX_AES &&
* !WOLFSSL_XILINX_CRYPT */
* !WOLFSSL_XILINX_CRYPT && !WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY */
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
{
@@ -23262,7 +23263,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
ERROR_OUT(ret, out);
#if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
!defined(WOLFSSL_XILINX_CRYPT)
!defined(WOLFSSL_XILINX_CRYPT) && \
!defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
ret = aesgcm_misaligned_test(enc, dec);
if (ret != 0)
ERROR_OUT(ret, out);