summaryrefslogtreecommitdiff
path: root/Modules/clinic
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2018-01-27 09:53:43 +0100
committerGitHub <noreply@github.com>2018-01-27 09:53:43 +0100
commit2f050c7e1b36bf641e7023f7b28b451454c6b98a (patch)
tree01ee725ca174b0e7f1ba6f160916f891bebb5a38 /Modules/clinic
parenta49ac9902903a798fab4970ccf563c531199c3f8 (diff)
downloadcpython-git-2f050c7e1b36bf641e7023f7b28b451454c6b98a.tar.gz
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 'Modules/clinic')
-rw-r--r--Modules/clinic/_hashopenssl.c.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index f08d7f3afd..cbc8638c94 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -54,7 +54,49 @@ exit:
#endif /* (OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)) */
+PyDoc_STRVAR(_hashlib_hmac_digest__doc__,
+"hmac_digest($module, /, key, msg, digest)\n"
+"--\n"
+"\n"
+"Single-shot HMAC");
+
+#define _HASHLIB_HMAC_DIGEST_METHODDEF \
+ {"hmac_digest", (PyCFunction)_hashlib_hmac_digest, METH_FASTCALL|METH_KEYWORDS, _hashlib_hmac_digest__doc__},
+
+static PyObject *
+_hashlib_hmac_digest_impl(PyObject *module, Py_buffer *key, Py_buffer *msg,
+ const char *digest);
+
+static PyObject *
+_hashlib_hmac_digest(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"key", "msg", "digest", NULL};
+ static _PyArg_Parser _parser = {"y*y*s:hmac_digest", _keywords, 0};
+ Py_buffer key = {NULL, NULL};
+ Py_buffer msg = {NULL, NULL};
+ const char *digest;
+
+ if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
+ &key, &msg, &digest)) {
+ goto exit;
+ }
+ return_value = _hashlib_hmac_digest_impl(module, &key, &msg, digest);
+
+exit:
+ /* Cleanup for key */
+ if (key.obj) {
+ PyBuffer_Release(&key);
+ }
+ /* Cleanup for msg */
+ if (msg.obj) {
+ PyBuffer_Release(&msg);
+ }
+
+ return return_value;
+}
+
#ifndef _HASHLIB_SCRYPT_METHODDEF
#define _HASHLIB_SCRYPT_METHODDEF
#endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
-/*[clinic end generated code: output=1ea7d0397f38e2c2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b5b90821caf05391 input=a9049054013a1b77]*/