Skip to content

Fix Keccak unit tests and add pure Keccak known-answer tests#98

Open
omonien wants to merge 1 commit into
MHumm:developmentfrom
omonien:pr-fix-keccak-tests
Open

Fix Keccak unit tests and add pure Keccak known-answer tests#98
omonien wants to merge 1 commit into
MHumm:developmentfrom
omonien:pr-fix-keccak-tests

Conversation

@omonien

@omonien omonien commented Jul 23, 2026

Copy link
Copy Markdown

For Markus — theme: red-test cleanup (Cluster A, tests only)

No production hash implementation is changed. This PR only fixes incorrect / incomplete unit tests for Keccak vs SHA-3.

Problem

Several Keccak cases failed for the wrong reasons:

  1. Hand vectors for Keccak-224 were broken (wrong setup / early exit / wrong digests).
  2. CAVP Unicode expectations (MDuni) were trusted even after the test harness rewrites input for Keccak domain separation (SHA-3 padding vs pure Keccak). After rewrite, the file’s Unicode expected digest no longer matches.
  3. There was little coverage of pure Keccak (empty / abc) as opposed to SHA-3.

Fix

  • Drive SHA-3 CAVP examples through the existing domain fixup (AddLastByteForCodeTest)
  • For Keccak fixtures: recompute Unicode expected digests after domain rewrite
  • Replace broken Keccak-224 hand setup with a small correct set
  • Add pure Keccak empty/abc KATs (PyCryptodome / XKCP-style) for 224/256/384/512

Scope boundary

In this PR Not in this PR
Unit Tests/Tests/TestDECHashSHA3.pas only Source/DECHash.pas large-buffer Absorb (#94) — separate PR
Test correctness / KATs HashBenchmark demo

Risk

Low (tests only). If a pure Keccak KAT disagreed with your intended DEC domain rules, that would surface here — vectors are chosen to match widely used pure-Keccak digests.

Independence

Can merge independently of DUnitX and GCM. Works with classic DUnit as well (same shared test unit).

Test plan

  • Run hash SHA-3/Keccak tests under DUnit or DUnitX
  • Confirm former Keccak failures are gone; no new fails in this unit

Remove broken Keccak-224 hand vectors and the early exit in SetUp; drive
SHA3 CAVP examples through domain fixup via AddLastByteForCodeTest.
Recompute MDuni after domain rewrite for Keccak fixtures so Unicode
CalcString matches fixed-up input. Add pure Keccak empty/abc known-answer
tests (PyCryptodome) to cover non-SHA3 domain separation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant