remove unnecessary wolfHSM PUBKEY_ID macro

pull/798/head
Brett Nicholas 2026-06-15 14:25:39 -06:00
parent e0e08a7dd2
commit 7195bd8008
3 changed files with 20 additions and 43 deletions

View File

@ -74,16 +74,12 @@ This section describes the configuration options available for wolfHSM integrati
This option enables wolfHSM client support in wolfBoot. Without defining this option, support for wolfHSM client mode is not compiled in.
In client mode, wolfBoot always uses HSM-resident public keys for firmware authentication; public keys are never baked into a local `keystore.c`. The key to verify against is referenced either by the reserved key ID defined in the HAL (`hsmKeyIdPubKey`), or, when certificate-chain verification (`WOLFBOOT_CERT_CHAIN_VERIFY`) is enabled, by the leaf key ID resolved from the verified chain.
### `WOLFBOOT_ENABLE_WOLFHSM_SERVER`
This option enables wolfHSM server support in wolfBoot. When defined, wolfBoot includes an embedded wolfHSM server that provides HSM functionality locally within the bootloader. This is mutually exclusive with `WOLFBOOT_ENABLE_WOLFHSM_CLIENT`.
### `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`
This option enables use of the reserved wolfHSM public key ID for firmware authentication, and is typically the desired behavior for using wolfHSM. When this option is defined, wolfBoot will use the reserved wolfHSM keyId defined by the HAL (`hsmKeyIdPubKey`). This option is meant to be used in conjunction with the `--nolocalkeys` keygen option, as the key material in the keystore will not be used.
If this option is not defined, cryptographic operations are still performed on the wolfHSM server, but wolfBoot assumes the key material is present in the keystore and NOT stored on the HSM. This means that wolfBoot will first load keys from the keystore, send the key material to the wolfHSM server at the time of use (cached as ephemeral keys), and finally evict the key from the HSM after usage. This behavior is typically only useful for debugging or testing scenarios, where the keys may not be pre-loaded onto the HSM. The keystore for use in this mode should not be generated with the `--nolocalkeys` option.
## HAL Implementations
In addition to the standard wolfBoot HAL functions, wolfHSM-enabled platforms must also implement or instantiate the following wolfHSM-specific items in the platform HAL:
@ -126,7 +122,7 @@ The wolfBoot simulator supports using wolfHSM with all algorithms mentioned in [
#### wolfHSM Client Mode Build
To build the simulator configured to use wolfHSM client mode, ensure you build with the `WOLFHSM_CLIENT=1` makefile option. This will automatically define `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`, and requires the public key corresponding to the private key that signed the image to be pre-loaded into the HSM at the keyId specified by `hsmKeyIdPubKey` in the simulator HAL.
To build the simulator configured to use wolfHSM client mode, ensure you build with the `WOLFHSM_CLIENT=1` makefile option. This requires the public key corresponding to the private key that signed the image to be pre-loaded into the HSM at the keyId specified by `hsmKeyIdPubKey` in the simulator HAL.
```sh
# Grab the HSM client simulator configuration

View File

@ -1394,7 +1394,6 @@ ifeq ($(WOLFHSM_CLIENT),1)
# authenticated via a certificate chain. Public keys baked into a local
# keystore.c are not supported.
KEYGEN_OPTIONS += --nolocalkeys
CFLAGS += -DWOLFBOOT_USE_WOLFHSM_PUBKEY_ID
# big enough for cert chain
CFLAGS += -DWOLFHSM_CFG_COMM_DATA_LEN=5000

View File

@ -214,10 +214,8 @@ static void wolfBoot_verify_signature_ecc(uint8_t key_slot,
int ret, verify_res = 0;
ecc_key ecc;
mp_int r, s;
#if (!defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT && \
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)) || \
(defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT && \
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID))
#if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
uint8_t* pubkey = keystore_get_buffer(key_slot);
int pubkey_sz = keystore_get_size(key_slot);
int point_sz = pubkey_sz / 2;
@ -251,7 +249,7 @@ static void wolfBoot_verify_signature_ecc(uint8_t key_slot,
uint8_t tmpSigBuf[ECC_MAX_SIG_SIZE] = {0};
size_t tmpSigSz = sizeof(tmpSigBuf);
#if defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID) || \
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) || \
(defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER) && \
defined(WOLFBOOT_CERT_CHAIN_VERIFY))
(void)key_slot;
@ -281,11 +279,11 @@ static void wolfBoot_verify_signature_ecc(uint8_t key_slot,
ret = wh_Client_EccSetKeyId(&ecc, hsmKeyIdPubKey);
#endif
}
#else
#else /* WOLFBOOT_CERT_CHAIN_VERIFY */
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
ret = wh_Client_EccSetKeyId(&ecc, hsmKeyIdPubKey);
#endif
#endif /* WOLFBOOT_USE_WOLFHSM_PUBKEY_ID */
#endif /* !WOLFBOOT_CERT_CHAIN_VERIFY */
if (ret != 0) {
return;
}
@ -299,7 +297,7 @@ static void wolfBoot_verify_signature_ecc(uint8_t key_slot,
return;
}
#endif /* !WOLFBOOT_USE_WOLFHSM_PUBKEY_ID */
#endif /* WOLFBOOT_ENABLE_WOLFHSM_CLIENT || (SERVER && CERT_CHAIN) */
/* wc_ecc_verify_hash_ex() doesn't trigger a crypto callback, so we need
to use wc_ecc_verify_hash instead. Unfortunately, that requires
converting the signature to intermediate DER format first */
@ -436,10 +434,8 @@ static void wolfBoot_verify_signature_rsa_common(uint8_t key_slot,
#endif
#endif /* WOLFBOOT_SIGN_RSAPSS_ANY */
#if (!defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)) || \
(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID))
#if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
uint8_t *pubkey = keystore_get_buffer(key_slot);
int pubkey_sz = keystore_get_size(key_slot);
@ -472,7 +468,7 @@ static void wolfBoot_verify_signature_rsa_common(uint8_t key_slot,
if (ret != 0) {
return;
}
#if defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID) || \
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) || \
(defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER) && \
defined(WOLFBOOT_CERT_CHAIN_VERIFY))
(void)key_slot;
@ -519,7 +515,7 @@ static void wolfBoot_verify_signature_rsa_common(uint8_t key_slot,
wc_FreeRsaKey(&rsa);
return;
}
#endif /* !WOLFBOOT_USE_WOLFHSM_PUBKEY_ID */
#endif /* WOLFBOOT_ENABLE_WOLFHSM_CLIENT || (SERVER && CERT_CHAIN) */
XMEMCPY(output, sig, RSA_IMAGE_SIGNATURE_SIZE);
#ifdef WOLFBOOT_SIGN_RSAPSS_ANY
if (is_pss) {
@ -532,14 +528,7 @@ static void wolfBoot_verify_signature_rsa_common(uint8_t key_slot,
RSA_VERIFY_FN(ret, wc_RsaSSL_VerifyInline, output,
RSA_IMAGE_SIGNATURE_SIZE, &digest_out, &rsa);
}
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID)
/* evict the key after use, since we aren't using the RSA import API */
if (WH_ERROR_OK != wh_Client_KeyEvict(&hsmClientCtx, hsmKeyId)) {
wc_FreeRsaKey(&rsa);
return;
}
#elif defined(WOLFBOOT_CERT_CHAIN_VERIFY)
#if defined(WOLFBOOT_CERT_CHAIN_VERIFY)
if (g_leafKeyIdValid) {
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
(void)wh_Client_KeyEvict(&hsmClientCtx, g_certLeafKeyId);
@ -548,7 +537,7 @@ static void wolfBoot_verify_signature_rsa_common(uint8_t key_slot,
#endif
g_leafKeyIdValid = 0;
}
#endif /* !WOLFBOOT_USE_WOLFHSM_PUBKEY_ID */
#endif /* WOLFBOOT_CERT_CHAIN_VERIFY */
#else
/* wolfCrypt software RSA verify */
ret = wc_InitRsaKey_ex(&rsa, NULL, WOLFBOOT_DEVID_PUBKEY);
@ -735,9 +724,7 @@ static void wolfBoot_verify_signature_ml_dsa(uint8_t key_slot,
{
int ret = 0;
wc_MlDsaKey ml_dsa;
#if !defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT || \
(defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT && \
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID))
#if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
uint8_t * pubkey = NULL;
int pub_len = 0;
#endif
@ -747,9 +734,7 @@ static void wolfBoot_verify_signature_ml_dsa(uint8_t key_slot,
wolfBoot_printf("info: ML-DSA %d verify_signature: pubkey %d, sig %d\n",
ML_DSA_LEVEL, KEYSTORE_PUBKEY_SIZE, ML_DSA_IMAGE_SIGNATURE_SIZE);
#if !defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT || \
(defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT && \
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID))
#if !defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
pubkey = keystore_get_buffer(key_slot);
if (pubkey == NULL) {
@ -774,8 +759,7 @@ static void wolfBoot_verify_signature_ml_dsa(uint8_t key_slot,
}
}
#if defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT && \
defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID)
#if defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
/* Use key slot ID directly with wolfHSM */
#if defined(WOLFBOOT_CERT_CHAIN_VERIFY)
/* If using certificate chain verification and we have a verified leaf key
@ -820,8 +804,7 @@ static void wolfBoot_verify_signature_ml_dsa(uint8_t key_slot,
ret);
}
}
#endif /* !defined WOLFBOOT_ENABLE_WOLFHSM_CLIENT &&
!defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID) */
#endif /* WOLFBOOT_ENABLE_WOLFHSM_CLIENT */
/* Make sure sig len matches parameters. */
@ -2267,8 +2250,7 @@ int wolfBoot_verify_authenticity(struct wolfBoot_image *img)
}
key_slot = 0;
#elif defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
defined(WOLFBOOT_USE_WOLFHSM_PUBKEY_ID)
#elif defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT)
/* Don't care about the key slot, we are using a fixed wolfHSM keyId */
key_slot = 0;
#elif defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER) && \