COSE_Sign1 and COSE_Sign
Sign and verify COSE_Sign1 and COSE_Sign messages.
from oxcrypto.cose.sign import COSE_SIGN, sign
from oxcrypto.signature.ecdsa import ECDSA
from oxcrypto.signature.ed25519 import ED25519
key = ECDSA.P256.generate()
message = COSE_SIGN.ES256.sign1(b"payload", key, external_aad=b"ctx", kid=b"1")
assert COSE_SIGN.ES256.decode1(message, key.public_key(), external_aad=b"ctx") == b"payload"
other = ED25519.ED25519.generate()
multi = sign(b"payload", [(COSE_SIGN.ES256, key, b"1"), (COSE_SIGN.EDDSA, other, None)])
assert COSE_SIGN.EDDSA.verify(multi, other.public_key())| Selector | Value | Key |
|---|---|---|
ES256, ES384, ES512 | -7, -35, -36 | ECDSAPrivateKey / ECDSAPublicKey on P-256, P-384, P-521 |
EDDSA | -8 | Ed25519PrivateKey / Ed448PrivateKey and their public keys |
PS256, PS384, PS512 | -37, -38, -39 | RSAPrivateKey / RSAPublicKey, at least 2048 bits |
sign1, verify1 and decode1 handle COSE_Sign1. sign(payload, signers) writes one COSE_Signature per (selector, private_key, kid)
entry; verify and decode on a selector succeed when a signature with that
protected alg verifies under the key. Each selector's value is its IANA
COSE algorithm identifier.
ECDSA signatures are the fixed-size r || s encoding (RFC 9053 section 2.1)
and nonces are deterministic (RFC 6979). Ed448 is experimental, see
Ed448.