espsecure sign-data --hsm hardcodes P-256 (SECP256R1/SHA-256), breaking ECDSA-P384 HSM signing (ESPTOOL-1389)
Is your feature request related to a problem?
Hi dev team,
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?
Thanks Again
Describe alternatives you've considered
No response
Additional context
No response
Source: espressif/esptool