summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2021-03-27 13:55:03 (GMT)
committerGitHub <noreply@github.com>2021-03-27 13:55:03 (GMT)
commit933dfd7504e521a27fd8b94d02b79f9ed08f4631 (patch)
treedaf6dda084ba6c854b579350392dfa31c51193db /Modules/clinic
parent5d6e8c1c1a5f667cdce99cb3c563ac922198678d (diff)
downloadcpython-933dfd7504e521a27fd8b94d02b79f9ed08f4631.zip
cpython-933dfd7504e521a27fd8b94d02b79f9ed08f4631.tar.gz
cpython-933dfd7504e521a27fd8b94d02b79f9ed08f4631.tar.bz2
bpo-40645: use C implementation of HMAC (GH-24920)
- [x] fix tests - [ ] add test scenarios for old/new code. Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_hashopenssl.c.h38
1 files changed, 7 insertions, 31 deletions
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index e72b558..fbdff26 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -1081,7 +1081,7 @@ PyDoc_STRVAR(_hashlib_hmac_singleshot__doc__,
static PyObject *
_hashlib_hmac_singleshot_impl(PyObject *module, Py_buffer *key,
- Py_buffer *msg, const char *digest);
+ Py_buffer *msg, PyObject *digest);
static PyObject *
_hashlib_hmac_singleshot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -1092,7 +1092,7 @@ _hashlib_hmac_singleshot(PyObject *module, PyObject *const *args, Py_ssize_t nar
PyObject *argsbuf[3];
Py_buffer key = {NULL, NULL};
Py_buffer msg = {NULL, NULL};
- const char *digest;
+ PyObject *digest;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
if (!args) {
@@ -1112,19 +1112,7 @@ _hashlib_hmac_singleshot(PyObject *module, PyObject *const *args, Py_ssize_t nar
_PyArg_BadArgument("hmac_digest", "argument 'msg'", "contiguous buffer", args[1]);
goto exit;
}
- if (!PyUnicode_Check(args[2])) {
- _PyArg_BadArgument("hmac_digest", "argument 'digest'", "str", args[2]);
- goto exit;
- }
- Py_ssize_t digest_length;
- digest = PyUnicode_AsUTF8AndSize(args[2], &digest_length);
- if (digest == NULL) {
- goto exit;
- }
- if (strlen(digest) != (size_t)digest_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
+ digest = args[2];
return_value = _hashlib_hmac_singleshot_impl(module, &key, &msg, digest);
exit:
@@ -1151,7 +1139,7 @@ PyDoc_STRVAR(_hashlib_hmac_new__doc__,
static PyObject *
_hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
- const char *digestmod);
+ PyObject *digestmod);
static PyObject *
_hashlib_hmac_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -1163,7 +1151,7 @@ _hashlib_hmac_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer key = {NULL, NULL};
PyObject *msg_obj = NULL;
- const char *digestmod = NULL;
+ PyObject *digestmod = NULL;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
if (!args) {
@@ -1185,19 +1173,7 @@ _hashlib_hmac_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
goto skip_optional_pos;
}
}
- if (!PyUnicode_Check(args[2])) {
- _PyArg_BadArgument("hmac_new", "argument 'digestmod'", "str", args[2]);
- goto exit;
- }
- Py_ssize_t digestmod_length;
- digestmod = PyUnicode_AsUTF8AndSize(args[2], &digestmod_length);
- if (digestmod == NULL) {
- goto exit;
- }
- if (strlen(digestmod) != (size_t)digestmod_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
+ digestmod = args[2];
skip_optional_pos:
return_value = _hashlib_hmac_new_impl(module, &key, msg_obj, digestmod);
@@ -1417,4 +1393,4 @@ exit:
#ifndef _HASHLIB_GET_FIPS_MODE_METHODDEF
#define _HASHLIB_GET_FIPS_MODE_METHODDEF
#endif /* !defined(_HASHLIB_GET_FIPS_MODE_METHODDEF) */
-/*[clinic end generated code: output=2bbd6159493f44ea input=a9049054013a1b77]*/
+/*[clinic end generated code: output=980087de1b03ad42 input=a9049054013a1b77]*/