@@ -195,10 +195,9 @@ _sha3_sha3_224_digest_impl(SHA3object *self)
195
195
/*[clinic end generated code: output=fd531842e20b2d5b input=5b2a659536bbd248]*/
196
196
{
197
197
unsigned char digest [SHA3_MAX_DIGESTSIZE ];
198
- // The only potential error here is an API misuse, such as trying to specify
199
- // a user-provided length when using a non-Shake algorithm. We thus ignore
200
- // the return code.
201
- Hacl_Streaming_Keccak_finish (self -> hash_state , digest , 0 );
198
+ // This function errors out if the algorithm is Shake. Here, we know this
199
+ // not to be the case, and therefore do not perform error checking.
200
+ Hacl_Streaming_Keccak_finish (self -> hash_state , digest );
202
201
return PyBytes_FromStringAndSize ((const char * )digest ,
203
202
Hacl_Streaming_Keccak_hash_len (self -> hash_state ));
204
203
}
@@ -215,7 +214,7 @@ _sha3_sha3_224_hexdigest_impl(SHA3object *self)
215
214
/*[clinic end generated code: output=75ad03257906918d input=2d91bb6e0d114ee3]*/
216
215
{
217
216
unsigned char digest [SHA3_MAX_DIGESTSIZE ];
218
- Hacl_Streaming_Keccak_finish (self -> hash_state , digest , 0 );
217
+ Hacl_Streaming_Keccak_finish (self -> hash_state , digest );
219
218
return _Py_strhex ((const char * )digest ,
220
219
Hacl_Streaming_Keccak_hash_len (self -> hash_state ));
221
220
}
@@ -397,8 +396,12 @@ _SHAKE_digest(SHA3object *self, unsigned long digestlen, int hex)
397
396
return PyErr_NoMemory ();
398
397
}
399
398
400
- /* Get the raw (binary) digest value */
401
- Hacl_Streaming_Keccak_finish (self -> hash_state , digest , digestlen );
399
+ /* Get the raw (binary) digest value. The HACL functions errors out if:
400
+ * - the algorith is not shake -- not the case here
401
+ * - the output length is zero -- we follow the existing behavior and return
402
+ * an empty digest, without raising an error */
403
+ if (digestlen > 0 )
404
+ Hacl_Streaming_Keccak_squeeze (self -> hash_state , digest , digestlen );
402
405
if (hex ) {
403
406
result = _Py_strhex ((const char * )digest , digestlen );
404
407
} else {
0 commit comments