https://github.com/python/cpython/commit/cb8045e86c4fadfd847d614193f2b38ec03933b8
commit: cb8045e86c4fadfd847d614193f2b38ec03933b8
branch: main
author: Bénédikt Tran <10796600+picn...@users.noreply.github.com>
committer: picnixz <10796600+picn...@users.noreply.github.com>
date: 2025-05-26T10:12:32Z
summary:

gh-134531: cleanup `_hashopenssl.c` to support `EVP_MAC` (#134626)

Rename components related to `_hashlib.{HASH,HASHXOF}` objects.

- The `EVPobject` structure is renamed `HASHobject`.
- Non-clinic `HASH` methods are now prefixed by `_hashlib_HASH_*`.
  A similar change is made for non-clinic `HASHXOF` methods.
- Functions extracting information from `EVP_MD` objects and functions
  constructing `EVP_MD` objects now include `openssl_evp_md` in their name.

This change allows us to avoid future ambiguities between the `EVP_MD`
and the `EVP_MAC` APIs (currently, we only use `EVP_MD` for hash functions
and rely on the legacy interface for HMAC instead of using `EVP_MAC`).

files:
A Misc/NEWS.d/next/Library/2025-05-26-11-01-54.gh-issue-134531.my1Fzt.rst
M Modules/_hashopenssl.c
M Modules/clinic/_hashopenssl.c.h

diff --git 
a/Misc/NEWS.d/next/Library/2025-05-26-11-01-54.gh-issue-134531.my1Fzt.rst 
b/Misc/NEWS.d/next/Library/2025-05-26-11-01-54.gh-issue-134531.my1Fzt.rst
new file mode 100644
index 00000000000000..ee5690df5c4193
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-26-11-01-54.gh-issue-134531.my1Fzt.rst
@@ -0,0 +1,2 @@
+:mod:`!_hashlib`: Rename internal C functions for :class:`!_hashlib.HASH`
+and :class:`!_hashlib.HASHXOF` objects. Patch by Bénédikt Tran.
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 48eed5eac975ed..dab0bb9b67fa00 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -38,6 +38,10 @@
 
 #include <stdbool.h>
 
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#  define Py_HAS_OPENSSL3_SUPPORT
+#endif
+
 #ifndef OPENSSL_THREADS
 #  error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
 #endif
@@ -55,7 +59,7 @@
 #define PY_OPENSSL_HAS_BLAKE2 1
 #endif
 
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#ifdef Py_HAS_OPENSSL3_SUPPORT
 #define PY_EVP_MD EVP_MD
 #define PY_EVP_MD_fetch(algorithm, properties) EVP_MD_fetch(NULL, algorithm, 
properties)
 #define PY_EVP_MD_up_ref(md) EVP_MD_up_ref(md)
@@ -77,12 +81,12 @@
  * py_alias as keys.
  */
 
