COSE_Encrypt0
Encrypt COSE_Encrypt0 messages with AES-GCM or ChaCha20-Poly1305.
from secrets import token_bytes
from oxcrypto.cose.encrypt import COSE_ENC
key = token_bytes(32)
message = COSE_ENC.A256GCM.encrypt0(b"secret", key, external_aad=b"ctx")
assert COSE_ENC.A256GCM.decrypt0(message, key, external_aad=b"ctx") == b"secret"| Selector | Value | Key size |
|---|---|---|
A128GCM, A192GCM, A256GCM | 1, 2, 3 | 16, 24, 32 bytes |
CHACHA20_POLY1305 | 24 | 32 bytes |
encrypt0 writes a random 12-byte IV to the unprotected header. Messages
using Partial IV are rejected with ValueError. The AEAD implementations
are the oxcrypto AES-GCM and ChaCha20-Poly1305 ones.
Important
Random 96-bit IVs bound how many messages one key may encrypt; follow the AES-GCM limits in NIST SP 800-38D section 8.3 and rotate keys well before 2^32 messages.