aboutsummaryrefslogtreecommitdiffstats
path: root/docs/hazmat/primitives/mac/poly1305.rst
diff options
context:
space:
mode:
authorJeff Yang <jeffjieyang@gmail.com>2019-07-08 16:44:11 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-07-08 15:44:11 -0500
commitcd59bd275ecc484b1662c86ae9ef0a64eb17d00f (patch)
tree0f2bc2ad0f5f7eb2df94038cd2cc6d56c435ce7c /docs/hazmat/primitives/mac/poly1305.rst
parent9a09f9690890c4b6fa6d4d1625e78dcbaffbf734 (diff)
downloadcryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.tar.gz
cryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.tar.bz2
cryptography-cd59bd275ecc484b1662c86ae9ef0a64eb17d00f.zip
add class methods for poly1305 sign verify operations (#4932)
Diffstat (limited to 'docs/hazmat/primitives/mac/poly1305.rst')
-rw-r--r--docs/hazmat/primitives/mac/poly1305.rst45
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/hazmat/primitives/mac/poly1305.rst b/docs/hazmat/primitives/mac/poly1305.rst
index 1d0753c6..7504a076 100644
--- a/docs/hazmat/primitives/mac/poly1305.rst
+++ b/docs/hazmat/primitives/mac/poly1305.rst
@@ -85,3 +85,48 @@ messages allows an attacker to forge tags. Poly1305 is described in
:return bytes: The message authentication code as bytes.
:raises cryptography.exceptions.AlreadyFinalized:
+
+ .. classmethod:: generate_tag(key, data)
+
+ A single step alternative to do sign operations. Returns the message
+ authentication code as ``bytes`` for the given ``key`` and ``data``.
+
+ :param key: Secret key as ``bytes``.
+ :type key: :term:`bytes-like`
+ :param data: The bytes to hash and authenticate.
+ :type data: :term:`bytes-like`
+ :return bytes: The message authentication code as bytes.
+ :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if
+ the version of OpenSSL ``cryptography`` is compiled against does not
+ support this algorithm.
+ :raises TypeError: This exception is raised if ``key`` or ``data`` are
+ not ``bytes``.
+
+ .. doctest::
+
+ >>> poly1305.Poly1305.generate_tag(key, b"message to authenticate")
+ b'T\xae\xff3\xbdW\xef\xd5r\x01\xe2n=\xb7\xd2h'
+
+ .. classmethod:: verify_tag(key, data, tag)
+
+ A single step alternative to do verify operations. Securely compares the
+ MAC to ``tag``, using the given ``key`` and ``data``.
+
+ :param key: Secret key as ``bytes``.
+ :type key: :term:`bytes-like`
+ :param data: The bytes to hash and authenticate.
+ :type data: :term:`bytes-like`
+ :param bytes tag: The bytes to compare against.
+ :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if
+ the version of OpenSSL ``cryptography`` is compiled against does not
+ support this algorithm.
+ :raises TypeError: This exception is raised if ``key``, ``data`` or
+ ``tag`` are not ``bytes``.
+ :raises cryptography.exceptions.InvalidSignature: If tag does not match.
+
+ .. doctest::
+
+ >>> poly1305.Poly1305.verify_tag(key, b"message to authenticate", b"an incorrect tag")
+ Traceback (most recent call last):
+ ...
+ cryptography.exceptions.InvalidSignature: Value did not match computed tag.