2121#endif
2222
2323#include "Python.h"
24+ #include "pycore_strhex.h" // _Py_strhex()
25+
2426#include "hashlib.h"
2527
2628/*[clinic input]
@@ -132,7 +134,7 @@ static PyObject *
132134MD5Type_digest_impl (MD5object * self )
133135/*[clinic end generated code: output=eb691dc4190a07ec input=bc0c4397c2994be6]*/
134136{
135- unsigned char digest [MD5_DIGESTSIZE ];
137+ uint8_t digest [MD5_DIGESTSIZE ];
136138 HASHLIB_ACQUIRE_LOCK (self );
137139 Hacl_Hash_MD5_digest (self -> hash_state , digest );
138140 HASHLIB_RELEASE_LOCK (self );
@@ -149,20 +151,11 @@ static PyObject *
149151MD5Type_hexdigest_impl (MD5object * self )
150152/*[clinic end generated code: output=17badced1f3ac932 input=b60b19de644798dd]*/
151153{
152- unsigned char digest [MD5_DIGESTSIZE ];
154+ uint8_t digest [MD5_DIGESTSIZE ];
153155 HASHLIB_ACQUIRE_LOCK (self );
154156 Hacl_Hash_MD5_digest (self -> hash_state , digest );
155157 HASHLIB_RELEASE_LOCK (self );
156-
157- const char * hexdigits = "0123456789abcdef" ;
158- char digest_hex [MD5_DIGESTSIZE * 2 ];
159- char * str = digest_hex ;
160- for (size_t i = 0 ; i < MD5_DIGESTSIZE ; i ++ ) {
161- unsigned char byte = digest [i ];
162- * str ++ = hexdigits [byte >> 4 ];
163- * str ++ = hexdigits [byte & 0x0f ];
164- }
165- return PyUnicode_FromStringAndSize (digest_hex , sizeof (digest_hex ));
158+ return _Py_strhex ((const char * )digest , MD5_DIGESTSIZE );
166159}
167160
168161static void
0 commit comments