From cd59bd275ecc484b1662c86ae9ef0a64eb17d00f Mon Sep 17 00:00:00 2001 From: Jeff Yang Date: Mon, 8 Jul 2019 16:44:11 -0400 Subject: add class methods for poly1305 sign verify operations (#4932) --- tests/hazmat/primitives/test_poly1305.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_poly1305.py b/tests/hazmat/primitives/test_poly1305.py index 71495ff7..edca4623 100644 --- a/tests/hazmat/primitives/test_poly1305.py +++ b/tests/hazmat/primitives/test_poly1305.py @@ -47,6 +47,9 @@ class TestPoly1305(object): poly.update(msg) assert poly.finalize() == tag + assert Poly1305.generate_tag(key, msg) == tag + Poly1305.verify_tag(key, msg, tag) + def test_key_with_no_additional_references(self, backend): poly = Poly1305(os.urandom(32)) assert len(poly.finalize()) == 16 @@ -66,6 +69,9 @@ class TestPoly1305(object): with pytest.raises(TypeError): poly.update(u'') + with pytest.raises(TypeError): + Poly1305.generate_tag(b"0" * 32, u'') + def test_verify(self, backend): poly = Poly1305(b"0" * 32) poly.update(b"msg") @@ -78,6 +84,8 @@ class TestPoly1305(object): poly2.update(b"msg") poly2.verify(tag) + Poly1305.verify_tag(b"0" * 32, b"msg", tag) + def test_invalid_verify(self, backend): poly = Poly1305(b"0" * 32) poly.update(b"msg") @@ -89,22 +97,37 @@ class TestPoly1305(object): 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_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'') + def test_invalid_key_type(self, backend): with pytest.raises(TypeError): Poly1305(object()) + with pytest.raises(TypeError): + Poly1305.generate_tag(object(), b"msg") + def test_invalid_key_length(self, backend): with pytest.raises(ValueError): Poly1305(b"0" * 31) + with pytest.raises(ValueError): + Poly1305.generate_tag(b"0" * 31, b"msg") + with pytest.raises(ValueError): Poly1305(b"0" * 33) + with pytest.raises(ValueError): + Poly1305.generate_tag(b"0" * 33, b"msg") + def test_buffer_protocol(self, backend): key = binascii.unhexlify( b"1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cb" @@ -123,3 +146,7 @@ class TestPoly1305(object): assert poly.finalize() == binascii.unhexlify( b"4541669a7eaaee61e708dc7cbcc5eb62" ) + + assert Poly1305.generate_tag(key, msg) == binascii.unhexlify( + b"4541669a7eaaee61e708dc7cbcc5eb62" + ) -- cgit v1.2.3