-enum Py_hash_type {
-    Py_ht_evp,            // usedforsecurity=True / default
-    Py_ht_evp_nosecurity, // usedforsecurity=False
-    Py_ht_mac,            // HMAC
-    Py_ht_pbkdf2,         // PKBDF2
-};
+typedef enum Py_hash_type {
+    Py_ht_evp,              // usedforsecurity=True / default
+    Py_ht_evp_nosecurity,   // usedforsecurity=False
+    Py_ht_mac,              // HMAC
+    Py_ht_pbkdf2,           // PKBDF2
+} Py_hash_type;
 
 typedef struct {
     const char *py_name;
@@ -255,10 +259,10 @@ py_hashentry_table_new(void) {
 static PyModuleDef _hashlibmodule;
 
 typedef struct {
-    PyTypeObject *EVPtype;
+    PyTypeObject *HASH_type;    // based on EVP_MD
     PyTypeObject *HMACtype;
 #ifdef PY_OPENSSL_HAS_SHAKE
-    PyTypeObject *EVPXOFtype;
+    PyTypeObject *HASHXOF_type; // based on EVP_MD
 #endif
     PyObject *constructs;
     PyObject *unsupported_digestmod_error;
@@ -275,13 +279,13 @@ get_hashlib_state(PyObject *module)
 
 typedef struct {
     PyObject_HEAD
-    EVP_MD_CTX          *ctx;   /* OpenSSL message digest context */
+    EVP_MD_CTX *ctx;    /* OpenSSL message digest context */
     // Prevents undefined behavior via multiple threads entering the C API.
     bool use_mutex;
-    PyMutex mutex;  /* OpenSSL context lock */
-} EVPobject;
+    PyMutex mutex;      /* OpenSSL context lock */
+} HASHobject;
 
-#define EVPobject_CAST(op)  ((EVPobject *)(op))
+#define HASHobject_CAST(op) ((HASHobject *)(op))
 
 typedef struct {
     PyObject_HEAD
@@ -296,11 +300,11 @@ typedef struct {
 #include "clinic/_hashopenssl.c.h"
 /*[clinic input]
 module _hashlib
-class _hashlib.HASH "EVPobject *" "((_hashlibstate 
*)PyModule_GetState(module))->EVPtype"
-class _hashlib.HASHXOF "EVPobject *" "((_hashlibstate 
*)PyModule_GetState(module))->EVPXOFtype"
+class _hashlib.HASH "HASHobject *" "((_hashlibstate 
*)PyModule_GetState(module))->EVPtype"
+class _hashlib.HASHXOF "HASHobject *" "((_hashlibstate 
*)PyModule_GetState(module))->EVPXOFtype"
 class _hashlib.HMAC "HMACobject *" "((_hashlibstate 
*)PyModule_GetState(module))->HMACtype"
 [clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7df1bcf6f75cb8ef]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4f6b8873ed13d1ff]*/
 
 
 /* LCOV_EXCL_START */
@@ -364,8 +368,8 @@ notify_ssl_error_occurred(void)
 }
 /* LCOV_EXCL_STOP */
 
-static PyObject*
-py_digest_name(const EVP_MD *md)
+static const char *
+get_openssl_evp_md_utf8name(const EVP_MD *md)
 {
     assert(md != NULL);
     int nid = EVP_MD_nid(md);
@@ -388,13 +392,20 @@ py_digest_name(const EVP_MD *md)
         if (name == NULL)
             name = OBJ_nid2sn(nid);
     }
+    return name;
+}
 
+static PyObject *
+get_openssl_evp_md_name(const EVP_MD *md)
+{
+    const char *name = get_openssl_evp_md_utf8name(md);
     return PyUnicode_FromString(name);
 }
 
 /* Get EVP_MD by HID and purpose */
-static PY_EVP_MD*
-py_digest_by_name(PyObject *module, const char *name, enum Py_hash_type py_ht)
+static PY_EVP_MD *
+get_openssl_evp_md_by_utf8name(PyObject *module, const char *name,
+                               Py_hash_type py_ht)
 {
     PY_EVP_MD *digest = NULL;
     PY_EVP_MD *other_digest = NULL;
@@ -460,15 +471,17 @@ py_digest_by_name(PyObject *module, const char *name, 
enum Py_hash_type py_ht)
     return digest;
 }
 
-/* Get digest EVP from object
+/* Get digest EVP_MD from object
  *
  * * string
  * * _hashopenssl builtin function
  *
  * on error returns NULL with exception set.
  */
-static PY_EVP_MD*
-py_digest_by_digestmod(PyObject *module, PyObject *digestmod, enum 
Py_hash_type py_ht) {
+static PY_EVP_MD *
+get_openssl_evp_md(PyObject *module, PyObject *digestmod,
+                   Py_hash_type py_ht)
+{
     PyObject *name_obj = NULL;
     const char *name;
 
@@ -494,13 +507,13 @@ py_digest_by_digestmod(PyObject *module, PyObject 
*digestmod, enum Py_hash_type
         return NULL;
     }
 
-    return py_digest_by_name(module, name, py_ht);
+    return get_openssl_evp_md_by_utf8name(module, name, py_ht);
 }
 
-static EVPobject *
-newEVPobject(PyTypeObject *type)
+static HASHobject *
+new_hash_object(PyTypeObject *type)
 {
-    EVPobject *retval = PyObject_New(EVPobject, type);
+    HASHobject *retval = PyObject_New(HASHobject, type);
     if (retval == NULL) {
         return NULL;
     }
@@ -517,7 +530,7 @@ newEVPobject(PyTypeObject *type)
 }
 
 static int
-EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
+_hashlib_HASH_hash(HASHobject *self, const void *vp, Py_ssize_t len)
 {
     unsigned int process;
     const unsigned char *cp = (const unsigned char *)vp;
@@ -539,9 +552,9 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
 /* Internal methods for a hash object */
 
 static void
-EVP_dealloc(PyObject *op)
+_hashlib_HASH_dealloc(PyObject *op)
 {
-    EVPobject *self = EVPobject_CAST(op);
+    HASHobject *self = HASHobject_CAST(op);
     PyTypeObject *tp = Py_TYPE(self);
     EVP_MD_CTX_free(self->ctx);
     PyObject_Free(self);
@@ -549,7 +562,7 @@ EVP_dealloc(PyObject *op)
 }
 
 static int
-locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject *self)
+_hashlib_HASH_copy_locked(HASHobject *self, EVP_MD_CTX *new_ctx_p)
 {
     int result;
     ENTER_HASHLIB(self);
@@ -561,21 +574,21 @@ locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject 
*self)
 /* External methods for a hash object */
 
 /*[clinic input]
-_hashlib.HASH.copy as EVP_copy
+_hashlib.HASH.copy
 
 Return a copy of the hash object.
 [clinic start generated code]*/
 
 static PyObject *
-EVP_copy_impl(EVPobject *self)
-/*[clinic end generated code: output=b370c21cdb8ca0b4 input=31455b6a3e638069]*/
+_hashlib_HASH_copy_impl(HASHobject *self)
+/*[clinic end generated code: output=2545541af18d53d7 input=814b19202cd08a26]*/
 {
-    EVPobject *newobj;
+    HASHobject *newobj;
 
-    if ((newobj = newEVPobject(Py_TYPE(self))) == NULL)
+    if ((newobj = new_hash_object(Py_TYPE(self))) == NULL)
         return NULL;
 
-    if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+    if (!_hashlib_HASH_copy_locked(self, newobj->ctx)) {
         Py_DECREF(newobj);
         notify_ssl_error_occurred();
         return NULL;
@@ -584,14 +597,14 @@ EVP_copy_impl(EVPobject *self)
 }
 
 /*[clinic input]
-_hashlib.HASH.digest as EVP_digest
+_hashlib.HASH.digest
 
 Return the digest value as a bytes object.
 [clinic start generated code]*/
 
 static PyObject *
-EVP_digest_impl(EVPobject *self)
-/*[clinic end generated code: output=0f6a3a0da46dc12d input=03561809a419bf00]*/
+_hashlib_HASH_digest_impl(HASHobject *self)
+/*[clinic end generated code: output=3fc6f9671d712850 input=d8d528d6e50af0de]*/
 {
     unsigned char digest[EVP_MAX_MD_SIZE];
     EVP_MD_CTX *temp_ctx;
@@ -604,7 +617,7 @@ EVP_digest_impl(EVPobject *self)
         return NULL;
     }
 
-    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+    if (!_hashlib_HASH_copy_locked(self, temp_ctx)) {
         goto error;
     }
     digest_size = EVP_MD_CTX_size(temp_ctx);
@@ -623,14 +636,14 @@ EVP_digest_impl(EVPobject *self)
 }
 
 /*[clinic input]
-_hashlib.HASH.hexdigest as EVP_hexdigest
+_hashlib.HASH.hexdigest
 
 Return the digest value as a string of hexadecimal digits.
 [clinic start generated code]*/
 
 static PyObject *
-EVP_hexdigest_impl(EVPobject *self)
-/*[clinic end generated code: output=18e6decbaf197296 input=aff9cf0e4c741a9a]*/
+_hashlib_HASH_hexdigest_impl(HASHobject *self)
+/*[clinic end generated code: output=1b8e60d9711e7f4d input=ae7553f78f8372d8]*/
 {
     unsigned char digest[EVP_MAX_MD_SIZE];
     EVP_MD_CTX *temp_ctx;
@@ -643,7 +656,7 @@ EVP_hexdigest_impl(EVPobject *self)
     }
 
     /* Get the raw (binary) digest value */
-    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+    if (!_hashlib_HASH_copy_locked(self, temp_ctx)) {
         goto error;
     }
     digest_size = EVP_MD_CTX_size(temp_ctx);
@@ -662,7 +675,7 @@ EVP_hexdigest_impl(EVPobject *self)
 }
 
 /*[clinic input]
-_hashlib.HASH.update as EVP_update
+_hashlib.HASH.update
 
     obj: object
     /
@@ -671,8 +684,8 @@ Update this hash object's state with the provided string.
 [clinic start generated code]*/
 
 static PyObject *
-EVP_update_impl(EVPobject *self, PyObject *obj)
-/*[clinic end generated code: output=d56f91c68348f95f input=9b30ec848f015501]*/
+_hashlib_HASH_update_impl(HASHobject *self, PyObject *obj)
+/*[clinic end generated code: output=62ad989754946b86 input=aa1ce20e3f92ceb6]*/
 {
     int result;
     Py_buffer view;
@@ -685,11 +698,11 @@ EVP_update_impl(EVPobject *self, PyObject *obj)
     if (self->use_mutex) {
         Py_BEGIN_ALLOW_THREADS
         PyMutex_Lock(&self->mutex);
-        result = EVP_hash(self, view.buf, view.len);
+        result = _hashlib_HASH_hash(self, view.buf, view.len);
         PyMutex_Unlock(&self->mutex);
         Py_END_ALLOW_THREADS
     } else {
-        result = EVP_hash(self, view.buf, view.len);
+        result = _hashlib_HASH_hash(self, view.buf, view.len);
     }
 
     PyBuffer_Release(&view);
@@ -699,54 +712,54 @@ EVP_update_impl(EVPobject *self, PyObject *obj)
     Py_RETURN_NONE;
 }
 
-static PyMethodDef EVP_methods[] = {
-    EVP_UPDATE_METHODDEF
-    EVP_DIGEST_METHODDEF
-    EVP_HEXDIGEST_METHODDEF
-    EVP_COPY_METHODDEF
+static PyMethodDef HASH_methods[] = {
+    _HASHLIB_HASH_COPY_METHODDEF
+    _HASHLIB_HASH_DIGEST_METHODDEF
+    _HASHLIB_HASH_HEXDIGEST_METHODDEF
+    _HASHLIB_HASH_UPDATE_METHODDEF
     {NULL, NULL}  /* sentinel */
 };
 
 static PyObject *
-EVP_get_block_size(PyObject *op, void *Py_UNUSED(closure))
+_hashlib_HASH_get_blocksize(PyObject *op, void *Py_UNUSED(closure))
 {
-    EVPobject *self = EVPobject_CAST(op);
+    HASHobject *self = HASHobject_CAST(op);
     long block_size = EVP_MD_CTX_block_size(self->ctx);
     return PyLong_FromLong(block_size);
 }
 
 static PyObject *
-EVP_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
+_hashlib_HASH_get_digestsize(PyObject *op, void *Py_UNUSED(closure))
 {
-    EVPobject *self = EVPobject_CAST(op);
+    HASHobject *self = HASHobject_CAST(op);
     long size = EVP_MD_CTX_size(self->ctx);
     return PyLong_FromLong(size);
 }
 
 static PyObject *
-EVP_get_name(PyObject *op, void *Py_UNUSED(closure))
+_hashlib_HASH_get_name(PyObject *op, void *Py_UNUSED(closure))
 {
-    EVPobject *self = EVPobject_CAST(op);
+    HASHobject *self = HASHobject_CAST(op);
     const EVP_MD *md = EVP_MD_CTX_md(self->ctx);
     if (md == NULL) {
         notify_ssl_error_occurred();
         return NULL;
     }
-    return py_digest_name(md);
+    return get_openssl_evp_md_name(md);
 }
 
-static PyGetSetDef EVP_getseters[] = {
-    {"digest_size", EVP_get_digest_size, NULL, NULL, NULL},
-    {"block_size", EVP_get_block_size, NULL, NULL, NULL},
-    {"name", EVP_get_name, NULL, NULL, PyDoc_STR("algorithm name.")},
+static PyGetSetDef HASH_getsets[] = {
+    {"digest_size", _hashlib_HASH_get_digestsize, NULL, NULL, NULL},
+    {"block_size", _hashlib_HASH_get_blocksize, NULL, NULL, NULL},
+    {"name", _hashlib_HASH_get_name, NULL, NULL, PyDoc_STR("algorithm name.")},
     {NULL}  /* Sentinel */
 };
 
 
 static PyObject *
-EVP_repr(PyObject *self)
+_hashlib_HASH_repr(PyObject *self)
 {
-    PyObject *name = EVP_get_name(self, NULL);
+    PyObject *name = _hashlib_HASH_get_name(self, NULL);
     if (name == NULL) {
         return NULL;
     }
@@ -756,7 +769,7 @@ EVP_repr(PyObject *self)
     return repr;
 }
 
-PyDoc_STRVAR(hashtype_doc,
+PyDoc_STRVAR(HASHobject_type_doc,
 "HASH(name, string=b\'\')\n"
 "--\n"
 "\n"
@@ -774,27 +787,31 @@ PyDoc_STRVAR(hashtype_doc,
 "name -- the hash algorithm being used by this object\n"
 "digest_size -- number of bytes in this hashes output");
 
-static PyType_Slot EVPtype_slots[] = {
-    {Py_tp_dealloc, EVP_dealloc},
-    {Py_tp_repr, EVP_repr},
-    {Py_tp_doc, (char *)hashtype_doc},
-    {Py_tp_methods, EVP_methods},
-    {Py_tp_getset, EVP_getseters},
+static PyType_Slot HASHobject_type_slots[] = {
+    {Py_tp_dealloc, _hashlib_HASH_dealloc},
+    {Py_tp_repr, _hashlib_HASH_repr},
+    {Py_tp_doc, (char *)HASHobject_type_doc},
+    {Py_tp_methods, HASH_methods},
+    {Py_tp_getset, HASH_getsets},
     {0, 0},
 };
 
-static PyType_Spec EVPtype_spec = {
-    "_hashlib.HASH",    /*tp_name*/
-    sizeof(EVPobject),  /*tp_basicsize*/
-    0,                  /*tp_itemsize*/
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE,
-    EVPtype_slots
+static PyType_Spec HASHobject_type_spec = {
+    .name = "_hashlib.HASH",
+    .basicsize = sizeof(HASHobject),
+    .flags = (
+        Py_TPFLAGS_DEFAULT
+        | Py_TPFLAGS_BASETYPE
+        | Py_TPFLAGS_DISALLOW_INSTANTIATION
+        | Py_TPFLAGS_IMMUTABLETYPE
+    ),
+    .slots = HASHobject_type_slots
 };
 
 #ifdef PY_OPENSSL_HAS_SHAKE
 
 /*[clinic input]
-_hashlib.HASHXOF.digest as EVPXOF_digest
+_hashlib.HASHXOF.digest
 
   length: Py_ssize_t
 
@@ -802,8 +819,8 @@ Return the digest value as a bytes object.
 [clinic start generated code]*/
 
 static PyObject *
-EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length)
-/*[clinic end generated code: output=ef9320c23280efad input=816a6537cea3d1db]*/
+_hashlib_HASHXOF_digest_impl(HASHobject *self, Py_ssize_t length)
+/*[clinic end generated code: output=dcb09335dd2fe908 input=3eb034ce03c55b21]*/
 {
     EVP_MD_CTX *temp_ctx;
     PyObject *retval = PyBytes_FromStringAndSize(NULL, length);
@@ -819,7 +836,7 @@ EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length)
         return NULL;
     }
 
-    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+    if (!_hashlib_HASH_copy_locked(self, temp_ctx)) {
         goto error;
     }
     if (!EVP_DigestFinalXOF(temp_ctx,
@@ -840,7 +857,7 @@ EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length)
 }
 
 /*[clinic input]
-_hashlib.HASHXOF.hexdigest as EVPXOF_hexdigest
+_hashlib.HASHXOF.hexdigest
 
     length: Py_ssize_t
 
@@ -848,8 +865,8 @@ Return the digest value as a string of hexadecimal digits.
 [clinic start generated code]*/
 
 static PyObject *
-EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length)
-/*[clinic end generated code: output=eb3e6ee7788bf5b2 input=5f9d6a8f269e34df]*/
+_hashlib_HASHXOF_hexdigest_impl(HASHobject *self, Py_ssize_t length)
+/*[clinic end generated code: output=519431cafa014f39 input=0e58f7238adb7ab8]*/
 {
     unsigned char *digest;
     EVP_MD_CTX *temp_ctx;
@@ -869,7 +886,7 @@ EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length)
     }
 
     /* Get the raw (binary) digest value */
-    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+    if (!_hashlib_HASH_copy_locked(self, temp_ctx)) {
         goto error;
     }
     if (!EVP_DigestFinalXOF(temp_ctx, digest, length)) {
@@ -889,25 +906,26 @@ EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length)
     return NULL;
 }
 
-static PyMethodDef EVPXOF_methods[] = {
-    EVPXOF_DIGEST_METHODDEF
-    EVPXOF_HEXDIGEST_METHODDEF
+static PyMethodDef HASHXOFobject_methods[] = {
+    _HASHLIB_HASHXOF_DIGEST_METHODDEF
+    _HASHLIB_HASHXOF_HEXDIGEST_METHODDEF
     {NULL, NULL}  /* sentinel */
 };
 
 
 static PyObject *
-EVPXOF_get_digest_size(PyObject *Py_UNUSED(self), void *Py_UNUSED(closure))
+_hashlib_HASHXOF_digest_size(PyObject *Py_UNUSED(self),
+                             void *Py_UNUSED(closure))
 {
     return PyLong_FromLong(0);
 }
 
-static PyGetSetDef EVPXOF_getseters[] = {
-    {"digest_size", EVPXOF_get_digest_size, NULL, NULL, NULL},
+static PyGetSetDef HASHXOFobject_getsets[] = {
+    {"digest_size", _hashlib_HASHXOF_digest_size, NULL, NULL, NULL},
     {NULL}  /* Sentinel */
 };
 
-PyDoc_STRVAR(hashxoftype_doc,
+PyDoc_STRVAR(HASHXOFobject_type_doc,
 "HASHXOF(name, string=b\'\')\n"
 "--\n"
 "\n"
@@ -925,38 +943,42 @@ PyDoc_STRVAR(hashxoftype_doc,
 "name -- the hash algorithm being used by this object\n"
 "digest_size -- number of bytes in this hashes output");
 
-static PyType_Slot EVPXOFtype_slots[] = {
-    {Py_tp_doc, (char *)hashxoftype_doc},
-    {Py_tp_methods, EVPXOF_methods},
-    {Py_tp_getset, EVPXOF_getseters},
+static PyType_Slot HASHXOFobject_type_slots[] = {
+    {Py_tp_doc, (char *)HASHXOFobject_type_doc},
+    {Py_tp_methods, HASHXOFobject_methods},
+    {Py_tp_getset, HASHXOFobject_getsets},
     {0, 0},
 };
 
-static PyType_Spec EVPXOFtype_spec = {
-    "_hashlib.HASHXOF",    /*tp_name*/
-    sizeof(EVPobject),  /*tp_basicsize*/
-    0,                  /*tp_itemsize*/
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE,
-    EVPXOFtype_slots
+static PyType_Spec HASHXOFobject_type_spec = {
+    .name = "_hashlib.HASHXOF",
+    .basicsize = sizeof(HASHobject),
+    .flags = (
+        Py_TPFLAGS_DEFAULT
+        | Py_TPFLAGS_BASETYPE
+        | Py_TPFLAGS_DISALLOW_INSTANTIATION
+        | Py_TPFLAGS_IMMUTABLETYPE
+    ),
+    .slots = HASHXOFobject_type_slots
 };
 
 
 #endif
 
-static PyObject*
-py_evp_fromname(PyObject *module, const char *digestname, PyObject *data_obj,
-                int usedforsecurity)
+static PyObject *
+_hashlib_HASH(PyObject *module, const char *digestname, PyObject *data_obj,
+              int usedforsecurity)
 {
     Py_buffer view = { 0 };
     PY_EVP_MD *digest = NULL;
     PyTypeObject *type;
-    EVPobject *self = NULL;
+    HASHobject *self = NULL;
 
     if (data_obj != NULL) {
         GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
     }
 
-    digest = py_digest_by_name(
+    digest = get_openssl_evp_md_by_utf8name(
         module, digestname, usedforsecurity ? Py_ht_evp : Py_ht_evp_nosecurity
     );
     if (digest == NULL) {
@@ -964,12 +986,12 @@ py_evp_fromname(PyObject *module, const char *digestname, 
PyObject *data_obj,
     }
 
     if ((EVP_MD_flags(digest) & EVP_MD_FLAG_XOF) == EVP_MD_FLAG_XOF) {
-        type = get_hashlib_state(module)->EVPXOFtype;
+        type = get_hashlib_state(module)->HASHXOF_type;
     } else {
-        type = get_hashlib_state(module)->EVPtype;
+        type = get_hashlib_state(module)->HASH_type;
     }
 
-    self = newEVPobject(type);
+    self = new_hash_object(type);
     if (self == NULL) {
         goto exit;
     }
@@ -994,10 +1016,10 @@ py_evp_fromname(PyObject *module, const char 
*digestname, PyObject *data_obj,
             /* We do not initialize self->lock here as this is the constructor
              * where it is not yet possible to have concurrent access. */
             Py_BEGIN_ALLOW_THREADS
-            result = EVP_hash(self, view.buf, view.len);
+            result = _hashlib_HASH_hash(self, view.buf, view.len);
             Py_END_ALLOW_THREADS
         } else {
-            result = EVP_hash(self, view.buf, view.len);
+            result = _hashlib_HASH_hash(self, view.buf, view.len);
         }
         if (result == -1) {
             assert(PyErr_Occurred());
@@ -1021,9 +1043,9 @@ py_evp_fromname(PyObject *module, const char *digestname, 
PyObject *data_obj,
 /* The module-level function: new() */
 
 /*[clinic input]
-_hashlib.new as EVP_new
+_hashlib.new as _hashlib_HASH_new
 
-    name as name_obj: object
+    name: str
     string as data_obj: object(c_default="NULL") = b''
     *
     usedforsecurity: bool = True
@@ -1037,16 +1059,11 @@ The MD5 and SHA1 algorithms are always supported.
 [clinic start generated code]*/
 
 static PyObject *
-EVP_new_impl(PyObject *module, PyObject *name_obj, PyObject *data_obj,
-             int usedforsecurity)
-/*[clinic end generated code: output=ddd5053f92dffe90 input=c24554d0337be1b0]*/
+_hashlib_HASH_new_impl(PyObject *module, const char *name,
+                       PyObject *data_obj, int usedforsecurity)
+/*[clinic end generated code: output=30c6e7b9a5a4dce3 input=28848db5ccd0a9b5]*/
 {
-    char *name;
-    if (!PyArg_Parse(name_obj, "s", &name)) {
-        PyErr_SetString(PyExc_TypeError, "name must be a string");
-        return NULL;
-    }
-    return py_evp_fromname(module, name, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, name, data_obj, usedforsecurity);
 }
 
 
@@ -1066,7 +1083,7 @@ _hashlib_openssl_md5_impl(PyObject *module, PyObject 
*data_obj,
                           int usedforsecurity)
 /*[clinic end generated code: output=87b0186440a44f8c input=990e36d5e689b16e]*/
 {
-    return py_evp_fromname(module, Py_hash_md5, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_md5, data_obj, usedforsecurity);
 }
 
 
@@ -1086,7 +1103,7 @@ _hashlib_openssl_sha1_impl(PyObject *module, PyObject 
*data_obj,
                            int usedforsecurity)
 /*[clinic end generated code: output=6813024cf690670d input=948f2f4b6deabc10]*/
 {
-    return py_evp_fromname(module, Py_hash_sha1, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha1, data_obj, usedforsecurity);
 }
 
 
@@ -1106,7 +1123,7 @@ _hashlib_openssl_sha224_impl(PyObject *module, PyObject 
*data_obj,
                              int usedforsecurity)
 /*[clinic end generated code: output=a2dfe7cc4eb14ebb input=f9272821fadca505]*/
 {
-    return py_evp_fromname(module, Py_hash_sha224, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha224, data_obj, usedforsecurity);
 }
 
 
@@ -1126,7 +1143,7 @@ _hashlib_openssl_sha256_impl(PyObject *module, PyObject 
*data_obj,
                              int usedforsecurity)
 /*[clinic end generated code: output=1f874a34870f0a68 input=549fad9d2930d4c5]*/
 {
-    return py_evp_fromname(module, Py_hash_sha256, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha256, data_obj, usedforsecurity);
 }
 
 
@@ -1146,7 +1163,7 @@ _hashlib_openssl_sha384_impl(PyObject *module, PyObject 
*data_obj,
                              int usedforsecurity)
 /*[clinic end generated code: output=58529eff9ca457b2 input=48601a6e3bf14ad7]*/
 {
-    return py_evp_fromname(module, Py_hash_sha384, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha384, data_obj, usedforsecurity);
 }
 
 
@@ -1166,7 +1183,7 @@ _hashlib_openssl_sha512_impl(PyObject *module, PyObject 
*data_obj,
                              int usedforsecurity)
 /*[clinic end generated code: output=2c744c9e4a40d5f6 input=c5c46a2a817aa98f]*/
 {
-    return py_evp_fromname(module, Py_hash_sha512, data_obj, usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha512, data_obj, usedforsecurity);
 }
 
 
@@ -1188,7 +1205,7 @@ _hashlib_openssl_sha3_224_impl(PyObject *module, PyObject 
*data_obj,
                                int usedforsecurity)
 /*[clinic end generated code: output=144641c1d144b974 input=e3a01b2888916157]*/
 {
-    return py_evp_fromname(module, Py_hash_sha3_224, data_obj, 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha3_224, data_obj, usedforsecurity);
 }
 
 /*[clinic input]
@@ -1207,7 +1224,7 @@ _hashlib_openssl_sha3_256_impl(PyObject *module, PyObject 
*data_obj,
                                int usedforsecurity)
 /*[clinic end generated code: output=c61f1ab772d06668 input=e2908126c1b6deed]*/
 {
-    return py_evp_fromname(module, Py_hash_sha3_256, data_obj , 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha3_256, data_obj, usedforsecurity);
 }
 
 /*[clinic input]
@@ -1226,7 +1243,7 @@ _hashlib_openssl_sha3_384_impl(PyObject *module, PyObject 
*data_obj,
                                int usedforsecurity)
 /*[clinic end generated code: output=f68e4846858cf0ee input=ec0edf5c792f8252]*/
 {
-    return py_evp_fromname(module, Py_hash_sha3_384, data_obj , 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha3_384, data_obj, usedforsecurity);
 }
 
 /*[clinic input]
@@ -1245,7 +1262,7 @@ _hashlib_openssl_sha3_512_impl(PyObject *module, PyObject 
*data_obj,
                                int usedforsecurity)
 /*[clinic end generated code: output=2eede478c159354a input=64e2cc0c094d56f4]*/
 {
-    return py_evp_fromname(module, Py_hash_sha3_512, data_obj , 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_sha3_512, data_obj, usedforsecurity);
 }
 #endif /* PY_OPENSSL_HAS_SHA3 */
 
@@ -1266,7 +1283,7 @@ _hashlib_openssl_shake_128_impl(PyObject *module, 
PyObject *data_obj,
                                 int usedforsecurity)
 /*[clinic end generated code: output=bc49cdd8ada1fa97 input=6c9d67440eb33ec8]*/
 {
-    return py_evp_fromname(module, Py_hash_shake_128, data_obj , 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_shake_128, data_obj, usedforsecurity);
 }
 
 /*[clinic input]
@@ -1285,7 +1302,7 @@ _hashlib_openssl_shake_256_impl(PyObject *module, 
PyObject *data_obj,
                                 int usedforsecurity)
 /*[clinic end generated code: output=358d213be8852df7 input=479cbe9fefd4a9f8]*/
 {
-    return py_evp_fromname(module, Py_hash_shake_256, data_obj , 
usedforsecurity);
+    return _hashlib_HASH(module, Py_hash_shake_256, data_obj, usedforsecurity);
 }
 #endif /* PY_OPENSSL_HAS_SHAKE */
 
@@ -1312,7 +1329,7 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
     long dklen;
     int retval;
 
-    PY_EVP_MD *digest = py_digest_by_name(module, hash_name, Py_ht_pbkdf2);
+    PY_EVP_MD *digest = get_openssl_evp_md_by_utf8name(module, hash_name, 
Py_ht_pbkdf2);
     if (digest == NULL) {
         goto end;
     }
@@ -1514,7 +1531,7 @@ _hashlib_hmac_singleshot_impl(PyObject *module, Py_buffer 
*key,
         return NULL;
     }
 
-    evp = py_digest_by_digestmod(module, digest, Py_ht_mac);
+    evp = get_openssl_evp_md(module, digest, Py_ht_mac);
     if (evp == NULL) {
         return NULL;
     }
@@ -1583,7 +1600,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, 
PyObject *msg_obj,
         return NULL;
     }
 
-    digest = py_digest_by_digestmod(module, digestmod, Py_ht_mac);
+    digest = get_openssl_evp_md(module, digestmod, Py_ht_mac);
     if (digest == NULL) {
         return NULL;
     }
@@ -1740,7 +1757,7 @@ _hmac_repr(PyObject *op)
     if (md == NULL) {
         return NULL;
     }
-    PyObject *digest_name = py_digest_name(md);
+    PyObject *digest_name = get_openssl_evp_md_name(md);
     if (digest_name == NULL) {
         return NULL;
     }
@@ -1860,7 +1877,7 @@ _hashlib_hmac_get_name(PyObject *op, void 
*Py_UNUSED(closure))
     if (md == NULL) {
         return NULL;
     }
-    PyObject *digest_name = py_digest_name(md);
+    PyObject *digest_name = get_openssl_evp_md_name(md);
     if (digest_name == NULL) {
         return NULL;
     }
@@ -1926,7 +1943,7 @@ typedef struct _internal_name_mapper_state {
 
 /* A callback function to pass to OpenSSL's OBJ_NAME_do_all(...) */
 static void
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#ifdef Py_HAS_OPENSSL3_SUPPORT
 _openssl_hash_name_mapper(EVP_MD *md, void *arg)
 #else
 _openssl_hash_name_mapper(const EVP_MD *md, const char *from,
@@ -1942,7 +1959,7 @@ _openssl_hash_name_mapper(const EVP_MD *md, const char 
*from,
         return;
     }
 
-    py_name = py_digest_name(md);
+    py_name = get_openssl_evp_md_name(md);
     if (py_name == NULL) {
         state->error = 1;
     } else {
@@ -1966,7 +1983,7 @@ hashlib_md_meth_names(PyObject *module)
         return -1;
     }
 
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#ifdef Py_HAS_OPENSSL3_SUPPORT
     // get algorithms from all activated providers in default context
     EVP_MD_do_all_provided(NULL, &_openssl_hash_name_mapper, &state);
 #else
@@ -1999,7 +2016,7 @@ _hashlib_get_fips_mode_impl(PyObject *module)
 /*[clinic end generated code: output=87eece1bab4d3fa9 input=2db61538c41c6fef]*/
 
 {
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#ifdef Py_HAS_OPENSSL3_SUPPORT
     return EVP_default_properties_is_fips_enabled(NULL);
 #else
     ERR_clear_error();
@@ -2134,7 +2151,7 @@ _hashlib_compare_digest_impl(PyObject *module, PyObject 
*a, PyObject *b)
 /* List of functions exported by this module */
 
 static struct PyMethodDef EVP_functions[] = {
-    EVP_NEW_METHODDEF
+    _HASHLIB_HASH_NEW_METHODDEF
     PBKDF2_HMAC_METHODDEF
     _HASHLIB_SCRYPT_METHODDEF
     _HASHLIB_GET_FIPS_MODE_METHODDEF
@@ -2163,10 +2180,10 @@ static int
 hashlib_traverse(PyObject *m, visitproc visit, void *arg)
 {
     _hashlibstate *state = get_hashlib_state(m);
-    Py_VISIT(state->EVPtype);
+    Py_VISIT(state->HASH_type);
     Py_VISIT(state->HMACtype);
 #ifdef PY_OPENSSL_HAS_SHAKE
-    Py_VISIT(state->EVPXOFtype);
+    Py_VISIT(state->HASHXOF_type);
 #endif
     Py_VISIT(state->constructs);
     Py_VISIT(state->unsupported_digestmod_error);
@@ -2177,10 +2194,10 @@ static int
 hashlib_clear(PyObject *m)
 {
     _hashlibstate *state = get_hashlib_state(m);
-    Py_CLEAR(state->EVPtype);
+    Py_CLEAR(state->HASH_type);
     Py_CLEAR(state->HMACtype);
 #ifdef PY_OPENSSL_HAS_SHAKE
-    Py_CLEAR(state->EVPXOFtype);
+    Py_CLEAR(state->HASHXOF_type);
 #endif
     Py_CLEAR(state->constructs);
     Py_CLEAR(state->unsupported_digestmod_error);
@@ -2214,37 +2231,37 @@ hashlib_init_hashtable(PyObject *module)
 }
 
 static int
-hashlib_init_evptype(PyObject *module)
+hashlib_init_HASH_type(PyObject *module)
 {
     _hashlibstate *state = get_hashlib_state(module);
 
-    state->EVPtype = (PyTypeObject *)PyType_FromSpec(&EVPtype_spec);
-    if (state->EVPtype == NULL) {
+    state->HASH_type = (PyTypeObject *)PyType_FromSpec(&HASHobject_type_spec);
+    if (state->HASH_type == NULL) {
         return -1;
     }
-    if (PyModule_AddType(module, state->EVPtype) < 0) {
+    if (PyModule_AddType(module, state->HASH_type) < 0) {
         return -1;
     }
     return 0;
 }
 
 static int
-hashlib_init_evpxoftype(PyObject *module)
+hashlib_init_HASHXOF_type(PyObject *module)
 {
 #ifdef PY_OPENSSL_HAS_SHAKE
     _hashlibstate *state = get_hashlib_state(module);
 
-    if (state->EVPtype == NULL) {
+    if (state->HASH_type == NULL) {
         return -1;
     }
 
-    state->EVPXOFtype = (PyTypeObject *)PyType_FromSpecWithBases(
-        &EVPXOFtype_spec, (PyObject *)state->EVPtype
+    state->HASHXOF_type = (PyTypeObject *)PyType_FromSpecWithBases(
+        &HASHXOFobject_type_spec, (PyObject *)state->HASH_type
     );
-    if (state->EVPXOFtype == NULL) {
+    if (state->HASHXOF_type == NULL) {
         return -1;
     }
-    if (PyModule_AddType(module, state->EVPXOFtype) < 0) {
+    if (PyModule_AddType(module, state->HASHXOF_type) < 0) {
         return -1;
     }
 #endif
@@ -2341,8 +2358,8 @@ hashlib_constants(PyObject *module)
 
 static PyModuleDef_Slot hashlib_slots[] = {
     {Py_mod_exec, hashlib_init_hashtable},
-    {Py_mod_exec, hashlib_init_evptype},
-    {Py_mod_exec, hashlib_init_evpxoftype},
+    {Py_mod_exec, hashlib_init_HASH_type},
+    {Py_mod_exec, hashlib_init_HASHXOF_type},
     {Py_mod_exec, hashlib_init_hmactype},
     {Py_mod_exec, hashlib_md_meth_names},
     {Py_mod_exec, hashlib_init_constructors},
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index 59ab46ca3f0978..b2f6b25a235e68 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -10,98 +10,98 @@ preserve
 #include "pycore_long.h"          // _PyLong_UnsignedLong_Converter()
 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 
-PyDoc_STRVAR(EVP_copy__doc__,
+PyDoc_STRVAR(_hashlib_HASH_copy__doc__,
 "copy($self, /)\n"
 "--\n"
 "\n"
 "Return a copy of the hash object.");
 
-#define EVP_COPY_METHODDEF    \
-    {"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__},
+#define _HASHLIB_HASH_COPY_METHODDEF    \
+    {"copy", (PyCFunction)_hashlib_HASH_copy, METH_NOARGS, 
_hashlib_HASH_copy__doc__},
 
 static PyObject *
-EVP_copy_impl(EVPobject *self);
+_hashlib_HASH_copy_impl(HASHobject *self);
 
 static PyObject *
-EVP_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HASH_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
 {
-    return EVP_copy_impl((EVPobject *)self);
+    return _hashlib_HASH_copy_impl((HASHobject *)self);
 }
 
-PyDoc_STRVAR(EVP_digest__doc__,
+PyDoc_STRVAR(_hashlib_HASH_digest__doc__,
 "digest($self, /)\n"
 "--\n"
 "\n"
 "Return the digest value as a bytes object.");
 
-#define EVP_DIGEST_METHODDEF    \
-    {"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__},
+#define _HASHLIB_HASH_DIGEST_METHODDEF    \
+    {"digest", (PyCFunction)_hashlib_HASH_digest, METH_NOARGS, 
_hashlib_HASH_digest__doc__},
 
 static PyObject *
-EVP_digest_impl(EVPobject *self);
+_hashlib_HASH_digest_impl(HASHobject *self);
 
 static PyObject *
-EVP_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HASH_digest(PyObject *self, PyObject *Py_UNUSED(ignored))
 {
-    return EVP_digest_impl((EVPobject *)self);
+    return _hashlib_HASH_digest_impl((HASHobject *)self);
 }
 
-PyDoc_STRVAR(EVP_hexdigest__doc__,
+PyDoc_STRVAR(_hashlib_HASH_hexdigest__doc__,
 "hexdigest($self, /)\n"
 "--\n"
 "\n"
 "Return the digest value as a string of hexadecimal digits.");
 
-#define EVP_HEXDIGEST_METHODDEF    \
-    {"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, 
EVP_hexdigest__doc__},
+#define _HASHLIB_HASH_HEXDIGEST_METHODDEF    \
+    {"hexdigest", (PyCFunction)_hashlib_HASH_hexdigest, METH_NOARGS, 
_hashlib_HASH_hexdigest__doc__},
 
 static PyObject *
-EVP_hexdigest_impl(EVPobject *self);
+_hashlib_HASH_hexdigest_impl(HASHobject *self);
 
 static PyObject *
-EVP_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
+_hashlib_HASH_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
 {
-    return EVP_hexdigest_impl((EVPobject *)self);
+    return _hashlib_HASH_hexdigest_impl((HASHobject *)self);
 }
 
-PyDoc_STRVAR(EVP_update__doc__,
+PyDoc_STRVAR(_hashlib_HASH_update__doc__,
 "update($self, obj, /)\n"
 "--\n"
 "\n"
 "Update this hash object\'s state with the provided string.");
 
-#define EVP_UPDATE_METHODDEF    \
-    {"update", (PyCFunction)EVP_update, METH_O, EVP_update__doc__},
+#define _HASHLIB_HASH_UPDATE_METHODDEF    \
+    {"update", (PyCFunction)_hashlib_HASH_update, METH_O, 
_hashlib_HASH_update__doc__},
 
 static PyObject *
-EVP_update_impl(EVPobject *self, PyObject *obj);
+_hashlib_HASH_update_impl(HASHobject *self, PyObject *obj);
 
 static PyObject *
-EVP_update(PyObject *self, PyObject *obj)
+_hashlib_HASH_update(PyObject *self, PyObject *obj)
 {
     PyObject *return_value = NULL;
 
-    return_value = EVP_update_impl((EVPobject *)self, obj);
+    return_value = _hashlib_HASH_update_impl((HASHobject *)self, obj);
 
     return return_value;
 }
 
 #if defined(PY_OPENSSL_HAS_SHAKE)
 
-PyDoc_STRVAR(EVPXOF_digest__doc__,
+PyDoc_STRVAR(_hashlib_HASHXOF_digest__doc__,
 "digest($self, /, length)\n"
 "--\n"
 "\n"
 "Return the digest value as a bytes object.");
 
-#define EVPXOF_DIGEST_METHODDEF    \
-    {"digest", _PyCFunction_CAST(EVPXOF_digest), METH_FASTCALL|METH_KEYWORDS, 
EVPXOF_digest__doc__},
+#define _HASHLIB_HASHXOF_DIGEST_METHODDEF    \
+    {"digest", _PyCFunction_CAST(_hashlib_HASHXOF_digest), 
METH_FASTCALL|METH_KEYWORDS, _hashlib_HASHXOF_digest__doc__},
 
 static PyObject *
-EVPXOF_digest_impl(EVPobject *self, Py_ssize_t length);
+_hashlib_HASHXOF_digest_impl(HASHobject *self, Py_ssize_t length);
 
 static PyObject *
-EVPXOF_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, 
PyObject *kwnames)
+_hashlib_HASHXOF_digest(PyObject *self, PyObject *const *args, Py_ssize_t 
nargs, PyObject *kwnames)
 {
     PyObject *return_value = NULL;
     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -151,7 +151,7 @@ EVPXOF_digest(PyObject *self, PyObject *const *args, 
Py_ssize_t nargs, PyObject
         }
         length = ival;
     }
-    return_value = EVPXOF_digest_impl((EVPobject *)self, length);
+    return_value = _hashlib_HASHXOF_digest_impl((HASHobject *)self, length);
 
 exit:
     return return_value;
@@ -161,20 +161,20 @@ EVPXOF_digest(PyObject *self, PyObject *const *args, 
Py_ssize_t nargs, PyObject
 
 #if defined(PY_OPENSSL_HAS_SHAKE)
 
-PyDoc_STRVAR(EVPXOF_hexdigest__doc__,
+PyDoc_STRVAR(_hashlib_HASHXOF_hexdigest__doc__,
 "hexdigest($self, /, length)\n"
 "--\n"
 "\n"
 "Return the digest value as a string of hexadecimal digits.");
 
-#define EVPXOF_HEXDIGEST_METHODDEF    \
-    {"hexdigest", _PyCFunction_CAST(EVPXOF_hexdigest), 
METH_FASTCALL|METH_KEYWORDS, EVPXOF_hexdigest__doc__},
+#define _HASHLIB_HASHXOF_HEXDIGEST_METHODDEF    \
+    {"hexdigest", _PyCFunction_CAST(_hashlib_HASHXOF_hexdigest), 
METH_FASTCALL|METH_KEYWORDS, _hashlib_HASHXOF_hexdigest__doc__},
 
 static PyObject *
-EVPXOF_hexdigest_impl(EVPobject *self, Py_ssize_t length);
+_hashlib_HASHXOF_hexdigest_impl(HASHobject *self, Py_ssize_t length);
 
 static PyObject *
-EVPXOF_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, 
PyObject *kwnames)
+_hashlib_HASHXOF_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t 
nargs, PyObject *kwnames)
 {
     PyObject *return_value = NULL;
     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -224,7 +224,7 @@ EVPXOF_hexdigest(PyObject *self, PyObject *const *args, 
Py_ssize_t nargs, PyObje
         }
         length = ival;
     }
-    return_value = EVPXOF_hexdigest_impl((EVPobject *)self, length);
+    return_value = _hashlib_HASHXOF_hexdigest_impl((HASHobject *)self, length);
 
 exit:
     return return_value;
@@ -232,7 +232,7 @@ EVPXOF_hexdigest(PyObject *self, PyObject *const *args, 
Py_ssize_t nargs, PyObje
 
 #endif /* defined(PY_OPENSSL_HAS_SHAKE) */
 
-PyDoc_STRVAR(EVP_new__doc__,
+PyDoc_STRVAR(_hashlib_HASH_new__doc__,
 "new($module, /, name, string=b\'\', *, usedforsecurity=True)\n"
 "--\n"
 "\n"
@@ -243,15 +243,15 @@ PyDoc_STRVAR(EVP_new__doc__,
 "\n"
 "The MD5 and SHA1 algorithms are always supported.");
 
-#define EVP_NEW_METHODDEF    \
-    {"new", _PyCFunction_CAST(EVP_new), METH_FASTCALL|METH_KEYWORDS, 
EVP_new__doc__},
+#define _HASHLIB_HASH_NEW_METHODDEF    \
+    {"new", _PyCFunction_CAST(_hashlib_HASH_new), METH_FASTCALL|METH_KEYWORDS, 
_hashlib_HASH_new__doc__},
 
 static PyObject *
-EVP_new_impl(PyObject *module, PyObject *name_obj, PyObject *data_obj,
-             int usedforsecurity);
+_hashlib_HASH_new_impl(PyObject *module, const char *name,
+                       PyObject *data_obj, int usedforsecurity);
 
 static PyObject *
-EVP_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject 
*kwnames)
+_hashlib_HASH_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, 
PyObject *kwnames)
 {
     PyObject *return_value = NULL;
     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
@@ -283,7 +283,7 @@ EVP_new(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs, PyObject *kwn
     #undef KWTUPLE
     PyObject *argsbuf[3];
     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 
1;
-    PyObject *name_obj;
+    const char *name;
     PyObject *data_obj = NULL;
     int usedforsecurity = 1;
 
@@ -292,7 +292,19 @@ EVP_new(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs, PyObject *kwn
     if (!args) {
         goto exit;
     }
-    name_obj = args[0];
+    if (!PyUnicode_Check(args[0])) {
+        _PyArg_BadArgument("new", "argument 'name'", "str", args[0]);
+        goto exit;
+    }
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+    if (name == NULL) {
+        goto exit;
+    }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
     if (!noptargs) {
         goto skip_optional_pos;
     }
@@ -311,7 +323,7 @@ EVP_new(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs, PyObject *kwn
         goto exit;
     }
 skip_optional_kwonly:
-    return_value = EVP_new_impl(module, name_obj, data_obj, usedforsecurity);
+    return_value = _hashlib_HASH_new_impl(module, name, data_obj, 
usedforsecurity);
 
 exit:
     return return_value;
@@ -1836,13 +1848,13 @@ _hashlib_compare_digest(PyObject *module, PyObject 
*const *args, Py_ssize_t narg
     return return_value;
 }
 
-#ifndef EVPXOF_DIGEST_METHODDEF
-    #define EVPXOF_DIGEST_METHODDEF
-#endif /* !defined(EVPXOF_DIGEST_METHODDEF) */
+#ifndef _HASHLIB_HASHXOF_DIGEST_METHODDEF
+    #define _HASHLIB_HASHXOF_DIGEST_METHODDEF
+#endif /* !defined(_HASHLIB_HASHXOF_DIGEST_METHODDEF) */
 
-#ifndef EVPXOF_HEXDIGEST_METHODDEF
-    #define EVPXOF_HEXDIGEST_METHODDEF
-#endif /* !defined(EVPXOF_HEXDIGEST_METHODDEF) */
+#ifndef _HASHLIB_HASHXOF_HEXDIGEST_METHODDEF
+    #define _HASHLIB_HASHXOF_HEXDIGEST_METHODDEF
+#endif /* !defined(_HASHLIB_HASHXOF_HEXDIGEST_METHODDEF) */
 
 #ifndef _HASHLIB_OPENSSL_SHA3_224_METHODDEF
     #define _HASHLIB_OPENSSL_SHA3_224_METHODDEF
@@ -1871,4 +1883,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const 
*args, Py_ssize_t narg
 #ifndef _HASHLIB_SCRYPT_METHODDEF
     #define _HASHLIB_SCRYPT_METHODDEF
 #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
-/*[clinic end generated code: output=2c78822e38be64a8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dc03b64435166a64 input=a9049054013a1b77]*/

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to