Skip to content

Add HMAC-SHA512 midstate path, vanity PBKDF2 and GPU regression tests#7

Closed
arkadianet wants to merge 1 commit intomainfrom
codex/optimize-pbkdf2-and-hmac-sha512-performance
Closed

Add HMAC-SHA512 midstate path, vanity PBKDF2 and GPU regression tests#7
arkadianet wants to merge 1 commit intomainfrom
codex/optimize-pbkdf2-and-hmac-sha512-performance

Conversation

@arkadianet
Copy link
Owner

Motivation

  • Reduce repeated SHA-512 compression work in PBKDF2 by caching HMAC inner/outer midstates for common fixed-length messages.
  • Special-case the BIP39 vanity path (salt "mnemonic", 2048 iterations) to get a predictable, faster PBKDF2 path.
  • Lower per-work-item private memory by avoiding duplicate padded-key buffers and large temporaries on the hot loop.
  • Add GPU and Rust-level regression tests to ensure midstate and vanity paths match the legacy implementations.

Description

  • Introduced HmacSha512MidstateCtx and hmac_sha512_midstate_init() plus fixed-length finalizers hmac_sha512_msg12() and hmac_sha512_msg64() in kernels/hmac_sha512.cl to compute HMAC using cached midstates.
  • Added pbkdf2_sha512_vanity() in kernels/pbkdf2.cl and switched bip39_entropy_to_seed() in kernels/bip39.cl to call the vanity path, including a safety clamp on password_len.
  • Added GPU test kernels: hmac_sha512_midstate_test, hmac_sha512_midstate_msg12_test, and pbkdf2_vanity_test, and corresponding Rust unit tests test_hmac_sha512_midstate_matches_legacy, test_hmac_sha512_midstate_msg12_matches_legacy, and test_pbkdf2_vanity_matches_bip39 in src/kernel.rs to compare against legacy kernels.
  • Added small caller-side key hashing for long keys and private-buffer copying for tests to ensure deterministic inputs.

Testing

  • Ran cargo test --release as an automated check, but the build failed due to erg-vanity-crypto using the unstable Rust feature bigint_helper_methods on the current toolchain, preventing the test suite from completing.
  • The new GPU kernel tests and Rust unit tests were added and will run once the workspace is buildable with the appropriate toolchain or feature flags.
  • No GPU regression assertions were observed to run to completion in CI in this rollout because the build error blocked test execution.
  • Manual/bench validation of the expected performance and memory improvements is still expected after resolving the build toolchain issue and running the full test suite.

Codex Task

@coderabbitai
Copy link

coderabbitai bot commented Jan 3, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arkadianet arkadianet closed this Jan 3, 2026
@arkadianet arkadianet deleted the codex/optimize-pbkdf2-and-hmac-sha512-performance branch January 3, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant