Skip to content

Commit 4b8e4b7

Browse files
bigbrettdanielinux
authored andcommitted
Additional fixes for new keytool features introduced in #521
1 parent ceffc78 commit 4b8e4b7

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

IDE/AURIX/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ cd $WOLFBOOT_DIR
292292

293293
# Start with a clean build
294294
make clean && make keysclean && cd $WOLFBOOT_DIR/tools/keytools && make clean
295-
cd $SCRIPTS_DIR && ./aurixtool.sh clean
295+
cd $SCRIPTS_DIR && ./wbaurixtool.sh clean
296296
# Delete any build artifacts in wolfBoot-tc3xx (or wolfBoot-tc3xx-wolfHSM) and test-app (or test-app-wolfHSM) AURIX Studio projects
297297
# ...
298298

@@ -303,13 +303,13 @@ make keytools
303303

304304
# Generate target.h
305305
cd $SCRIPTS_DIR
306-
./aurixtool.sh target
306+
./wbaurixtool.sh target
307307

308308
# Generate keys, as well as configuration macros and linker script based on the selected signature algorithm
309-
./aurixtool.sh [--hsm] keygen --sign-algo ecc256 --hash-algo sha256 macros lcf
309+
./wbaurixtool.sh [--hsm] keygen --sign-algo ecc256 --hash-algo sha256 macros lcf
310310

311311
# If using wolfHSM, generate key NVM image
312-
./aurixtool.sh nvm
312+
./wbaurixtool.sh nvm
313313
# Load NVM image hexfile to the device
314314
# ...
315315

@@ -320,7 +320,7 @@ cd $SCRIPTS_DIR
320320
# ....
321321

322322
# Sign test app
323-
./aurixtool.sh [--hsm] sign --sign-algo ecc256 --hash-algo sha256 [--debug]
323+
./wbaurixtool.sh [--hsm] sign --sign-algo ecc256 --hash-algo sha256 [--debug]
324324

325325
# Load wolfBoot + app in Lauterbach using tools/scripts/tc3xx/wolfBoot-loadAll-XXX.cmm
326326
# ...

IDE/AURIX/test-app-wolfHSM/Cpu0_Main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "IfxPort.h"
2323
#include "IfxScuWdt.h"
2424
#include "Ifx_Types.h"
25+
26+
#include "target.h"
2527
#include "wolfboot/wolfboot.h"
2628

2729
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

IDE/AURIX/test-app/Cpu0_Main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "IfxPort.h"
2323
#include "IfxScuWdt.h"
2424
#include "Ifx_Types.h"
25+
26+
#include "target.h"
2527
#include "wolfboot/wolfboot.h"
2628

2729
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

config/examples/sim-wolfHSM-mldsa.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ DEBUG=1
1212
# Category 2:
1313
ML_DSA_LEVEL=2
1414
IMAGE_SIGNATURE_SIZE=2420
15-
IMAGE_HEADER_SIZE?=8192
15+
IMAGE_HEADER_SIZE=8192
1616
#
1717
# Category 3:
1818
# ML_DSA_LEVEL=3
1919
# IMAGE_SIGNATURE_SIZE=3309
20-
# IMAGE_HEADER_SIZE?=8192
20+
# IMAGE_HEADER_SIZE=8192
2121
#
2222
# Category 5:
2323
# ML_DSA_LEVEL=5
2424
# IMAGE_SIGNATURE_SIZE=4627
25-
# IMAGE_HEADER_SIZE?=12288
25+
# IMAGE_HEADER_SIZE=12288
2626
# This example needs a larger sector size.
2727
# WOLFBOOT_SECTOR_SIZE=0x3000
2828
#

