Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,6 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
{
_hashlibstate *state = get_hashlib_state(module);
PyObject *key_obj = NULL;
char *key;
long dklen;
int retval;

Expand Down Expand Up @@ -1682,24 +1681,24 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
goto end;
}

key_obj = PyBytes_FromStringAndSize(NULL, dklen);
if (key_obj == NULL) {
PyBytesWriter *writer = PyBytesWriter_Create(dklen);
if (writer == NULL) {
goto end;
}
key = PyBytes_AS_STRING(key_obj);

Py_BEGIN_ALLOW_THREADS
retval = PKCS5_PBKDF2_HMAC((const char *)password->buf, (int)password->len,
(const unsigned char *)salt->buf, (int)salt->len,
iterations, digest, dklen,
(unsigned char *)key);
(unsigned char *)PyBytesWriter_GetData(writer));
Py_END_ALLOW_THREADS

if (!retval) {
Py_CLEAR(key_obj);
PyBytesWriter_Discard(writer);
notify_ssl_error_occurred_in(Py_STRINGIFY(PKCS5_PBKDF2_HMAC));
goto end;
}
key_obj = PyBytesWriter_Finish(writer);

end:
if (digest != NULL) {
Expand Down Expand Up @@ -1799,7 +1798,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
(const char *)password->buf, (size_t)password->len,
(const unsigned char *)salt->buf, (size_t)salt->len,
(uint64_t)n, (uint64_t)r, (uint64_t)p, (uint64_t)maxmem,
PyBytesWriter_GetData(writer), (size_t)dklen
(unsigned char *)PyBytesWriter_GetData(writer), (size_t)dklen
);
Py_END_ALLOW_THREADS

Expand Down
Loading