@@ -406,11 +406,10 @@ SHA256Type_update_impl(SHA256object *self, PyObject *obj)
406406{
407407 Py_buffer buf ;
408408 GET_BUFFER_VIEW_OR_ERROUT (obj , & buf );
409- Py_BEGIN_ALLOW_THREADS
410- HASHLIB_ACQUIRE_LOCK (self );
411- _hacl_sha2_state_update_256 (self -> state , buf .buf , buf .len );
412- HASHLIB_RELEASE_LOCK (self );
413- Py_END_ALLOW_THREADS
409+ HASHLIB_EXTERNAL_INSTRUCTIONS_WITH_MUTEX (
410+ self , buf .len ,
411+ _hacl_sha2_state_update_256 (self -> state , buf .buf , buf .len )
412+ )
414413 PyBuffer_Release (& buf );
415414 Py_RETURN_NONE ;
416415}
@@ -430,11 +429,10 @@ SHA512Type_update_impl(SHA512object *self, PyObject *obj)
430429{
431430 Py_buffer buf ;
432431 GET_BUFFER_VIEW_OR_ERROUT (obj , & buf );
433- Py_BEGIN_ALLOW_THREADS
434- HASHLIB_ACQUIRE_LOCK (self );
435- _hacl_sha2_state_update_512 (self -> state , buf .buf , buf .len );
436- HASHLIB_RELEASE_LOCK (self );
437- Py_END_ALLOW_THREADS
432+ HASHLIB_EXTERNAL_INSTRUCTIONS_WITH_MUTEX (
433+ self , buf .len ,
434+ _hacl_sha2_state_update_512 (self -> state , buf .buf , buf .len )
435+ )
438436 PyBuffer_Release (& buf );
439437 Py_RETURN_NONE ;
440438}
@@ -616,9 +614,10 @@ _sha2_sha256_impl(PyObject *module, PyObject *data, int usedforsecurity,
616614 if (string ) {
617615 /* Do not use self->mutex here as this is the constructor
618616 * where it is not yet possible to have concurrent access. */
619- Py_BEGIN_ALLOW_THREADS
620- _hacl_sha2_state_update_256 (new -> state , buf .buf , buf .len );
621- Py_END_ALLOW_THREADS
617+ HASHLIB_EXTERNAL_INSTRUCTIONS (
618+ buf .len ,
619+ _hacl_sha2_state_update_256 (new -> state , buf .buf , buf .len )
620+ )
622621 PyBuffer_Release (& buf );
623622 }
624623
@@ -673,9 +672,10 @@ _sha2_sha224_impl(PyObject *module, PyObject *data, int usedforsecurity,
673672 if (string ) {
674673 /* Do not use self->mutex here as this is the constructor
675674 * where it is not yet possible to have concurrent access. */
676- Py_BEGIN_ALLOW_THREADS
677- _hacl_sha2_state_update_256 (new -> state , buf .buf , buf .len );
678- Py_END_ALLOW_THREADS
675+ HASHLIB_EXTERNAL_INSTRUCTIONS (
676+ buf .len ,
677+ _hacl_sha2_state_update_256 (new -> state , buf .buf , buf .len )
678+ )
679679 PyBuffer_Release (& buf );
680680 }
681681
@@ -731,9 +731,10 @@ _sha2_sha512_impl(PyObject *module, PyObject *data, int usedforsecurity,
731731 if (string ) {
732732 /* Do not use self->mutex here as this is the constructor
733733 * where it is not yet possible to have concurrent access. */
734- Py_BEGIN_ALLOW_THREADS
735- _hacl_sha2_state_update_512 (new -> state , buf .buf , buf .len );
736- Py_END_ALLOW_THREADS
734+ HASHLIB_EXTERNAL_INSTRUCTIONS (
735+ buf .len ,
736+ _hacl_sha2_state_update_512 (new -> state , buf .buf , buf .len )
737+ )
737738 PyBuffer_Release (& buf );
738739 }
739740
@@ -789,9 +790,10 @@ _sha2_sha384_impl(PyObject *module, PyObject *data, int usedforsecurity,
789790 if (string ) {
790791 /* Do not use self->mutex here as this is the constructor
791792 * where it is not yet possible to have concurrent access. */
792- Py_BEGIN_ALLOW_THREADS
793- _hacl_sha2_state_update_512 (new -> state , buf .buf , buf .len );
794- Py_END_ALLOW_THREADS
793+ HASHLIB_EXTERNAL_INSTRUCTIONS (
794+ buf .len ,
795+ _hacl_sha2_state_update_512 (new -> state , buf .buf , buf .len )
796+ )
795797 PyBuffer_Release (& buf );
796798 }
797799
0 commit comments