You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
willing to use espsecure with 384 , here is the tips, can you confirm ?
Thanks !
espsecure/esp_hsm_sign/init.py hardcodes ECDSA P-256 in three places :
get_pubkey() always reconstructs the public key as SECP256R1:
public_key = EC.EllipticCurvePublicKey.from_encoded_point(EC.SECP256R1(), ecpoints)
sign_payload() always hashes with SHA-256:
hashed_payload = hashlib.sha256(payload).digest()
sign_payload() always splits the raw signature at a fixed 32-byte
boundary:
r = int(binascii.hexlify(signature[:32]), 16)
s = int(binascii.hexlify(signature[32:]), 16)
Describe the solution you'd like
As Secure Boot V2 already supports ECDSA-P384 for local signing
(--scheme ecdsa384, ec.SECP384R1 handled in sign_secure_boot_v2()), and
several targets (e.g. ESP32-C5) support ECDSA-P384 as a Secure Boot V2
scheme. But signing that same P-384 key through --hsm is broken: a P-384
EC_POINT does not match what from_encoded_point(SECP256R1(), ...) expects
(get_pubkey fails), and even if bypassed, the SHA-256 digest + 32/32 split
would produce a cryptographically wrong signature for a 384-bit curve
(which needs SHA-384 and a 48/48 split), with no clear error message.
Could HSM signing detect the curve from the private/public key object on
the HSM (e.g. via CKA_EC_PARAMS) or manage it , then select the matching hash algorithm
and r/s length accordingly, the same way sign_secure_boot_v2() already
does for local signing?
Hi @g-380! Please be aware that (1) the following suggestions are generated by a bot and haven't been fact-checked by Espressif Systems, (2) burning eFuses and enabling security features are irreversible operations and can damage your ESP32 device. We hope that this message will help you until an Espressif Engineer looks at your issue.
Thanks for the detailed report — I can confirm this based on the current esp_hsm_sign/__init__.py source.
Confirmation of the issue
The customer's analysis is accurate. Looking at the current implementation:
1. get_pubkey() hardcodes SECP256R1 when reconstructing an EC public key from the HSM's EC_POINT attribute:
There is no curve detection (e.g. via CKA_EC_PARAMS) — it always assumes P-256. [esp_hsm_sign]
2. sign_payload() always hashes with SHA-256, regardless of curve:
hashed_payload=hashlib.sha256(payload).digest()
For P-384, Secure Boot V2's local signing path correctly uses SHA-384 (see _sha384_digest), but the HSM path does not branch on curve type at all. [esp_hsm_sign]
3. sign_payload() always splits the raw signature at a fixed 32-byte boundary:
For P-384, r and s are each 48 bytes, so this fixed 32/32 split would produce an incorrect DER signature (or fail/corrupt silently) rather than a working ECDSA-384 signature. [esp_hsm_sign]
4. get_mechanism() also doesn't differentiate by curve for EC keys — it returns a plain Mechanism.ECDSA regardless of key size, so there's no place where curve-specific hash selection is currently threaded through. [esp_hsm_sign]
Contrast with local signing (non-HSM)
The local signing path in sign_secure_boot_v2() (and its helpers generate_signature_block_using_private_key / generate_signature_block_using_pre_calculated_signature) does correctly detect the curve and branch accordingly:
This confirms that Secure Boot V2 does support ECDSA-P384 for local signing (--scheme ecdsa384), matching what's documented in the signature block format for ESP32-C5, which defines a distinct "ECDSA-384 Signature Block" using SHA-384 and 48-byte R/S components. [private_key_sign; signature block format]
So the customer's proposed direction — detecting the curve from the HSM key object (e.g. via CKA_EC_PARAMS) and then selecting the matching hash algorithm and R/S length, the same way sign_secure_boot_v2() already does — aligns with how the rest of the codebase already handles multi-curve support. The knowledge sources do not show that this curve-detection logic has been implemented yet in the HSM signing path, so this does appear to be a genuine gap/feature request rather than something already addressed elsewhere in the code shown here.
Activity
[-]espsecure sign-data --hsm hardcodes P-256 (SECP256R1/SHA-256), breaking ECDSA-P384 HSM signing[/-][+]espsecure sign-data --hsm hardcodes P-256 (SECP256R1/SHA-256), breaking ECDSA-P384 HSM signing (ESPTOOL-1389)[/+]github-actions commentedon Sep 22, 2026
Hi @g-380! Please be aware that (1) the following suggestions are generated by a bot and haven't been fact-checked by Espressif Systems, (2) burning eFuses and enabling security features are irreversible operations and can damage your ESP32 device. We hope that this message will help you until an Espressif Engineer looks at your issue.
Thanks for the detailed report — I can confirm this based on the current
esp_hsm_sign/__init__.pysource.Confirmation of the issue
The customer's analysis is accurate. Looking at the current implementation:
1.
get_pubkey()hardcodes SECP256R1 when reconstructing an EC public key from the HSM'sEC_POINTattribute:There is no curve detection (e.g. via
CKA_EC_PARAMS) — it always assumes P-256. [esp_hsm_sign]2.
sign_payload()always hashes with SHA-256, regardless of curve:For P-384, Secure Boot V2's local signing path correctly uses SHA-384 (see
_sha384_digest), but the HSM path does not branch on curve type at all. [esp_hsm_sign]3.
sign_payload()always splits the raw signature at a fixed 32-byte boundary:For P-384, r and s are each 48 bytes, so this fixed 32/32 split would produce an incorrect DER signature (or fail/corrupt silently) rather than a working ECDSA-384 signature. [esp_hsm_sign]
4.
get_mechanism()also doesn't differentiate by curve for EC keys — it returns a plainMechanism.ECDSAregardless of key size, so there's no place where curve-specific hash selection is currently threaded through. [esp_hsm_sign]Contrast with local signing (non-HSM)
The local signing path in
sign_secure_boot_v2()(and its helpersgenerate_signature_block_using_private_key/generate_signature_block_using_pre_calculated_signature) does correctly detect the curve and branch accordingly:This confirms that Secure Boot V2 does support ECDSA-P384 for local signing (
--scheme ecdsa384), matching what's documented in the signature block format for ESP32-C5, which defines a distinct "ECDSA-384 Signature Block" using SHA-384 and 48-byte R/S components. [private_key_sign; signature block format]So the customer's proposed direction — detecting the curve from the HSM key object (e.g. via
CKA_EC_PARAMS) and then selecting the matching hash algorithm and R/S length, the same waysign_secure_boot_v2()already does — aligns with how the rest of the codebase already handles multi-curve support. The knowledge sources do not show that this curve-detection logic has been implemented yet in the HSM signing path, so this does appear to be a genuine gap/feature request rather than something already addressed elsewhere in the code shown here.Dzarda7 commentedon Sep 30, 2026
Hello @g-380, sorry for the late response, I asked our security guys to take a look at it, will return to you soon.
fix(espsecure): select HSM ECDSA parameters from key curve