Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    def verify_tag(self,
                   key: SymmetricKey,
                   alg: Optional[CoseAlgorithms] = None) -> bool:
        """ Verifies the authentication tag of a received message. """

        if not isinstance(key, SymmetricKey):
            raise CoseIllegalKeyType(
                "COSE key should be of type 'SymmetricKey', got {}".format(
                    type(key)))

        return key.verify_tag(self.auth_tag, self._mac_structure, alg)