diff options
author | Christian Heimes <christian@python.org> | 2018-01-27 08:53:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 08:53:43 (GMT) |
commit | 2f050c7e1b36bf641e7023f7b28b451454c6b98a (patch) | |
tree | 01ee725ca174b0e7f1ba6f160916f891bebb5a38 /Doc | |
parent | a49ac9902903a798fab4970ccf563c531199c3f8 (diff) | |
download | cpython-2f050c7e1b36bf641e7023f7b28b451454c6b98a.zip cpython-2f050c7e1b36bf641e7023f7b28b451454c6b98a.tar.gz cpython-2f050c7e1b36bf641e7023f7b28b451454c6b98a.tar.bz2 |
bpo-32433: Optimized HMAC digest (#5023)
The hmac module now has hmac.digest(), which provides an optimized HMAC
digest for short messages. hmac.digest() is up to three times faster
than hmac.HMAC().digest().
Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/hmac.rst | 15 | ||||
-rw-r--r-- | Doc/whatsnew/3.7.rst | 7 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Doc/library/hmac.rst b/Doc/library/hmac.rst index adbf78a..fcda86c 100644 --- a/Doc/library/hmac.rst +++ b/Doc/library/hmac.rst @@ -31,6 +31,21 @@ This module implements the HMAC algorithm as described by :rfc:`2104`. MD5 as implicit default digest for *digestmod* is deprecated. +.. function:: digest(key, msg, digest) + + Return digest of *msg* for given secret *key* and *digest*. The + function is equivalent to ``HMAC(key, msg, digest).digest()``, but + uses an optimized C or inline implementation, which is faster for messages + that fit into memory. The parameters *key*, *msg*, and *digest* have + the same meaning as in :func:`~hmac.new`. + + CPython implementation detail, the optimized C implementation is only used + when *digest* is a string and name of a digest algorithm, which is + supported by OpenSSL. + + .. versionadded:: 3.7 + + An HMAC object has the following methods: .. method:: HMAC.update(msg) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 43fbd01..133975a 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -492,6 +492,13 @@ and the ``--directory`` to the command line of the module :mod:`~http.server`. With this parameter, the server serves the specified directory, by default it uses the current working directory. (Contributed by Stéphane Wirtel and Julien Palard in :issue:`28707`.) +hmac +---- + +The hmac module now has an optimized one-shot :func:`~hmac.digest` function, +which is up to three times faster than :func:`~hmac.HMAC`. +(Contributed by Christian Heimes in :issue:`32433`.) + importlib --------- |