/* loader.h * * Public key information for the signed images * * * Copyright (C) 2026 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 this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #ifndef LOADER_H #define LOADER_H #include #ifdef __cplusplus extern "C" { #endif #define ED25519_IMAGE_SIGNATURE_SIZE (64) #define ED448_IMAGE_SIGNATURE_SIZE (114) #if defined(WOLFBOOT_SIGN_ECC256) || defined(WOLFBOOT_SIGN_SECONDARY_ECC256) #define ECC_IMAGE_SIGNATURE_SIZE (64) #elif defined(WOLFBOOT_SIGN_ECC384) || defined(WOLFBOOT_SIGN_SECONDARY_ECC384) #define ECC_IMAGE_SIGNATURE_SIZE (96) #elif defined(WOLFBOOT_SIGN_ECC521) || defined(WOLFBOOT_SIGN_SECONDARY_ECC521) #define ECC_IMAGE_SIGNATURE_SIZE (132) #endif /* Consolidated RSA-PSS flag: set when any RSA-PSS variant is enabled * (primary or secondary). Used to guard PSS-specific code paths in the * unified RSA verify function. */ #if defined(WOLFBOOT_SIGN_RSAPSS2048) || defined(WOLFBOOT_SIGN_RSAPSS3072) || \ defined(WOLFBOOT_SIGN_RSAPSS4096) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS2048) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS3072) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS4096) #define WOLFBOOT_SIGN_RSAPSS_ANY #endif /* Consolidated RSA flag: set when any RSA variant is enabled (PKCS#1 v1.5 or * PSS, primary or secondary). Used to guard the unified RSA verify function * and related RSA code paths. */ #if defined(WOLFBOOT_SIGN_RSA2048) || defined(WOLFBOOT_SIGN_RSA3072) || \ defined(WOLFBOOT_SIGN_RSA4096) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSA2048) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSA3072) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSA4096) || \ defined(WOLFBOOT_SIGN_RSAPSS2048) || defined(WOLFBOOT_SIGN_RSAPSS3072) || \ defined(WOLFBOOT_SIGN_RSAPSS4096) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS2048) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS3072) || \ defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS4096) #define WOLFBOOT_SIGN_RSA_ANY #endif #if defined(WOLFBOOT_SIGN_RSA2048) || defined(WOLFBOOT_SIGN_SECONDARY_RSA2048) || \ defined(WOLFBOOT_SIGN_RSAPSS2048) || defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS2048) #define RSA_IMAGE_SIGNATURE_SIZE (256) #elif defined(WOLFBOOT_SIGN_RSA3072) || defined(WOLFBOOT_SIGN_SECONDARY_RSA3072) || \ defined(WOLFBOOT_SIGN_RSAPSS3072) || defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS3072) #define RSA_IMAGE_SIGNATURE_SIZE (384) #elif defined(WOLFBOOT_SIGN_RSA4096) || defined(WOLFBOOT_SIGN_SECONDARY_RSA4096) || \ defined(WOLFBOOT_SIGN_RSAPSS4096) || defined(WOLFBOOT_SIGN_SECONDARY_RSAPSS4096) #define RSA_IMAGE_SIGNATURE_SIZE (512) #endif #ifndef ML_DSA_IMAGE_SIGNATURE_SIZE #define ML_DSA_IMAGE_SIGNATURE_SIZE (3309) #endif void wolfBoot_start(void); #include "hooks.h" #if defined(ARCH_ARM) && defined(WOLFBOOT_ARMORED) /* attempt to jump 5 times to self, causing loop that cannot be glitched past */ #ifdef WOLFBOOT_HOOK_PANIC #define wolfBoot_panic() do { \ wolfBoot_hook_panic(); \ asm volatile("b ."); \ asm volatile("b .-2"); \ asm volatile("b .-4"); \ asm volatile("b .-6"); \ asm volatile("b .-8"); \ } while(0) #else #define wolfBoot_panic() do { \ asm volatile("b ."); \ asm volatile("b .-2"); \ asm volatile("b .-4"); \ asm volatile("b .-6"); \ asm volatile("b .-8"); \ } while(0) #endif #elif defined(ARCH_SIM) #include #include static inline void wolfBoot_panic(void) { #ifdef WOLFBOOT_HOOK_PANIC wolfBoot_hook_panic(); #endif fprintf(stderr, "wolfBoot: PANIC!\n"); exit('P'); } #elif defined UNIT_TEST static int wolfBoot_panicked = 0; static inline void wolfBoot_panic(void) { #ifdef WOLFBOOT_HOOK_PANIC wolfBoot_hook_panic(); #endif fprintf(stderr, "wolfBoot: PANIC!\n"); wolfBoot_panicked++; } #else #include "printf.h" static inline void wolfBoot_panic(void) { #ifdef WOLFBOOT_HOOK_PANIC wolfBoot_hook_panic(); #endif wolfBoot_printf("wolfBoot: PANIC!\n"); #ifdef WOLFBOOT_FSP extern void panic(void); panic(); #endif /* Spin so the watchdog fires and resets the chip (recovery). Do NOT * pet the WDT here -- production must reset out of a panic. */ while(1) ; } #endif #ifdef WOLFCRYPT_SECURE_MODE void wcs_Init(void); #endif #ifdef __cplusplus } #endif #endif /* LOADER_H */