Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wolfHSM support for ML-DSA #523

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
18 changes: 15 additions & 3 deletions .github/workflows/test-wolfhsm-simulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ on:

jobs:
wolfhsm_simulator_test:
# Matrix strategy runs all steps below for each config specified.
# This allows testing multiple configurations without duplicating the workflow.
strategy:
matrix:
config:
- name: "Standard wolfHSM"
file: "config/examples/sim-wolfHSM.config"
- name: "wolfHSM ML-DSA"
file: "config/examples/sim-wolfHSM-mldsa.config"
fail-fast: false

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -25,9 +36,9 @@ jobs:
run: |
make distclean

- name: Select config (wolfHSM simulator)
- name: Select config (${{ matrix.config.name }})
run: |
cp config/examples/sim-wolfHSM.config .config
cp ${{ matrix.config.file }} .config

- name: Build tools
run: |
Expand Down Expand Up @@ -62,5 +73,6 @@ jobs:

# Kill the server if it is still running
- name: Kill POSIX TCP server
if: always()
run: |
kill $TCP_SERVER_PID
kill $TCP_SERVER_PID || true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ IDE/AURIX/Configurations/*
!IDE/AURIX/Configurations/placeholder.txt
IDE/AURIX/wolfHSM-infineon-tc3xx/*
!IDE/AURIX/wolfHSM-infineon-tc3xx/placeholder.txt
IDE/AURIX/wolfBoot-tc3xx/wolfBoot_macros.txt
IDE/AURIX/wolfBoot-tc3xx-wolfHSM/wolfBoot_macros.txt
IDE/AURIX/test-app/Lcf_Gnuc_Tricore_Tc.lsl
IDE/AURIX/test-app-wolfHSM/Lcf_Gnuc_Tricore_Tc.lsl

tpm_seal_key.key

Expand Down
118 changes: 104 additions & 14 deletions IDE/AURIX/README.md

Large diffs are not rendered by default.

611 changes: 611 additions & 0 deletions IDE/AURIX/test-app-wolfHSM/.cproject

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions IDE/AURIX/test-app-wolfHSM/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test-app-wolfHSM</name>
<comment></comment>
<projects>
<project>wolfBoot-tc3xx-wolfHSM</project>
</projects>
<buildSpec>
<buildCommand>
<name>com.infineon.aurix.buildsystem.builders.booster</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.infineon.aurix.buildsystem.builders.autodiscovery</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>com.infineon.aurix.buildsystem.aurixnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>Configurations</name>
<type>2</type>
<locationURI>SDK_CONFIGURATION_DIR</locationURI>
</link>
<link>
<name>Libraries</name>
<type>2</type>
<locationURI>SDK_DIR</locationURI>
</link>
</linkedResources>
<variableList>
<variable>
<name>SDK_CONFIGURATION_DIR</name>
<value>$%7BPARENT-1-PROJECT_LOC%7D/Configurations</value>
</variable>
<variable>
<name>SDK_DIR</name>
<value>$%7BPARENT-1-PROJECT_LOC%7D/SDK</value>
</variable>
</variableList>
</projectDescription>
85 changes: 85 additions & 0 deletions IDE/AURIX/test-app-wolfHSM/Cpu0_Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* Cpu0_Main.c
*
* Copyright (C) 2014-2024 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot 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.
*
* wolfBoot 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 wolfBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Bsp.h"
#include "IfxCpu.h"
#include "IfxPort.h"
#include "IfxScuWdt.h"
#include "Ifx_Types.h"

#include "target.h"
#include "wolfboot/wolfboot.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;


#define LED &MODULE_P00, 5 /* LED: Port, Pin definition */
#define BLINK_TIME_BASE 500 /* Wait time constant in milliseconds */
#define BLINK_TIME_UPDATE 100 /* Wait time constant in milliseconds */

#define BASE_FW_VERSION 1

