Skip to content

Expose PBKDF2#46

Merged
Not-Nik merged 7 commits into
mozilla:mainfrom
Not-Nik:pbkdf2
May 6, 2026
Merged

Expose PBKDF2#46
Not-Nik merged 7 commits into
mozilla:mainfrom
Not-Nik:pbkdf2

Conversation

@Not-Nik
Copy link
Copy Markdown
Collaborator

@Not-Nik Not-Nik commented May 5, 2026

Fixes #44

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

❌ Patch coverage is 91.26214% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@f829678). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/pbkdf2.rs 90.72% 1 Missing and 8 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #46   +/-   ##
=======================================
  Coverage        ?   68.89%           
=======================================
  Files           ?       26           
  Lines           ?     3244           
  Branches        ?     3244           
=======================================
  Hits            ?     2235           
  Misses          ?      806           
  Partials        ?      203           
Flag Coverage Δ
freebsd 68.89% <91.26%> (?)
linux 68.89% <91.26%> (?)
macos 68.89% <91.26%> (?)
windows 68.89% <91.26%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/pbkdf2.rs
Comment thread src/hmac.rs Outdated
Comment thread src/pbkdf2.rs Outdated
Comment thread src/pbkdf2.rs
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-structured addition that follows existing patterns (HKDF, HMAC). The FFI boundary is handled correctly — algid is manually destroyed and SymKey::from_ptr guards the key pointer. One resource-leak bug on an early-return path needs fixing before merge (see inline). Minor nits on naming and annotation consistency.

Good test coverage with RFC vectors; would benefit from exercising the SHA-384/SHA-512 code paths.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean addition that follows established codebase patterns (HMAC, HKDF). The FFI boundary is handled correctly for the happy path, and test coverage includes RFC 7914 known-answer vectors.

The second commit ("Claude fixes") addressed the #[must_use] annotation on hmac_alg_to_prf_oid. The resource leak on the algid early-return path (lines 51–52) from the prior review remains open and should be resolved before merge — the suggested reordering is straightforward.

Comment thread src/hmac.rs Outdated
@beurdouche
Copy link
Copy Markdown
Member

Keeping my approve so that you can make the suggested fixes and push.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-structured addition that follows the existing HKDF/HMAC patterns. The FFI boundary is handled correctly — algid is manually destroyed after use, and SymKey's Drop impl handles the derived key.

The three issues from the prior review (resource leak on algid early-return, missing #[must_use], RFC 6070→7914 test naming) are all resolved across the follow-up commits.

Two items from the prior review remain open and should be addressed before merge:

  1. hmac_alg_to_prf_oid visibility (existing thread) — pub leaks an FFI return type (SECOidTag::Type) into the crate's public API. The only consumer is pbkdf2::pbkdf2() within the crate, so pub(crate) is the correct visibility. This is consistent with the private hmac_alg_to_ckm helper.

  2. SHA-384/SHA-512 test coverage (existing thread) — all four tests exercise only HMAC_SHA2_256. At least one known-answer vector for SHA-384 or SHA-512 would verify the OID mapping end-to-end.

Comment thread src/pbkdf2.rs
Comment thread src/pbkdf2.rs
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissing empty pending review to allow new review with inline comments.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(clearing pending review)

Comment thread src/pbkdf2.rs
Comment thread src/pbkdf2.rs
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-structured PBKDF2 wrapper that follows the crate's established HKDF/HMAC patterns. FFI boundary is handled correctly — algid lifetime is properly managed (the resource-leak issue from the prior review is resolved), SymKey::from_ptr guards the key pointer, and SECOID_DestroyAlgorithmID runs unconditionally after PK11_PBEKeyGen.

Prior review items addressed in this revision: resource leak on algid early-return, #[must_use] on hmac_alg_to_prf_oid, pub(crate) visibility, RFC 6070→7914 test naming, and SHA-384/SHA-512 test coverage.

Blocking: The latest commit has a syntax error — missing } closing rfc_7914_vector_iter_2 — which prevents compilation (see inline).

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean PBKDF2 wrapper that follows the crate's established HKDF/HMAC patterns. FFI boundary is correctly managed — algid is allocated after all fallible setup, destroyed unconditionally after PK11_PBEKeyGen, and SymKey::from_ptr guards the key pointer. Test coverage now spans all three HMAC variants with known-answer vectors.

All blocking issues from prior reviews are resolved (resource leak on algid early-return, missing }, pub(crate) visibility, #[must_use], RFC naming, SHA-384/512 coverage).

One prior suggestion remains open: extracting hmac_alg_to_prf_oid(alg) to a local variable to clarify that passing the same OID for both cipherAlgTag and prfAlgTag in PK11_CreatePBEV2AlgorithmID is intentional (thread).

Comment thread src/pbkdf2.rs Outdated
Comment thread src/pbkdf2.rs
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean PBKDF2 wrapper that follows the crate's established HKDF/HMAC patterns well. FFI boundary is correctly managed: all fallible operations (Slot::internal, SECItemBorrowed::wrap) are hoisted before algid allocation, SECOID_DestroyAlgorithmID runs unconditionally after PK11_PBEKeyGen, and SymKey::from_ptr guards the key pointer. Test coverage spans all three HMAC variants with known-answer vectors (RFC 7914 §11 for SHA-256, standard vectors for SHA-384/SHA-512).

All blocking issues from prior reviews are resolved (resource leak on algid early-return, pub(crate) visibility, #[must_use], test naming, SHA-384/512 coverage, syntax error).

One minor suggestion remains open (see inline): extracting the PRF OID to a local variable to clarify the PK11_CreatePBEV2AlgorithmID parameter semantics.

@Not-Nik Not-Nik merged commit e6ef55e into mozilla:main May 6, 2026
44 checks passed
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.

Expose PBKDF2

3 participants