Skip to Content
oxcrypto

COSE_Mac0

Authenticate COSE_Mac0 messages with HMAC.

from secrets import token_bytes

from oxcrypto.cose.mac import COSE_MAC

key = token_bytes(32)
message = COSE_MAC.HMAC_256_256.mac0(b"payload", key)
assert COSE_MAC.HMAC_256_256.decode0(message, key) == b"payload"
SelectorValueAlgorithm
HMAC_256_644HMAC-SHA-256 truncated to 64 bits
HMAC_256_2565HMAC-SHA-256
HMAC_384_3846HMAC-SHA-384
HMAC_512_5127HMAC-SHA-512

The key is bytes. Tags are compared in constant time with subtle. A message tagged under one HMAC selector raises InvalidTag when decoded with another, because the protected alg differs.