Page MenuHomePhabricator

[secp256k1] Change SHA256 byte counter from size_t to uint64_t
ClosedPublic

Authored by PiRK on Tue, Feb 10, 12:17.

Details

Summary

This avoids that the SHA256 implementation would produce wrong paddings
and thus wrong digests for messages of length >= 2^32 bytes on 32-bit
platforms.

This is not exploitable in any way since the SHA256 API is an internal
API and we never call it with that long messages.

Add test vector for very long SHA256 messages

The vector has been taken from https://www.di-mgt.com.au/sha_testvectors.html.
It can be independently verified using the following Python code.

h = hashlib.sha256()
for i in range(1_000_000):
    h.update(b'a')
print(h.hexdigest())

Add SHA256 bit counter tests

This is a backport of secp256k1#731

Test Plan

ninja check-secp256k1

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Tue, Feb 10, 12:17
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/secp256k1/src/hash_impl.h
157 ↗(On Diff #58245)

this took me way to long to understand...

This revision is now accepted and ready to land.Tue, Feb 10, 13:07