COSE
CBOR Object Signing and Encryption messages and keys (RFC 9052, RFC 9053).
oxcrypto.cose builds and parses tagged COSE messages with the
coset crate 0.4.2, which handles only
the CBOR structure. Signatures, MACs and AEAD encryption run on the same
oxcrypto primitives as JOSE.
Each operation takes the algorithm as a selector. Decoding requires that:
- the message carries the expected CBOR tag (
COSE_Sign118,COSE_Sign98,COSE_Mac017,COSE_Encrypt016); algis in the protected header and equals the selector; analgin the unprotected header, a missingalgor acritheader raisesValueError, and a differentalgraisesInvalidTag;- the payload or ciphertext is attached; detached content raises
ValueError.
A key of the wrong type for the selector raises TypeError. A failed
signature, MAC or decryption raises InvalidTag, and verify* returns
False instead. Malformed CBOR raises ValueError. Optional kid values
are written to the unprotected header, and external_aad is bound into the
Sig_structure, MAC_structure or Enc_structure.
Formats
- COSE_Sign1 and COSE_Sign with ECDSA, EdDSA and RSA-PSS.
- COSE_Mac0 with HMAC.
- COSE_Encrypt0 with AES-GCM and ChaCha20-Poly1305.
- COSE_Key import and export.
Upstream
| Crate | Standard | Audit |
|---|---|---|
coset 0.4.2 on ciborium | RFC 9052, RFC 9053 (CBOR structures only) | No published audit |
Tests use the cose-wg/Examples messages whose algorithm is in the protected header and whose key is direct, including their failure cases.
Zeroization
COSE adds no long-lived key objects. AEAD and MAC keys are Python bytes
and are not wiped. Decrypted plaintext is held in a wiped buffer until the
returned bytes are created, and private COSE_Key members are encoded from
borrowed buffers. Private COSE_Key parsing wipes the decoded CBOR byte and text values managed
by oxcrypto. Stack copies made by the AES, ChaCha20, HMAC, RSA and curve
crates remain outside that coverage.
Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.