def test_verify_reject_unicode(self, backend):
        poly = Poly1305(b"0" * 32)
        with pytest.raises(TypeError):
            poly.verify(u"")

        with pytest.raises(TypeError):
            Poly1305.verify_tag(b"0" * 32, b"msg", u"")
Exemplo n.º 2
0
    def test_verify_reject_unicode(self, backend):
        poly = Poly1305(b"0" * 32)
        with pytest.raises(TypeError):
            poly.verify("")  # type:ignore[arg-type]

        with pytest.raises(TypeError):
            Poly1305.verify_tag(b"0" * 32, b"msg", "")  # type:ignore[arg-type]
Exemplo n.º 3
0
    def poly1305_verify(key, data, nonce, tag):
        """Verify a Poly1305 tag for a block of data"""

        try:
            Poly1305.verify_tag(poly1305_key(key, nonce), data, tag)
            return True
        except InvalidSignature:
            return False
    def test_vectors(self, vector, backend):
        key = binascii.unhexlify(vector["key"])
        msg = binascii.unhexlify(vector["msg"])
        tag = binascii.unhexlify(vector["tag"])
        poly = Poly1305(key)
        poly.update(msg)
        assert poly.finalize() == tag

        assert Poly1305.generate_tag(key, msg) == tag
        Poly1305.verify_tag(key, msg, tag)
    def test_invalid_verify(self, backend):
        poly = Poly1305(b"0" * 32)
        poly.update(b"msg")
        with pytest.raises(InvalidSignature):
            poly.verify(b"")

        p2 = Poly1305(b"0" * 32)
        p2.update(b"msg")
        with pytest.raises(InvalidSignature):
            p2.verify(b"\x00" * 16)

        with pytest.raises(InvalidSignature):
            Poly1305.verify_tag(b"0" * 32, b"msg", b"\x00" * 16)
    def test_verify(self, backend):
        poly = Poly1305(b"0" * 32)
        poly.update(b"msg")
        tag = poly.finalize()

        with pytest.raises(AlreadyFinalized):
            poly.verify(b"")

        poly2 = Poly1305(b"0" * 32)
        poly2.update(b"msg")
        poly2.verify(tag)

        Poly1305.verify_tag(b"0" * 32, b"msg", tag)