@@ -1629,7 +1629,6 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
1629
1629
{
1630
1630
_hashlibstate * state = get_hashlib_state (module );
1631
1631
PyObject * key_obj = NULL ;
1632
- char * key ;
1633
1632
long dklen ;
1634
1633
int retval ;
1635
1634
@@ -1682,24 +1681,24 @@ pbkdf2_hmac_impl(PyObject *module, const char *hash_name,
1682
1681
goto end ;
1683
1682
}
1684
1683
1685
- key_obj = PyBytes_FromStringAndSize ( NULL , dklen );
1686
- if (key_obj == NULL ) {
1684
+ PyBytesWriter * writer = PyBytesWriter_Create ( dklen );
1685
+ if (writer == NULL ) {
1687
1686
goto end ;
1688
1687
}
1689
- key = PyBytes_AS_STRING (key_obj );
1690
1688
1691
1689
Py_BEGIN_ALLOW_THREADS
1692
1690
retval = PKCS5_PBKDF2_HMAC ((const char * )password -> buf , (int )password -> len ,
1693
1691
(const unsigned char * )salt -> buf , (int )salt -> len ,
1694
1692
iterations , digest , dklen ,
1695
- (unsigned char * )key );
1693
+ (unsigned char * )PyBytesWriter_GetData ( writer ) );
1696
1694
Py_END_ALLOW_THREADS
1697
1695
1698
1696
if (!retval ) {
1699
- Py_CLEAR ( key_obj );
1697
+ PyBytesWriter_Discard ( writer );
1700
1698
notify_ssl_error_occurred_in (Py_STRINGIFY (PKCS5_PBKDF2_HMAC ));
1701
1699
goto end ;
1702
1700
}
1701
+ key_obj = PyBytesWriter_Finish (writer );
1703
1702
1704
1703
end :
1705
1704
if (digest != NULL ) {
@@ -1799,7 +1798,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
1799
1798
(const char * )password -> buf , (size_t )password -> len ,
1800
1799
(const unsigned char * )salt -> buf , (size_t )salt -> len ,
1801
1800
(uint64_t )n , (uint64_t )r , (uint64_t )p , (uint64_t )maxmem ,
1802
- PyBytesWriter_GetData (writer ), (size_t )dklen
1801
+ ( unsigned char * ) PyBytesWriter_GetData (writer ), (size_t )dklen
1803
1802
);
1804
1803
Py_END_ALLOW_THREADS
1805
1804
0 commit comments