+18
-7
lines changedFilter options
+18
-7
lines changed Original file line number Diff line number Diff line change
@@ -434,6 +434,15 @@ def test_case_md5_huge(self, size):
434
434
def test_case_md5_uintmax(self, size):
435
435
self.check('md5', b'A'*size, '28138d306ff1b8281f1a9067e1a1a2b3')
436
436
437
+
@unittest.skipIf(sys.maxsize < _4G - 1, 'test cannot run on 32-bit systems')
438
+
@bigmemtest(size=_4G - 1, memuse=1, dry_run=False)
439
+
def test_sha3_update_overflow(self, size):
440
+
"""Regression test for gh-98517 CVE-2022-37454."""
441
+
h = hashlib.sha3_224()
442
+
h.update(b'\x01')
443
+
h.update(b'\x01'*0xffff_ffff)
444
+
self.assertEqual(h.hexdigest(), '80762e8ce6700f114fec0f621fd97c4b9c00147fa052215294cceeed')
445
+
437
446
# use the three examples from Federal Information Processing Standards
438
447
# Publication 180-1, Secure Hash Standard, 1995 April 17
439
448
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
+
Port XKCP's fix for the buffer overflows in SHA-3 (CVE-2022-37454).
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dat
171
171
i = 0;
172
172
curData = data;
173
173
while(i < dataByteLen) {
174
-
if ((instance->byteIOIndex == 0) && (dataByteLen >= (i + rateInBytes))) {
174
+
if ((instance->byteIOIndex == 0) && (dataByteLen-i >= rateInBytes)) {
175
175
#ifdef SnP_FastLoop_Absorb
176
176
/* processing full blocks first */
177
177
@@ -199,10 +199,10 @@ int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dat
199
199
}
200
200
else {
201
201
/* normal lane: using the message queue */
202
-
203
-
partialBlock = (unsigned int)(dataByteLen - i);
204
-
if (partialBlock+instance->byteIOIndex > rateInBytes)
202
+
if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
205
203
partialBlock = rateInBytes-instance->byteIOIndex;
204
+
else
205
+
partialBlock = (unsigned int)(dataByteLen - i);
206
206
#ifdef KeccakReference
207
207
displayBytes(1, "Block to be absorbed (part)", curData, partialBlock);
208
208
#endif
@@ -281,7 +281,7 @@ int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByte
281
281
i = 0;
282
282
curData = data;
283
283
while(i < dataByteLen) {
284
-
if ((instance->byteIOIndex == rateInBytes) && (dataByteLen >= (i + rateInBytes))) {
284
+
if ((instance->byteIOIndex == rateInBytes) && (dataByteLen-i >= rateInBytes)) {
285
285
for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
286
286
SnP_Permute(instance->state);
287
287
SnP_ExtractBytes(instance->state, curData, 0, rateInBytes);
@@ -299,9 +299,10 @@ int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByte
299
299
SnP_Permute(instance->state);
300
300
instance->byteIOIndex = 0;
301
301
}
302
-
partialBlock = (unsigned int)(dataByteLen - i);
303
-
if (partialBlock+instance->byteIOIndex > rateInBytes)
302
+
if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
304
303
partialBlock = rateInBytes-instance->byteIOIndex;
304
+
else
305
+
partialBlock = (unsigned int)(dataByteLen - i);
305
306
i += partialBlock;
306
307
307
308
SnP_ExtractBytes(instance->state, curData, instance->byteIOIndex, partialBlock);
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4