Skip to content

Commit 661472c

Browse files
committed
post-merge
1 parent fc6b0b1 commit 661472c

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

Modules/_hashopenssl.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,11 +1822,25 @@ hashlib_openssl_HMAC_evp_md_borrowed(HMACobject *self)
18221822
}
18231823
#endif
18241824

1825+
static int
1826+
hashlib_openssl_HMAC_update_once(Py_HMAC_CTX_TYPE *ctx, const Py_buffer *v)
1827+
{
1828+
int r;
18251829
#ifdef Py_HAS_OPENSSL3_SUPPORT
1826-
#define HASHLIB_OPENSSL_HMAC_UPDATE_ONCE EVP_MAC_update
1830+
r = EVP_MAC_update(ctx, (const unsigned char *)v->buf, (size_t)v->len);
18271831
#else
1828-
#define HASHLIB_OPENSSL_HMAC_UPDATE_ONCE HMAC_Update
1832+
r = HMAC_Update(ctx, (const unsigned char *)v->buf, (size_t)v->len);
18291833
#endif
1834+
if (r == 0) {
1835+
#ifdef Py_HAS_OPENSSL3_SUPPORT
1836+
notify_smart_ssl_error_occurred_in(Py_STRINGIFY(EVP_MAC_update));
1837+
#else
1838+
notify_smart_ssl_error_occurred_in(Py_STRINGIFY(HMAC_Update));
1839+
#endif
1840+
return -1;
1841+
}
1842+
return 0;
1843+
}
18301844

18311845
static void
18321846
hashlib_openssl_HMAC_ctx_free(Py_HMAC_CTX_TYPE *ctx)
@@ -1854,30 +1868,21 @@ hashlib_openssl_HMAC_update_with_lock(HMACobject *self, PyObject *data)
18541868
Py_buffer view = {0};
18551869
GET_BUFFER_VIEW_OR_ERROR(data, &view, return -1);
18561870
if (!self->use_mutex && view.len >= HASHLIB_GIL_MINSIZE) {
1857-
// TODO(picnixz): disable mutex afterwards
1871+
// TODO(picnixz): see https://github.com/python/cpython/issues/135239.
18581872
self->use_mutex = true;
18591873
}
18601874
if (self->use_mutex) {
18611875
Py_BEGIN_ALLOW_THREADS
18621876
PyMutex_Lock(&self->mutex);
1863-
r = HASHLIB_OPENSSL_HMAC_UPDATE_ONCE(self->ctx,
1864-
(const unsigned char *)view.buf,
1865-
(size_t)view.len);
1877+
r = hashlib_openssl_HMAC_update_once(self->ctx, &view);
18661878
PyMutex_Unlock(&self->mutex);
18671879
Py_END_ALLOW_THREADS
18681880
}
18691881
else {
1870-
r = HASHLIB_OPENSSL_HMAC_UPDATE_ONCE(self->ctx,
1871-
(const unsigned char *)view.buf,
1872-
(size_t)view.len);
1882+
r = hashlib_openssl_HMAC_update_once(self->ctx, &view);
18731883
}
18741884
PyBuffer_Release(&view);
1875-
if (r == 0) {
1876-
const char *funcname = Py_STRINGIFY(HASHLIB_OPENSSL_HMAC_UPDATE_ONCE);
1877-
notify_ssl_error_occurred_in(funcname);
1878-
return -1;
1879-
}
1880-
return 0;
1885+
return r;
18811886
}
18821887

18831888
static Py_HMAC_CTX_TYPE *
@@ -1894,9 +1899,9 @@ hashlib_openssl_HMAC_ctx_copy_with_lock(HMACobject *self)
18941899
}
18951900
#else
18961901
int r;
1897-
ctx = HMAC_CTX_new();
1902+
ctx = py_openssl_wrapper_HMAC_CTX_new();
18981903
if (ctx == NULL) {
1899-
goto error;
1904+
return NULL;
19001905
}
19011906
ENTER_HASHLIB(self);
19021907
r = HMAC_CTX_copy(ctx, self->ctx);

0 commit comments

Comments
 (0)