diff options
| author | eunhhu <[email protected]> | 2026-10-13 05:08:06 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-13 05:08:06 +0100 |
| commit | 41a2e5c65dc92a0c47212efcb7f5dfef8443f9b2 (patch) | |
| tree | 5c3354e41a5f15b253d333de24dd1bae4037c77b /tests | |
| parent | 5a44af0308017f4e7b54a8ff6ccdc797b5d94015 (diff) | |
| download | pure-41a2e5c65dc92a0c47212efcb7f5dfef8443f9b2.tar.gz pure-41a2e5c65dc92a0c47212efcb7f5dfef8443f9b2.zip | |
Research 140, 027's stage 1 measured: SHA-256 written in aup (its examples/sha256.aup) right for FIPS 180-2's examples and 138 more messages on every path, in make check against hashlib; 52 lines against Python's 28 (the bar missed: no formatting, no bytes joined or sliced, no lists as values, moved into stage 2), 176 times C's time and 0.43 of plain Python's (1,591 ns a byte; a block's 19,129 instructions, 39% of them the inlined fn's literals not folded); 044's check, time.c against the same algorithm in C (digests compared first) and the Python reference
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/check.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/check.py b/tests/check.py index 91ac114..eef4ae9 100644 --- a/tests/check.py +++ b/tests/check.py @@ -1841,6 +1841,24 @@ def module_assumptions(aup, pure, work): assert outputs[name] == outputs['batches'], ('view', name, next((a, b) for a, b in zip(outputs[name].splitlines(), outputs['batches'].splitlines()) if a != b)) faults = [json.loads(line)['fault'] for line in outputs['batches'].splitlines() if line.startswith('{"states"')] assert 'none' in faults and 'work' in faults, faults + # SHA-256 written in aup (its examples/sha256.aup, docs/design/027's stage 1: bytes by position, bit operations, lists + # of i64): FIPS 180-2's examples and messages of every length up to two blocks, against hashlib, on every path. + import hashlib + import random + program = work / 'sha256.pmod' + compile_module(aup, EDITOR.parent / 'sha256.aup', program) + chooser = random.Random(140) + messages = [b'abc', b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', + b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu'] + messages += [bytes(chooser.randrange(256) for _ in range(n)) for n in list(range(130)) + [1000, 4096]] + given = ''.join(f"message hash {m.hex() or '-'}\n" for m in messages) + outputs = {name: subprocess.run([str(pure / 'build/pure-run'), str(program)], input=given, capture_output=True, text=True, + timeout=120, env=dict(os.environ, **env)).stdout + for name, env in (('batches', {'PURE_JIT': '0'}), ('rounds', {'PURE_JIT': '0', 'PURE_BATCH': '0'}), ('all', {'PURE_JIT': 'all'}))} + for name in ('rounds', 'all'): + assert outputs[name] == outputs['batches'], ('sha256', name) + digests = [json.loads(line)['states']['digest'] for line in outputs['batches'].splitlines()] + assert digests == [hashlib.sha256(m).hexdigest() for m in messages], 'sha256' return len(runs) |
