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"| Selector | Value | Algorithm |
|---|---|---|
HMAC_256_64 | 4 | HMAC-SHA-256 truncated to 64 bits |
HMAC_256_256 | 5 | HMAC-SHA-256 |
HMAC_384_384 | 6 | HMAC-SHA-384 |
HMAC_512_512 | 7 | HMAC-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.