Skip to content

Commit 60eb7bd

Browse files
committed
Merge branch 'main' into feat/hashlib/evp-mac-134531
2 parents 56f73ca + 4a151ca commit 60eb7bd

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

Modules/_hashopenssl.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ raise_unsupported_algorithm_impl(PyObject *exc_type,
518518
{
519519
// Since OpenSSL 3.0, if the algorithm is not supported or fetching fails,
520520
// the reason lacks the algorithm name.
521-
int errcode = ERR_peek_last_error(), reason_id;
522-
switch (reason_id = ERR_GET_REASON(errcode)) {
521+
int errcode = ERR_peek_last_error();
522+
switch (ERR_GET_REASON(errcode)) {
523523
case ERR_R_UNSUPPORTED: {
524524
PyObject *text = PyUnicode_FromFormat(fallback_format, format_arg);
525525
if (text != NULL) {
@@ -688,13 +688,11 @@ disable_fips_property(Py_hash_type py_ht)
688688
* If 'name' is an OpenSSL indexed name, the return value is cached.
689689
*/
690690
static PY_EVP_MD *
691-
get_openssl_evp_md_by_utf8name(_hashlibstate *state,
692-
const char *name, Py_hash_type py_ht)
691+
get_openssl_evp_md_by_utf8name(_hashlibstate *state, const char *name,
692+
Py_hash_type py_ht)
693693
{
694694
PY_EVP_MD *digest = NULL, *other_digest = NULL;
695-
py_hashentry_t *entry = (py_hashentry_t *)_Py_hashtable_get(
696-
state->hashtable, (const void*)name
697-
);
695+
py_hashentry_t *entry = _Py_hashtable_get(state->hashtable, name);
698696

699697
if (entry != NULL) {
700698
if (!disable_fips_property(py_ht)) {
@@ -1277,19 +1275,13 @@ _hashlib_HASH(_hashlibstate *state, const char *digestname, PyObject *data_obj,
12771275
GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view);
12781276
}
12791277

1280-
digest = get_openssl_evp_md_by_utf8name(
1281-
state, digestname, usedforsecurity ? Py_ht_evp : Py_ht_evp_nosecurity
1282-
);
1278+
Py_hash_type purpose = usedforsecurity ? Py_ht_evp : Py_ht_evp_nosecurity;
1279+
digest = get_openssl_evp_md_by_utf8name(state, digestname, purpose);
12831280
if (digest == NULL) {
12841281
goto exit;
12851282
}
12861283

1287-
if ((EVP_MD_flags(digest) & EVP_MD_FLAG_XOF) == EVP_MD_FLAG_XOF) {
1288-
type = state->HASHXOF_type;
1289-
} else {
1290-
type = state->HASH_type;
1291-
}
1292-
1284+
type = PY_EVP_MD_xof(digest) ? state->HASHXOF_type : state->HASH_type;
12931285
self = new_hash_object(type);
12941286
if (self == NULL) {
12951287
goto exit;
@@ -1650,7 +1642,8 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
16501642
long dklen;
16511643
int retval;
16521644

1653-
PY_EVP_MD *digest = get_openssl_evp_md_by_utf8name(state, hash_name, Py_ht_pbkdf2);
1645+
PY_EVP_MD *digest = get_openssl_evp_md_by_utf8name(state, hash_name,
1646+
Py_ht_pbkdf2);
16541647
if (digest == NULL) {
16551648
goto end;
16561649
}

0 commit comments

Comments
 (0)