Skip to content

ECDSA P-384, keys held in a KMS or an HSM, and a FIPS leg - #31

Merged
HackTuah merged 1 commit into
mainfrom
slice/066-signer-kms
Nov 30, 2026
Merged

HackTuah merged 1 commit into
mainfrom
slice/066-signer-kms

Conversation

@HackTuah

@HackTuah HackTuah commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

What

  • BeamMCP.Signer.ECDSAP384 (new): ECDSA P-384 / SHA-384 (FIPS 186-5) behind the unchanged sign/2.
    • Takes a local 48-byte key, or remote: (asked {:digest, sha384}, answering DER).
    • Returns a fixed 96-byte r || s. The DER is read strictly: minimal integers, nothing trailing, and r and s in 1..n-1.
    • Every signature is verified under the public key, and must fail over bytes one bit away, before it is returned.
  • remote: and mu: on MLDSA87, COSE and COSE.HashEnvelope:
    • The host's function is asked {:raw, bytes} (at most 4,096 bytes) or {:external_mu, mu}.
    • μ = SHAKE256(SHAKE256(pk, 64) ‖ 0x00 ‖ 0x00 ‖ M, 64), computed with :crypto.hash_xof/3.
    • Supplying both private_key: and remote: is refused.
    • The hash envelope judges remote: and mu: before it reads the first chunk.
  • BeamMCP.Signer.KMS (new): AWS KMS's wire shapes only.
    • sign_input/2: RAW or EXTERNAL_MU with ML_DSA_SHAKE_256; DIGEST with ECDSA_SHA_384.
    • signature/1 reads a Sign response's signature.
    • public_key/1 accepts exactly the one DER SPKI for each key type, or a GetPublicKey response whose KeySpec and KeyUsage agree.
    • No client and no new dependency: the host's client (aws-elixir, ex_aws_kms, the CLI) sends the request.
  • Fixed: COSE.HashEnvelope refused to sign on every FIPS host. It asked crypto:supports/1, which leaves mldsa87 out in FIPS mode even where the provider serves it. It now asks by trying a verify of zeros, which answers false where ML-DSA-87 works and raises where it does not. The test helper does the same.
  • CI:
  • Docs: the README gains "A key in a KMS or an HSM" and "On a FIPS host". The architecture and assurance-case pages and the CHANGELOG are updated. Two links to private modules that ex_doc 0.40.5 warns on are fixed.

Measured

  • Suite: 138 tests, 0 failures on OTP 28.5.0.8 with OpenSSL 3.5.9. On a runtime without ML-DSA, the refusal tests run and the ML-DSA tests are skipped. Credo --strict is clean, and mix docs gives no warnings.

  • FIPS mode, locally (OTP 28.5.0.9 --enable-fips, x86_64): 138 tests, 0 failures under each provider. The record:

    • 3.5.9: "Ed25519: refused by OTP … ECDSA P-384 / SHA-384: works … ML-DSA-87 (pure, empty context): works".
    • 3.1.2: the same, except "ML-DSA-87: refused (not in this provider)".
  • AWS KMS, live (us-east-1, --only aws_live): each request went out as exactly KMS.sign_input/2's map through the AWS CLI. 3 tests, 0 failures:

    • ML-DSA-87 by RAW and by EXTERNAL_MU (50,000 bytes);
    • a COSE carrier and a 4 MiB hash envelope;
    • ECDSA P-384 by DIGEST.

    The offline tests replay those signatures as fixtures.

  • Mutation testing: 16 mutants, all caught by a failing test. They cover the μ prefix, tr's length, the 4,096 boundary, mu: :always, both keys at once, a remote signature's size, the DER range, minimality and trailing bytes, the digest sent, the hash envelope's early check, the shared key helper, KMS key-usage, algorithm and SPKI strictness, and the FIPS probe.

No public entry of BeamMCP.Signer changes: the callback is still one sign/2. The additions are new modules and options.

BeamMCP.Signer.ECDSAP384 signs ECDSA over P-384 with SHA-384 behind the
same sign/2, from a local key or a remote one, and returns 96 bytes r || s
checked under the public key before it leaves.

MLDSA87, COSE and COSE.HashEnvelope take remote: in place of the seed: the
host's function signs where the key is held, asked for the bytes (at most
4,096) or for FIPS 204's mu, computed here. Every signature is checked as
a local one is; the hash envelope judges remote: before its first chunk.
BeamMCP.Signer.KMS gives AWS KMS's Sign input, its response's signature and
GetPublicKey's key, read strictly. No client, no new dependency.

The hash envelope refused to sign on every FIPS host: it asked
crypto:supports/1, which leaves ML-DSA-87 out in FIPS mode even where the
provider serves it. It now asks by trying a verify, as the test helper does.

CI runs the suite in FIPS mode under OpenSSL FIPS providers 3.5.9 and 3.1.2
on x86_64 and aarch64 and records what each signature does there; Ed25519
is refused by OTP in FIPS mode (erlang/otp#12305). One quality gate job is
green only when every job is.

Signed-off-by: Ayla Croft <aylacroft@proton.me>
@HackTuah
HackTuah merged commit b971bba into main Nov 30, 2026
16 checks passed
@HackTuah
HackTuah deleted the slice/066-signer-kms branch November 30, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant