Signers for beam_mcp's canonical connectome
bytes, through OTP's :crypto. Four modules, each implementing core's BeamMCP.Signer
behaviour (sign/2) and nothing else, a fifth for artifacts too large to hold whole, the wire
shapes for a key held in AWS KMS, and a verifier for all of it:
BeamMCP.Signer.ECDSAP384: ECDSA over P-384 with SHA-384 (FIPS 186-5), a 96-byter || ssignature: the FIPS-approved signature on a FIPS host, from a local key or a key in a KMS or an HSM.BeamMCP.Signer.MLDSA87: ML-DSA-87 (FIPS 204), the post-quantum signature CNSA 2.0 names, a 4,627-byte signature. It needs an OTP whose:cryptois linked to OpenSSL 3.5 or later; see ML-DSA-87 below.BeamMCP.Signer.COSE: the same ML-DSA-87 signature inside COSE (RFC 9964, algorithm -50), with the algorithm and the key's thumbprint in the signed bytes; see COSE below.BeamMCP.Signer.COSE.HashEnvelope(non-claimed): a file of any size, streamed and signed by its SHA-512 as an RFC 9995 COSE Hash Envelope under the same ML-DSA-87. It is not aBeamMCP.Signer; see Hash envelope below.BeamMCP.Signer.KMS: AWS KMS's request and response shapes for a key held there, and no client; see A key in a KMS or an HSM below.BeamMCP.Signer.Verify: checks raw signatures under a policy that names every algorithm that must verify, and checks both carriers against the bytes they name; see Verifying below.BeamMCP.Signer.Ed25519: Ed25519 (RFC 8032), a 64-byte signature. Kept for hosts that already sign with it, and not recommended for new use; see Ed25519. Not available in FIPS mode; see On a FIPS host.
For new use: ML-DSA-87, and ECDSA P-384 where a classical signature is still needed. The CNSA 2.0 algorithm suite lists ML-DSA-87 for signatures, and ECDSA P-384 from CNSA 1.0 for the transition; it lists no EdDSA. A host that wants both a post-quantum and a classical signature signs with both and verifies under a policy that requires both (Verifying).
What the signers sign. Exactly the bytes BeamMCP.Connectome.Canonical.encode/2 produces, as
Canonical.signature/3 hands them over; the signature comes back beside them. Nothing else:
no envelope byte moves, no verdict or receipt is added.
BeamMCP.Signer.MLDSA87 signs pure ML-DSA-87 through the external interface with an empty
context: the form RFC 9964 requires for COSE (algorithm -50). The host hands in two keys,
each as bytes or, better, as a zero-arity function returning them (why: Ed25519, "Why a function", which holds for every signer here):
{:ok, %{signature: sig}} =
BeamMCP.Connectome.Canonical.signature(graph, BeamMCP.Signer.MLDSA87,
private_key: fn -> seed end, public_key: fn -> public_key end, scheme: :mldsa87)
true = :crypto.verify(:mldsa87, :none, BeamMCP.Connectome.Canonical.encode!(graph), sig, public_key):private_keyis the 32-byte seed, RFC 9964's one private-key form.:public_keyis the 2,592-byte public key that seed derives. It is required because:cryptosigns from a seed but cannot derive the public key from one. The host provisions the pair outside the VM and hands in both.- Every signature is checked before it is returned. It must verify under the public key
given, or the answer is
{:error, {:public_key, :does_not_verify}}and no signature leaves the module: that is how a seed and a public key that are not a pair are caught. The same signature over bytes one bit away must not verify, or the answer is{:error, :self_check_failed}. - Signing is hedged. OpenSSL draws fresh randomness for each signature, and
:cryptocannot select the deterministic variant: two signatures of the same bytes differ, and both verify. - Where it runs. OTP 28.1 or later, with
:cryptolinked to OpenSSL 3.5 or later (:mldsa87 in :crypto.supports(:public_keys)). OTP 28.0, or an OTP linked to an older OpenSSL, answers every call{:error, :crypto_refused}. CI runs the ML-DSA tests on the box leg (OTP 28.5.0.9 on Ubuntu 26.04's arm64 runner, OpenSSL 3.5.5) and fails that leg if:cryptodoes not offer the algorithm. - FIPS mode with a provider that approves ML-DSA needs
default_properties = fips=yesin OpenSSL's own configuration; OTP'sfips_modealone leaves the signature unavailable. No provider in this package's CI approves ML-DSA, so FIPS mode is not tested here. - Vectors. The suite holds the runtime to NIST's ACVP and C2SP's Wycheproof ML-DSA-87
vectors, every case
:cryptocan express (it passes no context and has no HashML-DSA or internal interface); the rest are counted by reason, so one that comes into reach fails the count until it runs. - Other implementations. On every CI run, the box leg's ML-DSA-87 signature is verified by
Go's
crypto/mldsaand by AWS-LC (aws-lc-rs), neither of them OpenSSL; each must refuse it over the message with one bit flipped, and Go also confirms the public key is the one the seed derives (tools/cross_verify/).
BeamMCP.Signer.COSE fixes what a raw signature cannot: Canonical.signature/3 places
scheme: and key_id: beside the signature, asserted by the host and verified by nobody, so
swapping either leaves a raw signature valid. Here the algorithm and the key's thumbprint sit
in the COSE protected header, inside the signed bytes.
{:ok, %{signature: carrier}} =
BeamMCP.Connectome.Canonical.signature(graph, BeamMCP.Signer.COSE,
private_key: fn -> seed end, public_key: fn -> public_key end, issuer: "box-17")The keys are BeamMCP.Signer.MLDSA87's, read the same way, and that module makes and checks
the signature. :issuer is required, and is N6's issuer: text of 1 to 255 bytes, each a printable ASCII character other than the space (0x21 to 0x7E), or {:bytes, binary} of 1 to 64 bytes. The verifier refuses the same (:text_grammar_mismatch, and :value_out_of_range for bytes), so two text issuers that differ never print alike and none drives a terminal. An issuer is an identifier: a name for people, in any script or with spaces, belongs in the host's own records, outside the signed statement. A byte-string issuer has no grammar but its length: it comes back tagged {:bytes, binary}, it may hold a line feed or an escape, and it is printed as hex (Base.encode16/1), never as the text it may spell. Until 1.1.0 the issuer was any one line of Unicode text and bytes up to 65,536; the statement profile is provisional on both sides that share it, and this rule is the one both now hold.
What comes back is one binary, deterministic CBOR, in the form Script Kitty's systems share for everything they sign (the N6 profile, v0.1, a draft; provisional until its v1):
{0: 0xFFFF0003, ; the single-signer carrier
1: h'<body>',
2: [h'<protected>', {}, null, h'<signature>']} ; COSE_Sign1, untagged, detached
protected = {1: -50, ; alg: ML-DSA-87
4: h'<48 bytes>', ; kid: SHA-384 COSE Key Thumbprint
16: "application/vnd.example.b85.connectome.v0+cose"} ; typ
body = {0: 0x85000101, ; the statement's schema
1: "<issuer>",
2: {0: [-43, h'<SHA-384 of the canonical bytes>'], 1: <their length>,
2: "application/json"}}
To verify, BeamMCP.Signer.Verify.cose/3 does all of this (see Verifying). By
hand, with the canonical bytes beside the carrier and the public key from your own key registry:
- Decode the carrier, the protected header and the body, refusing anything that is not deterministic CBOR.
- Require the protected header to be exactly
{1: -50, 4: kid, 16: typ}, withkidthe SHA-384 ofa3 01 07 03 38 31 20 59 0a 20followed by the 2,592-byte public key (RFC 9679 over the AKP key). - Verify the signature, pure ML-DSA-87 with an empty context, over
["Signature1", protected, h'', body](RFC 9052 section 4.4), the protected bytes as received. - Require the body's digest and length to be the canonical bytes'.
tools/cross_verify/ does exactly this in Go (fxamacker/cbor and crypto/mldsa) and in Rust
(coset, ciborium and aws-lc-rs), and CI runs both on the box leg's carrier on every change.
The schema number and typ are provisional and change when the shared registry assigns them.
The encoder is this package's own: no Elixir library writes deterministic CBOR or COSE with
ML-DSA. It is held to RFC 8949 Appendix A and to RFC 9964 Appendix A.2, byte for byte. Text
follows the profile's text rule against Unicode 15.0.0 tables embedded in the package
(tools/unicode_tables.sh fetches the data and pins it by sha256), never the runtime's own
Unicode; the suite checks every code point against the data files with a parser of its own.
One key per scheme. Keep a COSE key for BeamMCP.Signer.COSE and the hash envelope, and do
not hand it to BeamMCP.Signer.MLDSA87 for anything but core's canonical bytes.
MLDSA87.sign/2 signs any binary it is given, and a COSE ToBeSigned is a binary. Core's
canonical bytes begin with {, and every ToBeSigned begins 84 6a "Signature1", so a raw
signature over the connectome is never a COSE one. Other bytes could be.
BeamMCP.Signer.COSE.HashEnvelope signs an artifact by its digest, so a 10 GB clip, tile
bundle or model file never has to be in memory whole. The host streams it in, and memory stays
one chunk and a hash state:
{:ok, envelope} =
BeamMCP.Signer.COSE.HashEnvelope.sign_stream(chunks, # say, a file read 1 MiB at a time
private_key: fn -> seed end, public_key: fn -> public_key end,
typ: "application/vnd.example.b80.test_hash.v0+cose", preimage_type: "video/mp4")sign_digest/2 takes a digest the host already has. It checks only the length, so the carrier
says that the key holder asserts that digest. What comes back is the same carrier as
COSE's, with the digest as its payload:
{0: 0xFFFF0003, 1: h'<SHA-512 of the artifact>', 2: [h'<protected>', {}, null, h'<signature>']}
protected = {1: -50, 2: [258], 4: h'<kid>', 16: "<typ>",
258: -44, ; payload-hash-alg: SHA-512
259: "video/mp4", ; preimage-content-type
260: "<location>"} ; optional hint, never trusted
- What it fixes. A raw signature over a digest leaves the hash algorithm unsigned and the digest indistinguishable from content. Here both the hash algorithm and the preimage's type are in the protected header.
- How a verifier reads it.
critlists 258, so a COSE verifier that does not know hash envelopes refuses the signature. One that does needs only the envelope and the public key. It rebuilds["Signature1", protected, h'', digest]and verifies. When it holds the artifact, it also checks the digest.BeamMCP.Signer.Verify.hash_envelope/3does both, and will not verify without the artifact or its digest. - The
typis the host's and required. It is a lowercase media type ending+cosethat names the kind of statement; the connectome'stypis refused. The preimage type is per artifact. - SHA-512 by default (258 = -44). FIPS 204 section 5.4 asks that a digest signed in place
of a message have at least the signature's collision strength, 256 bits for ML-DSA-87.
SHA-512 has 256; SHA-384 has 192.
payload_hash: :sha384(-43) remains for a host that must match a digest it already publishes; the envelope is then a 192-bit construction. - Non-claimed. The signature is pure ML-DSA-87, not HashML-DSA, but no NSA, NIST or IETF
text yet names this construction. A verified envelope is judged non-claimed, and
BeamMCP.Signer.COSEstays the claimed path. - Tested. CI's box leg signs a 10 GiB file, holds the VM's memory growth under 64 MiB and
compares the digest with
sha512sum's. The Go and Rust verifiers read each run's envelope.cosetrefuses it overcrit(it predates RFC 9995), and the Rust check confirms that refusal before verifying with coset's ToBeSigned.
MLDSA87, COSE, COSE.HashEnvelope and ECDSAP384 take remote: in place of
:private_key: a one-argument function, the host's, that asks the service holding the key to
sign. This package never sees the key and holds no credential, HTTP client or SDK. The function
is called with one of:
{:raw, bytes}: ML-DSA-87 over the bytes (1 to 4,096, AWS KMS's limits for a raw message);{:external_mu, mu}: ML-DSA-87 over the 64-byte μ of FIPS 204, computed here, so the message never leaves the host.mu: :auto(the default) sends:rawfor 1 to 4,096 bytes and μ otherwise;mu: :alwayssends μ every time, andmu: :neverthe bytes every time, for a service without KMS's limit;{:digest, sha384}: ECDSA P-384 over the SHA-384 computed here; the answer is DER.
:public_key is still required (an ECDSA point off the curve is refused before the service
is asked), and every signature is checked under it before it is returned, so a service that
signs with another key, or another way, is caught on its first call. When the function answers
{:error, reason}, the signer answers {:error, {:remote, {:error, reason}}} with the reason
as it came: it is the host's, and this package neither reads nor cleans it.
BeamMCP.Signer.KMS turns each request into AWS KMS's Sign input and reads the response and
GetPublicKey's key, strictly; the host's own client sends it:
remote = fn request ->
with {:ok, body, _} <- AWS.KMS.sign(client, BeamMCP.Signer.KMS.sign_input(key_id, request)),
do: BeamMCP.Signer.KMS.signature(body)
endMeasured against AWS KMS on 2026-11-29: ML_DSA_87 keys sign pure ML-DSA-87 with the empty
context in both RAW and EXTERNAL_MU (both verify under :crypto in FIPS mode), and
ECC_NIST_P384 keys sign ECDSA_SHA_384 over a DIGEST. Where KMS offers ML-DSA, and which
certificate covers it, is AWS's to state: KMS's HSM certificate (CMVP #4884) lists ECDSA, not
ML-DSA, today.
Rotation. AWS KMS rotates only symmetric keys automatically. An asymmetric key, ML-DSA-87 or P-384, is rotated by making a new key: a new public key and so a new kid. Point the alias at it, publish the new public key, and keep the old one in verifiers' registries for as long as signatures made under it must verify.
BeamMCP.Signer.Verify checks what the signers make. It answers whether a signature verifies
under the key it is given; whether that key is the right party's is your key registry's
question.
Raw signatures, under a policy. A host that signs the same bytes with ML-DSA-87 and with
ECDSA P-384 has readers who rely on different ones. A verifier that accepts whichever one
verifies serves none of them: strip the signature one reader relies on and the other still
passes. So signatures/3 takes :require, every scheme that must verify, and checks exactly
those. There is no any-of.
{:ok, %{verified: [:mldsa87, :ecdsa_p384_sha384], unchecked: []}} =
BeamMCP.Signer.Verify.signatures(canonical_bytes,
%{mldsa87: ml_dsa_signature, ecdsa_p384_sha384: p384_signature},
require: [:mldsa87, :ecdsa_p384_sha384],
keys: %{mldsa87: ml_dsa_public_key, ecdsa_p384_sha384: p384_public_key})require: [:mldsa87] accepts the post-quantum signature alone; require: [:ecdsa_p384_sha384]
the P-384 signature alone; both, both. A signature the policy does not name is not judged and is
listed as unchecked. The scheme names are core's (Canonical.scheme()). Ed25519 cannot be
required: OTP refuses it in FIPS mode, and NIST IR 8547 deprecates it after 2030. A refusal
names the first required scheme that failed and why, for example
{:error, {:ecdsa_p384_sha384, :no_signature}}.
The carriers. cose/3 checks a statement against the canonical bytes, and
hash_envelope/3 checks an envelope against the artifact (streamed, or its digest) and the
statement kinds you accept (typ:). Each judges the carrier in the N6 profile's order (strict
decode, carrier, protected header, kid, signature, then the body and the named bytes) and names
a refusal by the profile's code (:kid_not_thumbprint, :signature_invalid, ...). Canonical
bytes that are not the ones a statement names come back as the profile's attachment finding,
{:attachment, "2", :foreign_digest_mismatch}; an artifact that is not the one an envelope
names, as :preimage_digest_mismatch. A statement verifies as :claim, an envelope as
:verified_nonclaimed. The strict decoder is held to the profile's decoding steps and to the
shared vector set's encoding cases.
Not recommended for new use. BeamMCP.Signer.Ed25519 was this package's first signer and
stays for hosts that already sign with it: nothing about it changes in 1.x, and it is not
removed before 2.0. A new host signs with ML-DSA-87, or with ECDSA P-384
(BeamMCP.Signer.ECDSAP384) where a classical signature is still needed; the CNSA 2.0
algorithm suite lists no EdDSA.
Who holds the key. The host. It passes the 32-byte Ed25519 private key on every call, as a zero-arity function that returns it:
{public_key, private_key} = :crypto.generate_key(:eddsa, :ed25519) # or a key the host keeps
{:ok, %{signature: sig}} =
BeamMCP.Connectome.Canonical.signature(graph, BeamMCP.Signer.Ed25519,
private_key: fn -> private_key end)
true = :crypto.verify(:eddsa, :none, BeamMCP.Connectome.Canonical.encode!(graph), sig, [public_key, :ed25519])Why a function. Options pass through the host's code and core's, and whatever prints
them (an exception raised on a mistyped call, a debug log line, a crash report) prints a key
passed as bytes, byte by byte. A function prints as #Function<...>. The 32 bytes themselves
are still accepted; the function is the form that nothing printed can reveal. For the same
reason nothing this module meets is raised: a mistyped call is answered
{:error, :bad_arguments} (so is an improper list whose end comes before a :private_key
entry), a key function that raises, throws or exits is answered
{:error, {:private_key, :unreadable}}, and a refusal from :crypto is answered
{:error, :crypto_refused}. The key function's own exception is dropped with it, so a host
that wants it logged logs it inside that function, without the key.
CI runs the suite in FIPS mode (OTP 28.5.0.9 built --enable-fips, OpenSSL 3.5.9) under two
validated OpenSSL FIPS providers, on x86_64 and aarch64, and records what each signature does:
| provider 3.5.9 (CMVP #5586) | provider 3.1.2 (CMVP #4985) | |
|---|---|---|
ECDSA P-384 (ECDSAP384) |
works | works |
ML-DSA-87 (MLDSA87, COSE, HashEnvelope) |
works | refused (not in the module) |
Ed25519 (Ed25519) |
refused by OTP | refused by OTP |
OTP's crypto refuses EdDSA in FIPS mode by its own rule, signing and verifying alike, even
where the provider approves it (#5586 does, under FIPS 186-5): reported as
erlang/otp#12305. Ed25519.sign/2 answers
{:error, :crypto_refused} there. So on a FIPS host the FIPS-approved signature is
ECDSAP384, with MLDSA87 beside it as the post-quantum one: two independent signatures,
never one composite. In FIPS mode crypto:supports/1 also leaves ML-DSA-87 out where it
works; this package asks by trying instead.
Validation belongs to the module and the operational environments its certificate names; the host's FIPS posture is its own build of OTP and OpenSSL on its own platform. The FIPS 140-3 CMVP Management Manual (section 7.9.2) lets a user run a validated Level 1 software module, built unmodified as its security policy describes, on another general-purpose platform with the listed or a compatible operating system, and affirm it; the CMVP makes no statement about such a port. Whether that affirmation meets a given policy is the host's question.
This package reads the key options, for COSE the issuer, for the hash envelope its own
options listed above, and for the verifier its arguments, and nothing else (opts[:private_key] or opts[:remote] and opts[:mu],
for ML-DSA-87 and ECDSA P-384 opts[:public_key], for COSE opts[:issuer]). There is no environment variable, no file and no application config.
No key, issuer or typ has a default.
Where the keys live between calls is the host's decision.
Core is a separate package. beam_mcp holds no key and calls no signing primitive; it is
not a dependency of this package in the other direction, and it never will be. A host that
wants signatures adds this package and attaches the module; one that does not, does not.
Apache-2.0. Erlang/OTP 28 or newer, Elixir 1.18.4 or newer -- the same floor as core, from
1.1.0 (ML-DSA-87 as above). A host on OTP 27 can stay on ~> 1.0.2, which receives no further
fixes.
The project. Reference documentation is on HexDocs.
What a host can rely on, and how to report a vulnerability: SECURITY.md. Why
the security requirements hold: docs/assurance-case.md, with the
design in docs/architecture.md. Checking a release's signature:
docs/verifying-releases.md. Contributing:
CONTRIBUTING.md, under the Code of Conduct. Who
decides, and what comes next: GOVERNANCE.md,
docs/roadmap.md. Bugs and ideas: issues.