-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Those tests verify that the SHA256 bit counter wraps correctly at bit lengths 20 to 34. This wide range aims at being independent of the implementation of the counter and it catches multiple natural 32-bit overflows (e.g., counting bits, counting bytes, counting blocks, ...). The test vectors have been generated using cloudtools/sha256@e0645d1 and the following Python script ``` from sha256 import sha256 from copy import copy def midstate_c_definition(hasher): ret = ' {{UINT32_C(0x' + hasher.state[0].hex('_', 4).replace('_', '), UINT32_C(0x') + ')},\n' ret += ' {0x00}, UINT64_C(' + str(hasher.state[1]) + ')}' return ret def output_c_literal(hasher): return '{0x' + hasher.digest().hex('_').replace('_', ', 0x') + '}' MESSAGE = b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno' ITER_BOUNDARIES = [(2**b)//len(MESSAGE) - 1 for b in range(20, 34)] midstates = [] digests = [] hasher = sha256() for i in range(ITER_BOUNDARIES[-1] + 1): if i in ITER_BOUNDARIES: midstates.append(midstate_c_definition(hasher)) hasher_copy = copy(hasher) hasher_copy.update(MESSAGE) digests.append(output_c_literal(hasher_copy)) hasher.update(MESSAGE) for x in midstates: print(x + ',') for x in digests: print(x + ',') ```
- Loading branch information
1 parent
03bd12f
commit 768b850
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters