[Python-checkins] (no subject)

Stéphane Wirtel webhook-mailer at python.org
Thu Sep 12 09:03:54 EDT 2019




To: python-checkins at python.org
Subject: bpo-38132: Simplify _hashopenssl code (GH-16023) (#16040)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/67b90a079c39066aa9d51690fe5678c36ccb=
c258
commit: 67b90a079c39066aa9d51690fe5678c36ccbc258
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.co=
m>
committer: St=C3=A9phane Wirtel <stephane at wirtel.be>
date: 2019-09-12T14:03:50+01:00
summary:

bpo-38132: Simplify _hashopenssl code (GH-16023) (#16040)

Signed-off-by: Christian Heimes <christian at python.org>
(cherry picked from commit 5a4f82f457049b5b07b6fba4ca42bc1ecf597976)

Co-authored-by: Christian Heimes <christian at python.org>

files:
A Misc/NEWS.d/next/Library/2019-09-12-12-47-35.bpo-38132.KSFx1F.rst
M Lib/test/test_hashlib.py
M Modules/_hashopenssl.c
M Modules/clinic/_hashopenssl.c.h

diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index f83f73a0cc45..b7b04a37f0d0 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -194,6 +194,9 @@ def test_unknown_hash(self):
         self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam=
')
         self.assertRaises(TypeError, hashlib.new, 1)
=20
+    def test_new_upper_to_lower(self):
+        self.assertEqual(hashlib.new("SHA256").name, "sha256")
+
     def test_get_builtin_constructor(self):
         get_builtin_constructor =3D getattr(hashlib,
                                           '__get_builtin_constructor')
diff --git a/Misc/NEWS.d/next/Library/2019-09-12-12-47-35.bpo-38132.KSFx1F.rs=
t b/Misc/NEWS.d/next/Library/2019-09-12-12-47-35.bpo-38132.KSFx1F.rst
new file mode 100644
index 000000000000..c2e3b6290d9e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-09-12-12-47-35.bpo-38132.KSFx1F.rst
@@ -0,0 +1,3 @@
+The OpenSSL hashlib wrapper uses a simpler implementation. Several Macros
+and pointless caches are gone. The hash name now comes from OpenSSL's EVP.
+The algorithm name stays the same, except it is now always lower case.
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 5e76853b3411..798317fb58b9 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -30,7 +30,6 @@
=20
 typedef struct {
     PyObject_HEAD
-    PyObject            *name;  /* name of this hash algorithm */
     EVP_MD_CTX          *ctx;   /* OpenSSL message digest context */
     PyThread_type_lock   lock;  /* OpenSSL context lock */
 } EVPobject;
@@ -38,18 +37,6 @@ typedef struct {
=20
 static PyTypeObject EVPtype;
=20
-
-#define DEFINE_CONSTS_FOR_NEW(Name)  \
-    static PyObject *CONST_ ## Name ## _name_obj =3D NULL; \
-    static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p =3D NULL;
-
-DEFINE_CONSTS_FOR_NEW(md5)
-DEFINE_CONSTS_FOR_NEW(sha1)
-DEFINE_CONSTS_FOR_NEW(sha224)
-DEFINE_CONSTS_FOR_NEW(sha256)
-DEFINE_CONSTS_FOR_NEW(sha384)
-DEFINE_CONSTS_FOR_NEW(sha512)
-
 #include "clinic/_hashopenssl.c.h"
 /*[clinic input]
 module _hashlib
@@ -90,16 +77,13 @@ _setException(PyObject *exc)
 /* LCOV_EXCL_STOP */
=20
 static EVPobject *
-newEVPobject(PyObject *name)
+newEVPobject(void)
 {
     EVPobject *retval =3D (EVPobject *)PyObject_New(EVPobject, &EVPtype);
     if (retval =3D=3D NULL) {
         return NULL;
     }
=20
-    /* save the name for .name to return */
-    Py_INCREF(name);
-    retval->name =3D name;
     retval->lock =3D NULL;
=20
     retval->ctx =3D EVP_MD_CTX_new();
@@ -139,7 +123,6 @@ EVP_dealloc(EVPobject *self)
     if (self->lock !=3D NULL)
         PyThread_free_lock(self->lock);
     EVP_MD_CTX_free(self->ctx);
-    Py_XDECREF(self->name);
     PyObject_Del(self);
 }
=20
@@ -167,7 +150,7 @@ EVP_copy_impl(EVPobject *self)
 {
     EVPobject *newobj;
=20
-    if ( (newobj =3D newEVPobject(self->name))=3D=3DNULL)
+    if ( (newobj =3D newEVPobject())=3D=3DNULL)
         return NULL;
=20
     if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
@@ -307,10 +290,20 @@ EVP_get_digest_size(EVPobject *self, void *closure)
     return PyLong_FromLong(size);
 }
=20
-static PyMemberDef EVP_members[] =3D {
-    {"name", T_OBJECT, offsetof(EVPobject, name), READONLY, PyDoc_STR("algor=
ithm name.")},
-    {NULL}  /* Sentinel */
-};
+static PyObject *
+EVP_get_name(EVPobject *self, void *closure)
+{
+    const char *name =3D EVP_MD_name(EVP_MD_CTX_md(self->ctx));
+    PyObject *name_obj, *name_lower;
+
+    name_obj =3D PyUnicode_FromString(name);
+    if (!name_obj) {
+        return NULL;
+    }
+    name_lower =3D PyObject_CallMethod(name_obj, "lower", NULL);
+    Py_DECREF(name_obj);
+    return name_lower;
+}
=20
 static PyGetSetDef EVP_getseters[] =3D {
     {"digest_size",
@@ -321,6 +314,10 @@ static PyGetSetDef EVP_getseters[] =3D {
      (getter)EVP_get_block_size, NULL,
      NULL,
      NULL},
+    {"name",
+     (getter)EVP_get_name, NULL,
+     NULL,
+     PyDoc_STR("algorithm name.")},
     {NULL}  /* Sentinel */
 };
=20
@@ -328,7 +325,14 @@ static PyGetSetDef EVP_getseters[] =3D {
 static PyObject *
 EVP_repr(EVPobject *self)
 {
-    return PyUnicode_FromFormat("<%U HASH object @ %p>", self->name, self);
+    PyObject *name_obj, *repr;
+    name_obj =3D EVP_get_name(self, NULL);
+    if (!name_obj) {
+        return NULL;
+    }
+    repr =3D PyUnicode_FromFormat("<%U HASH object @ %p>", name_obj, self);
+    Py_DECREF(name_obj);
+    return repr;
 }
=20
 PyDoc_STRVAR(hashtype_doc,
@@ -379,7 +383,7 @@ static PyTypeObject EVPtype =3D {
     0,                  /*tp_iter*/
     0,                  /*tp_iternext*/
     EVP_methods,        /* tp_methods */
-    EVP_members,        /* tp_members */
+    NULL,        /* tp_members */
     EVP_getseters,      /* tp_getset */
     0,                  /* tp_base */
     0,                  /* tp_dict */
@@ -389,28 +393,23 @@ static PyTypeObject EVPtype =3D {
 };
=20
 static PyObject *
-EVPnew(PyObject *name_obj,
-       const EVP_MD *digest, const EVP_MD_CTX *initial_ctx,
+EVPnew(const EVP_MD *digest,
        const unsigned char *cp, Py_ssize_t len)
 {
     EVPobject *self;
=20
-    if (!digest && !initial_ctx) {
+    if (!digest) {
         PyErr_SetString(PyExc_ValueError, "unsupported hash type");
         return NULL;
     }
=20
-    if ((self =3D newEVPobject(name_obj)) =3D=3D NULL)
+    if ((self =3D newEVPobject()) =3D=3D NULL)
         return NULL;
=20
-    if (initial_ctx) {
-        EVP_MD_CTX_copy(self->ctx, initial_ctx);
-    } else {
-        if (!EVP_DigestInit(self->ctx, digest)) {
-            _setException(PyExc_ValueError);
-            Py_DECREF(self);
-            return NULL;
-        }
+    if (!EVP_DigestInit(self->ctx, digest)) {
+        _setException(PyExc_ValueError);
+        Py_DECREF(self);
+        return NULL;
     }
=20
     if (cp && len) {
@@ -462,13 +461,132 @@ EVP_new_impl(PyObject *module, PyObject *name_obj, PyO=
bject *data_obj)
=20
     digest =3D EVP_get_digestbyname(name);
=20
-    ret_obj =3D EVPnew(name_obj, digest, NULL, (unsigned char*)view.buf, vie=
w.len);
+    ret_obj =3D EVPnew(digest, (unsigned char*)view.buf, view.len);
=20
     if (data_obj)
         PyBuffer_Release(&view);
     return ret_obj;
 }
=20
+static PyObject*
+EVP_fast_new(PyObject *module, PyObject *data_obj, const EVP_MD *digest)
+{
+    Py_buffer view =3D { 0 };
+    PyObject *ret_obj;
+
+    if (data_obj)
+        GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
+
+    ret_obj =3D EVPnew(digest, (unsigned char*)view.buf, view.len);
+
+    if (data_obj)
+        PyBuffer_Release(&view);
+
+    return ret_obj;
+}
+
+/*[clinic input]
+_hashlib.openssl_md5
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a md5 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_md5_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D6caae75b73e22c3f input=3D52010d3869e1=
b1a7]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_md5());
+}
+
+
+/*[clinic input]
+_hashlib.openssl_sha1
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a sha1 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_sha1_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D07606d8f75153e61 input=3D16807d30e4aa=
8ae9]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_sha1());
+}
+
+
+/*[clinic input]
+_hashlib.openssl_sha224
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a sha224 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_sha224_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D55e848761bcef0c9 input=3D5dbc2f1d84eb=
459b]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_sha224());
+}
+
+
+/*[clinic input]
+_hashlib.openssl_sha256
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a sha256 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_sha256_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D05851d7cce34ac65 input=3Da68a5d21cda5=
a80f]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_sha256());
+}
+
+
+/*[clinic input]
+_hashlib.openssl_sha384
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a sha384 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_sha384_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D5101a4704a932c2f input=3D6bdfa006622b=
64ea]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_sha384());
+}
+
+
+/*[clinic input]
+_hashlib.openssl_sha512
+
+    string as data_obj: object(py_default=3D"b''") =3D NULL
+
+Returns a sha512 hash object; optionally initialized with a string
+
+[clinic start generated code]*/
+
+static PyObject *
+_hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj)
+/*[clinic end generated code: output=3D20c8e63ee560a5cb input=3Dece50182ad4b=
76a6]*/
+{
+    return EVP_fast_new(module, data_obj, EVP_sha512());
+}
+
+
 /*[clinic input]
 _hashlib.pbkdf2_hmac as pbkdf2_hmac
=20
@@ -800,76 +918,6 @@ generate_hash_name_list(void)
     return state.set;
 }
=20
-
-/*
- *  This macro generates constructor function definitions for specific
- *  hash algorithms.  These constructors are much faster than calling
- *  the generic one passing it a python string and are noticeably
- *  faster than calling a python new() wrapper.  That is important for
- *  code that wants to make hashes of a bunch of small strings.
- *  The first call will lazy-initialize, which reports an exception
- *  if initialization fails.
- */
-#define GEN_CONSTRUCTOR(NAME)  \
-    static PyObject * \
-    EVP_new_ ## NAME (PyObject *self, PyObject *const *args, Py_ssize_t narg=
s) \
-    { \
-        PyObject *data_obj =3D NULL; \
-        Py_buffer view =3D { 0 }; \
-        PyObject *ret_obj; \
-     \
-        if (!_PyArg_ParseStack(args, nargs, "|O:" #NAME , &data_obj)) { \
-            return NULL; \
-        } \
-     \
-        if (CONST_new_ ## NAME ## _ctx_p =3D=3D NULL) { \
-            EVP_MD_CTX *ctx_p =3D EVP_MD_CTX_new(); \
-            if (!EVP_get_digestbyname(#NAME) || \
-                !EVP_DigestInit(ctx_p, EVP_get_digestbyname(#NAME))) { \
-                _setException(PyExc_ValueError); \
-                EVP_MD_CTX_free(ctx_p); \
-                return NULL; \
-            } \
-            CONST_new_ ## NAME ## _ctx_p =3D ctx_p; \
-        } \
-     \
-        if (data_obj) \
-            GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view); \
-     \
-        ret_obj =3D EVPnew( \
-                    CONST_ ## NAME ## _name_obj, \
-                    NULL, \
-                    CONST_new_ ## NAME ## _ctx_p, \
-                    (unsigned char*)view.buf, \
-                    view.len); \
-     \
-        if (data_obj) \
-            PyBuffer_Release(&view); \
-        return ret_obj; \
-    }
-
-/* a PyMethodDef structure for the constructor */
-#define CONSTRUCTOR_METH_DEF(NAME)  \
-    {"openssl_" #NAME, (PyCFunction)(void(*)(void))EVP_new_ ## NAME, METH_FA=
STCALL, \
-        PyDoc_STR("Returns a " #NAME \
-                  " hash object; optionally initialized with a string") \
-    }
-
-/* used in the init function to setup a constructor: initialize OpenSSL
-   constructor constants if they haven't been initialized already.  */
-#define INIT_CONSTRUCTOR_CONSTANTS(NAME)  do { \
-    if (CONST_ ## NAME ## _name_obj =3D=3D NULL) { \
-        CONST_ ## NAME ## _name_obj =3D PyUnicode_FromString(#NAME); \
-    } \
-} while (0);
-
-GEN_CONSTRUCTOR(md5)
-GEN_CONSTRUCTOR(sha1)
-GEN_CONSTRUCTOR(sha224)
-GEN_CONSTRUCTOR(sha256)
-GEN_CONSTRUCTOR(sha384)
-GEN_CONSTRUCTOR(sha512)
-
 /* List of functions exported by this module */
=20
 static struct PyMethodDef EVP_functions[] =3D {
@@ -877,12 +925,12 @@ static struct PyMethodDef EVP_functions[] =3D {
     PBKDF2_HMAC_METHODDEF
     _HASHLIB_SCRYPT_METHODDEF
     _HASHLIB_HMAC_DIGEST_METHODDEF
-    CONSTRUCTOR_METH_DEF(md5),
-    CONSTRUCTOR_METH_DEF(sha1),
-    CONSTRUCTOR_METH_DEF(sha224),
-    CONSTRUCTOR_METH_DEF(sha256),
-    CONSTRUCTOR_METH_DEF(sha384),
-    CONSTRUCTOR_METH_DEF(sha512),
+    _HASHLIB_OPENSSL_MD5_METHODDEF
+    _HASHLIB_OPENSSL_SHA1_METHODDEF
+    _HASHLIB_OPENSSL_SHA224_METHODDEF
+    _HASHLIB_OPENSSL_SHA256_METHODDEF
+    _HASHLIB_OPENSSL_SHA384_METHODDEF
+    _HASHLIB_OPENSSL_SHA512_METHODDEF
     {NULL,      NULL}            /* Sentinel */
 };
=20
@@ -939,12 +987,5 @@ PyInit__hashlib(void)
     Py_INCREF((PyObject *)&EVPtype);
     PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype);
=20
-    /* these constants are used by the convenience constructors */
-    INIT_CONSTRUCTOR_CONSTANTS(md5);
-    INIT_CONSTRUCTOR_CONSTANTS(sha1);
-    INIT_CONSTRUCTOR_CONSTANTS(sha224);
-    INIT_CONSTRUCTOR_CONSTANTS(sha256);
-    INIT_CONSTRUCTOR_CONSTANTS(sha384);
-    INIT_CONSTRUCTOR_CONSTANTS(sha512);
     return m;
 }
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index 854d92537736..9aaea47e8328 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -109,6 +109,228 @@ EVP_new(PyObject *module, PyObject *const *args, Py_ssi=
ze_t nargs, PyObject *kwn
     return return_value;
 }
=20
+PyDoc_STRVAR(_hashlib_openssl_md5__doc__,
+"openssl_md5($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a md5 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_MD5_METHODDEF    \
+    {"openssl_md5", (PyCFunction)(void(*)(void))_hashlib_openssl_md5, METH_F=
ASTCALL|METH_KEYWORDS, _hashlib_openssl_md5__doc__},
+
+static PyObject *
+_hashlib_openssl_md5_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_md5(PyObject *module, PyObject *const *args, Py_ssize_t nar=
gs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_md5", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_md5_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_hashlib_openssl_sha1__doc__,
+"openssl_sha1($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a sha1 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_SHA1_METHODDEF    \
+    {"openssl_sha1", (PyCFunction)(void(*)(void))_hashlib_openssl_sha1, METH=
_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha1__doc__},
+
+static PyObject *
+_hashlib_openssl_sha1_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_sha1(PyObject *module, PyObject *const *args, Py_ssize_t na=
rgs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_sha1", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_sha1_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_hashlib_openssl_sha224__doc__,
+"openssl_sha224($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a sha224 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_SHA224_METHODDEF    \
+    {"openssl_sha224", (PyCFunction)(void(*)(void))_hashlib_openssl_sha224, =
METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha224__doc__},
+
+static PyObject *
+_hashlib_openssl_sha224_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_sha224(PyObject *module, PyObject *const *args, Py_ssize_t =
nargs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_sha224", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_sha224_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_hashlib_openssl_sha256__doc__,
+"openssl_sha256($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a sha256 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_SHA256_METHODDEF    \
+    {"openssl_sha256", (PyCFunction)(void(*)(void))_hashlib_openssl_sha256, =
METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha256__doc__},
+
+static PyObject *
+_hashlib_openssl_sha256_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_sha256(PyObject *module, PyObject *const *args, Py_ssize_t =
nargs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_sha256", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_sha256_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_hashlib_openssl_sha384__doc__,
+"openssl_sha384($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a sha384 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_SHA384_METHODDEF    \
+    {"openssl_sha384", (PyCFunction)(void(*)(void))_hashlib_openssl_sha384, =
METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha384__doc__},
+
+static PyObject *
+_hashlib_openssl_sha384_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_sha384(PyObject *module, PyObject *const *args, Py_ssize_t =
nargs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_sha384", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_sha384_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_hashlib_openssl_sha512__doc__,
+"openssl_sha512($module, /, string=3Db\'\')\n"
+"--\n"
+"\n"
+"Returns a sha512 hash object; optionally initialized with a string");
+
+#define _HASHLIB_OPENSSL_SHA512_METHODDEF    \
+    {"openssl_sha512", (PyCFunction)(void(*)(void))_hashlib_openssl_sha512, =
METH_FASTCALL|METH_KEYWORDS, _hashlib_openssl_sha512__doc__},
+
+static PyObject *
+_hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj);
+
+static PyObject *
+_hashlib_openssl_sha512(PyObject *module, PyObject *const *args, Py_ssize_t =
nargs, PyObject *kwnames)
+{
+    PyObject *return_value =3D NULL;
+    static const char * const _keywords[] =3D {"string", NULL};
+    static _PyArg_Parser _parser =3D {NULL, _keywords, "openssl_sha512", 0};
+    PyObject *argsbuf[1];
+    Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0=
) - 0;
+    PyObject *data_obj =3D NULL;
+
+    args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, =
1, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    data_obj =3D args[0];
+skip_optional_pos:
+    return_value =3D _hashlib_openssl_sha512_impl(module, data_obj);
+
+exit:
+    return return_value;
+}
+
 PyDoc_STRVAR(pbkdf2_hmac__doc__,
 "pbkdf2_hmac($module, /, hash_name, password, salt, iterations,\n"
 "            dklen=3DNone)\n"
@@ -401,4 +623,4 @@ _hashlib_hmac_digest(PyObject *module, PyObject *const *a=
rgs, Py_ssize_t nargs,
 #ifndef _HASHLIB_SCRYPT_METHODDEF
     #define _HASHLIB_SCRYPT_METHODDEF
 #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
-/*[clinic end generated code: output=3Dcfe686cb2fa042e1 input=3Da9049054013a=
1b77]*/
+/*[clinic end generated code: output=3D38c2637f67e9bb79 input=3Da9049054013a=
1b77]*/



More information about the Python-checkins mailing list