tools/scripts/tc3xx/wbaurixtool.sh

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ get_header_size() {
100100
"rsa4096") echo "1024" ;;
101101
"ed25519") echo "256" ;;
102102
"ed448") echo "512" ;;
103-
"lms"|"xmss") echo "0" ;;
103+
"lms"|"xmss") echo "0" ;; # currently not supported
104104
"none") echo "256" ;;
105105
*) echo "256" ;; # Default
106106
esac
@@ -164,10 +164,22 @@ usage() {
164164

165165
# Function to generate keys
166166
do_keygen() {
167-
local base_dir="../../../"
167+
local sign_algo="${KEYGEN_OPTS[sign_algo]:-$DEFAULT_SIGN_ALGO}"
168+
local pq_params="${COMMON_OPTS[sign_pq_params]}"
169+
local header_size
170+
171+
# Get header size for current algorithm
172+
header_size=$(get_header_size "$sign_algo" "$pq_params")
173+
174+
echo "Generating keys with algorithm: $sign_algo"
175+
176+
# Set environment variables for keygen tool
177+
export IMAGE_HEADER_SIZE="$header_size"
178+
if [ "$sign_algo" = "ml_dsa" ]; then
179+
export ML_DSA_LEVEL="${pq_params:-2}" # Default to level 2 if not specified
180+
fi
168181

169-
echo "Generating keys with algorithm: ${KEYGEN_OPTS[sign_algo]}"
170-
(cd $base_dir && tools/keytools/keygen --"${KEYGEN_OPTS[sign_algo]}" -g $(basename $PRVKEY_DER) --exportpubkey \
182+
(cd $WOLFBOOT_DIR && tools/keytools/keygen --"$sign_algo" -g $(basename $PRVKEY_DER) --exportpubkey \
171183
${KEYGEN_OPTS[nolocalkeys]:+--nolocalkeys} --der)
172184
}
173185

@@ -176,9 +188,18 @@ do_sign() {
176188
local base_path="../../../IDE/AURIX"
177189
local app_name="test-app${HSM:+-wolfHSM}"
178190
local sign_algo="${SIGN_OPTS[sign_algo]:-${KEYGEN_OPTS[sign_algo]}}"
191+
local pq_params="${COMMON_OPTS[sign_pq_params]}"
192+
local header_size
193+
local bin_path="$base_path/$app_name/TriCore ${SIGN_OPTS[build_type]} (GCC)/$app_name.bin"
194+
195+
# Get header size for current algorithm
196+
header_size=$(get_header_size "$sign_algo" "$pq_params")
197+
198+
# Set IMAGE_HEADER_SIZE environment variable for sign tool
199+
export IMAGE_HEADER_SIZE="$header_size"
179200

180201
echo "Signing binaries with $sign_algo and ${SIGN_OPTS[hash_algo]}"
181-
local bin_path="$base_path/$app_name/TriCore ${SIGN_OPTS[build_type]} (GCC)/$app_name.bin"
202+
echo "Using header size: $header_size"
182203

183204
# Sign for both partition 1 and 2
184205
../../keytools/sign --"$sign_algo" --"${SIGN_OPTS[hash_algo]}" "$bin_path" "$PRVKEY_DER" 1
@@ -264,11 +285,24 @@ do_gen_macros() {
264285
use_wolfhsm_pubkey_id="-DWOLFBOOT_USE_WOLFHSM_PUBKEY_ID"
265286
fi
266287

267-
# Set image signature size and ML-DSA level only for ML-DSA
288+
# Quirk: set additional (redundant) macros for ML DSA based on pq_params
268289
if [[ "${sign_algo,,}" == ml_dsa* ]]; then
269-
image_signature_size="-DIMAGE_SIGNATURE_SIZE=2420"
270-
ml_dsa_image_signature_size="-DML_DSA_IMAGE_SIGNATURE_SIZE=2420"
271-
ml_dsa_level="-DML_DSA_LEVEL=2"
290+
local level="${pq_params:-2}" # Default to level 2 if not specified
291+
case "$level" in
292+
2)
293+
image_signature_size="-DIMAGE_SIGNATURE_SIZE=2420"
294+
ml_dsa_image_signature_size="-DML_DSA_IMAGE_SIGNATURE_SIZE=2420"
295+
;;
296+
3)
297+
image_signature_size="-DIMAGE_SIGNATURE_SIZE=3300"
298+
ml_dsa_image_signature_size="-DML_DSA_IMAGE_SIGNATURE_SIZE=3300"
299+
;;
300+
5)
301+
image_signature_size="-DIMAGE_SIGNATURE_SIZE=5200"
302+
ml_dsa_image_signature_size="-DML_DSA_IMAGE_SIGNATURE_SIZE=5200"
303+
;;
304+
esac
305+
ml_dsa_level="-DML_DSA_LEVEL=$level"
272306
fi
273307

274308
echo "Generating macros file with sign_algo=$sign_algo, hash_algo=$hash_algo"

0 commit comments

Comments
 (0)