/* This function initializes the port pin which drives the LED */
static void initLED(void)
{
/* Initialization of the LED used in this example */
IfxPort_setPinModeOutput(LED,
IfxPort_OutputMode_pushPull,
IfxPort_OutputIdx_general);

/* Switch OFF the LED (low-level active) */
IfxPort_setPinLow(LED);
}

void core0_main(void)
{
size_t blinkTime;

IfxCpu_enableInterrupts();

/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

initLED();

if (wolfBoot_current_firmware_version() <= BASE_FW_VERSION) {
/* We are booting into the base firmware, so stage the update and set
* the LED to blink slow */
wolfBoot_update_trigger();
blinkTime = BLINK_TIME_BASE;
}
else {
/* we are booting into the updated firmware so acknowledge the update
* (to prevent rollback) and set the LED to blink fast */
wolfBoot_success();
blinkTime = BLINK_TIME_UPDATE;
}

while (1) {
IfxPort_togglePin(LED);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, blinkTime));
}
}
42 changes: 42 additions & 0 deletions IDE/AURIX/test-app-wolfHSM/Cpu1_Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Cpu1_Main.c
*
* Copyright (C) 2014-2024 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot 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.
*
* wolfBoot 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 wolfBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"

extern IfxCpu_syncEvent g_cpuSyncEvent;

void core1_main(void)
{
IfxCpu_enableInterrupts();

/* !!WATCHDOG1 IS DISABLED HERE!!
* Enable the watchdog and service it periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

while(1)
{
}
}
42 changes: 42 additions & 0 deletions IDE/AURIX/test-app-wolfHSM/Cpu2_Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Cpu2_Main.c
*
* Copyright (C) 2014-2024 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot 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.
*
* wolfBoot 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 wolfBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"

extern IfxCpu_syncEvent g_cpuSyncEvent;

void core2_main(void)
{
IfxCpu_enableInterrupts();

/* !!WATCHDOG2 IS DISABLED HERE!!
* Enable the watchdog and service it periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

while(1)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ LCF_HEAP2_OFFSET = (LCF_USTACK2_OFFSET - LCF_HEAP_SIZE);


LCF_WOLFBOOT_BOOT_PART_BASEADDR = 0xA0300000;
LCF_WOLFBOOT_HEADER_OFFSET = 0x100;

/* size of wolfBoot header, configured by aurixtool.sh based on --sign-algo */
LCF_WOLFBOOT_HEADER_OFFSET = @LCF_WOLFBOOT_HEADER_OFFSET@;

LCF_CODE_BASE_ADDR = LCF_WOLFBOOT_BOOT_PART_BASEADDR + LCF_WOLFBOOT_HEADER_OFFSET;

Expand Down Expand Up @@ -116,10 +118,10 @@ MEMORY
pfls0 (rx!p): org = 0xA0000000, len = 3M

/* placeholder for wolfBoot image header */
pfls1_hdr (rx!p): org = 0xA0300000, len = 256
pfls1_hdr (rx!p): org = LCF_WOLFBOOT_BOOT_PART_BASEADDR, len = LCF_WOLFBOOT_HEADER_OFFSET

/* pfls1 is the remainder of the wolfBoot BOOT partition. Everything goes here */
pfls1 (rx!p): org = 0xA0300100, len = 0x17DF00 /* 0x17E000 - 256B */
pfls1 (rx!p): org = LCF_CODE_BASE_ADDR, len = (0x17E000 - LCF_WOLFBOOT_HEADER_OFFSET)

/* reserved for wolfBoot UPDATE partition */
pfls1_update (rwx!p): org = 0xA047E000, len = 0x17E000 /* ~1.5MiB */
Expand Down
2 changes: 2 additions & 0 deletions IDE/AURIX/test-app/Cpu0_Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "IfxPort.h"
#include "IfxScuWdt.h"
#include "Ifx_Types.h"

#include "target.h"
#include "wolfboot/wolfboot.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
Expand Down
Loading
Loading