Skip to content

Commit c71ec8a

Browse files
committed
sha3: let's keep it simple and always allocate enough extra space for uint64_t[20].
1 parent c49a516 commit c71ec8a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Modules/_sha3/sha3module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
#endif
115115

116116
#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+
#define SHA3_LANESIZE (20 * 8) /* ExtractLane needs max uint64_t[20] extra. */
118118
#define SHA3_state Keccak_HashInstance
119119
#define SHA3_init Keccak_HashInitialize
120120
#define SHA3_process Keccak_HashUpdate
@@ -605,8 +605,7 @@ _SHAKE_digest(SHA3object *self, unsigned long digestlen, int hex)
605605
/* ExtractLane needs at least SHA3_MAX_DIGESTSIZE + SHA3_LANESIZE and
606606
* SHA3_LANESIZE extra space.
607607
*/
608-
digest = (unsigned char*)PyMem_Malloc(SHA3_LANESIZE +
609-
((digestlen > SHA3_MAX_DIGESTSIZE) ? digestlen : SHA3_MAX_DIGESTSIZE));
608+
digest = (unsigned char*)PyMem_Malloc(digestlen + SHA3_LANESIZE);
610609
if (digest == NULL) {
611610
return PyErr_NoMemory();
612611
}

0 commit comments

Comments
 (0)