Skip to content

Support nil signer options in KMS and TPM signers - #1151

Open
maraino wants to merge 1 commit into
masterfrom
mariano/signeropts
Open

maraino wants to merge 1 commit into
masterfrom
mariano/signeropts

Conversation

@maraino

@maraino maraino commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

crypto.Signer implementations in the standard library accept nil opts: ecdsa.PrivateKey.Sign picks the hash from the curve and ed25519 signs the raw message. Callers such as PKCS #11 CKM_ECDSA, which don't know which hash produced the digest, depend on this. Several of our signers instead panicked on opts.HashFunc() or rejected the call.

Add cryptoutil.SignerOpts, which turns nil opts into what crypto/ecdsa would use:

  • ECDSA keys get the hash named by the curve (SHA-256, SHA-384 or SHA-512). Shorter digests are left-padded with zeros and longer ones are truncated, so the signature matches the one for the original digest. P-521 fails on digests longer than 64 bytes, and an empty digest fails.
  • RSA keys fail, because the signature depends on the hash.
  • Other keys sign with crypto.Hash(0).

Use it in the awskms, azurekms, cloudkms, yubikey, tpm and tss2 signers. In capi, mackms and pkcs11, return an error instead of panicking when an RSA key gets nil opts; pkcs11 wraps crypto11 RSA signers to do this. x25519 now accepts nil opts as well.

crypto.Signer implementations in the standard library accept nil opts:
ecdsa.PrivateKey.Sign picks the hash from the curve and ed25519 signs
the raw message. Callers such as PKCS #11 CKM_ECDSA, which don't know
which hash produced the digest, depend on this. Several of our signers
instead panicked on opts.HashFunc() or rejected the call.

Add cryptoutil.SignerOpts, which turns nil opts into what crypto/ecdsa
would use:

- ECDSA keys get the hash named by the curve (SHA-256, SHA-384 or
  SHA-512). Shorter digests are left-padded with zeros and longer ones
  are truncated, so the signature matches the one for the original
  digest. P-521 fails on digests longer than 64 bytes, and an empty
  digest fails.
- RSA keys fail, because the signature depends on the hash.
- Other keys sign with crypto.Hash(0).

Use it in the awskms, azurekms, cloudkms, yubikey, tpm and tss2
signers. In capi, mackms and pkcs11, return an error instead of
panicking when an RSA key gets nil opts; pkcs11 wraps crypto11 RSA
signers to do this. x25519 now accepts nil opts as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants