SHA-224 on x86-64, x86, AArch64 and ARMv7: vg_sha224_init and the Rust API - #454
Merged
Merged
Conversation
…ance SHA224ShortMsg.rsp, SHA224LongMsg.rsp and SHA224Monte.rsp, byte for byte from the same shabytetestvectors.zip as the other SHA vectors (same SHA-256), in a directory and source file of their own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
…HA source They come from the same download, so they belong to its source file rather than a second one with the same URL and hash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
… value FIPS 180-4's SHA-224 is SHA-256 from another initial hash value (§5.3.2), truncated to 28 bytes (§6.3). As for the SHA-512 family, it shares the streaming state and vg_sha256_update/vg_sha256_finalize, and only needs an init of its own: * Spec/Sha256.lean: H0_224; finalHash iv (the 32-byte H⁽ᴺ⁾ from iv), with hash := finalHash H0 and sha224 := (finalHash H0_224 ·).take 28; ReprFrom iv, with Repr := ReprFrom H0 (so HMAC and PBKDF2's contracts, which use Repr and hash, are unchanged). * Spec/Sha256/Contract.lean: updateContract and finalizeContract hold for a state hashed from any initial hash value (finalize writes finalHash iv msg, which is hash msg for H0); init224Contract and init224Api for vg_sha224_init. The existing implementations are unchanged: their update and finalize are the generic Merkle-Damgard code, whose proofs already hold for any initial hash value, so the per-target contracts quantify over it too and the few callers that relied on H0 instantiate it. docs/algorithms/sha224.toml adds the row (spec landed, no architecture yet). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
…/gifted-cannon-gdzq6w
…t API vg_sha224_init stores SHA-224's initial hash value, then SHA-256's update and finalize (whose contracts hold for any initial hash value) do the rest, with every one of their implementations (SHA-NI and AVX2 on x86-64, the SHA2 extension on AArch64). * Impl: each target's init is now initWith iv, with init := initWith H0 (the emitted vg_sha256_init is unchanged) and init224 := initWith H0_224. * Proof: each target's init proof holds for any iv; the checks the kernel can only run on literal code (the taint analysis, and on x86-64 that it never loads MXCSR) are done for each of the two instances. The per-target init contracts take iv. * Artifacts/Sha224/<Target>.lean registers vg_sha224_init from Spec.Sha256.init224Api. * hashes::sha224::Sha224, over streaming_hash! with its own backend enum (the same variants as SHA-256's); unit tests, the CAVP short, long and Monte Carlo vectors, a Lean known-answer test of the spec, and a benchmark against OpenSSL. README table regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
Member
Author
|
Two CI failures on 43c4fc2 are not from this PR: Both died in setup, before any build or test ran. An armv7l container job in the unrelated #453 failed at the same time. I don't know of a fix yet; it is in the runner image's preinstalled toolchain, not in this repository. I'll re-run the failed jobs once when the run finishes. Generated by Claude Code |
…-256 streaming glue Main's x86 SHA-256 streaming proofs moved to Proof/Sha256/X86/Stream/Variant.lean (for any compression backend); its update_of/finalize_of now pass iv through instead of H0, as the other targets' do. src/asm/x86/sha256.rs regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
src/asm/x86/sha256.rs regenerated (main's #460 reworked the x86 SHA-256 artifacts; vg_sha224_init is re-emitted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third of the SHA-224 PRs: the implementation. The vectors (#446) and the spec (#452) are merged, and main is merged into this branch. It changes no files under
Spec/orTCB/.SHA-224 only needs an
initof its own.vg_sha224_initstores SHA-224's initial hash value, and SHA-256'supdateandfinalizedo the rest (as of #452, their contracts hold for any initial hash value). Every existing implementation of those is reused: SHA-NI and AVX2 on x86-64, and the SHA2 extension on AArch64.Lean
initbecomesinitWith iv, withinit := initWith H0andinit224 := initWith H0_224. The emittedvg_sha256_initis byte-identical; the only change tosrc/asm/is the newvg_sha224_init, one per target.initproof now holds for anyiv.setWidth 32 (setWidth 64 x) = x); on the other targets the proof was already written overword x off.iv.Artifacts/Sha224/{X86_64,X86,AArch64,Arm}.lean, each made fromSpec.Sha256.init224Api.VerifiedGarbageTest/Sha224.leanchecksSpec.Sha256.sha224against two of the CAVP short-message vectors at build time, like the SHA-256 test. I checked that it fails if one word ofH0_224is wrong.Rust
hashes::sha224::Sha224: a new module with its own#[cfg], built withstreaming_hash!and its ownSha224Backend.selecttest checks, for every feature set, that it picks the same implementation asSha256Backend(matching exhaustively).HashFunction.tests/cavp/sha224.rs: all 65 short and 64 long messages, plus the Monte Carlo test.bench/benches/primitives/sha224.rs: compared against OpenSSL's SHA-224;USESissha224andsha256.Checks run locally (after merging main)
lake build(5648 jobs) andlake env lean --run Emit.lean --checkci/check_lean_imports.py,check_lean_speed.py,check_vectors.py,check_arch_gates.py,check_variants.py,check_mcdt.py,algorithms_table.py --checkcargo fmt --checkandcargo clippy --all-targets -- -D warnings, on x86-64 and for the i686, aarch64 and armv7 targetscargo teston x86-64. Before this merge I also ran it withVG_CPU_FEATURES=avx,avx2,bmi1,bmi2and withVG_CPU_FEATURES=none; after it, the full suite and the SHA-224 vectors pass.cargo check --benchesinbench/(before this merge)I couldn't run the Rust tests on the other architectures locally; CI covers them.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HDRg9k22FbCYq3TnciKvwG