114
114
#endif
115
115
116
116
#define SHA3_MAX_DIGESTSIZE 64 /* 64 Bytes (512 Bits) for 224 to 512 */
117
+ #define SHA3_LANESIZE 96 /* ExtractLane needs an extra 96 bytes */
117
118
#define SHA3_state Keccak_HashInstance
118
119
#define SHA3_init Keccak_HashInitialize
119
120
#define SHA3_process Keccak_HashUpdate
@@ -310,7 +311,7 @@ static PyObject *
310
311
_sha3_sha3_224_digest_impl (SHA3object * self )
311
312
/*[clinic end generated code: output=fd531842e20b2d5b input=a5807917d219b30e]*/
312
313
{
313
- unsigned char digest [SHA3_MAX_DIGESTSIZE ];
314
+ unsigned char digest [SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE ];
314
315
SHA3_state temp ;
315
316
HashReturn res ;
316
317
@@ -337,7 +338,7 @@ static PyObject *
337
338
_sha3_sha3_224_hexdigest_impl (SHA3object * self )
338
339
/*[clinic end generated code: output=75ad03257906918d input=2d91bb6e0d114ee3]*/
339
340
{
340
- unsigned char digest [SHA3_MAX_DIGESTSIZE ];
341
+ unsigned char digest [SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE ];
341
342
SHA3_state temp ;
342
343
HashReturn res ;
343
344
@@ -601,7 +602,12 @@ _SHAKE_digest(SHA3object *self, unsigned long digestlen, int hex)
601
602
int res ;
602
603
PyObject * result = NULL ;
603
604
604
- if ((digest = (unsigned char * )PyMem_Malloc (digestlen )) == NULL ) {
605
+ /* ExtractLane needs at least SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE and
606
+ * SHA3_LANESIZE extra space.
607
+ */
608
+ digest = (unsigned char * )PyMem_Malloc (SHA3_LANESIZE +
609
+ ((digestlen > SHA3_MAX_DIGESTSIZE ) ? digestlen : SHA3_MAX_DIGESTSIZE ));
610
+ if (digest == NULL ) {
605
611
return PyErr_NoMemory ();
606
612
}
607
613
@@ -708,7 +714,9 @@ PyInit__sha3(void)
708
714
{
709
715
PyObject * m = NULL ;
710
716
711
- m = PyModule_Create (& _SHA3module );
717
+ if ((m = PyModule_Create (& _SHA3module )) == NULL ) {
718
+ return NULL ;
719
+ }
712
720
713
721
#define init_sha3type (name , type ) \
714
722
do { \
0 commit comments