def test_symmetric_mac(kid, alg, key_ops, base_iv, k, pl, algo, ct): key = SymmetricKey(kid=kid, alg=alg, key_ops=key_ops, base_iv=base_iv, k=k) assert ct == key.compute_tag(pl, algo) # switch to another key operation key.key_ops = KeyOps.MAC_VERIFY assert key.verify_tag(ct, pl, algo)
def compute_tag(self, key: SymmetricKey, alg: Optional[CoseAlgorithms] = None) -> bytes: """ Computes the authentication tag of a COSE_Mac or COSE_Mac0 message. """ if not isinstance(key, SymmetricKey): raise CoseIllegalKeyType( "COSE key should be of type 'SymmetricKey', got {}".format( type(key))) self.auth_tag = key.compute_tag(self._mac_structure, alg) return self.auth_tag