Skip to content

fixes #12094 -- added support for argon2id phc format #12855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025

Conversation

alex
Copy link
Member

@alex alex commented May 4, 2025

This was implemented using claude-code and then non-trivial manual cleanup. The prompt used was:

Please implement the feature requested in https://github.com/pyca/cryptography/issues/12094.

This means adding the following methods to the existing `Argon2id` class:

```
class Argon2id:
    def derive_phc_encoded(self, key_material: bytes) -> str: ...
    @classmethod
    def verify_phc_encoded(key_material: bytes, phc_encoded: str) -> None: ...
```

The specification can be found at https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md

You should plan to implement:

- These two methods (in Rust, on the existing class)
- The python stub file declarations for them
- Tests for these
- Documentation
- A changelog entry

Before you start to write code, do the required research and planning and present me with a detailed plan of what you will do.

The total cost was $2.64

@alex alex requested a review from Copilot May 4, 2025 22:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the PHC formatted encoding for Argon2id, implementing two new methods (derive_phc_encoded and verify_phc_encoded) in the Rust backend along with corresponding Python stubs, tests, and documentation updates.

  • New methods in Argon2id for generating and verifying PHC strings
  • Updated tests to validate proper formatting and error handling of PHC strings
  • Adjustments to dependency management and documentation (spelling wordlist)

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/hazmat/primitives/test_argon2.py Added tests for the new PHC encode/verify methods
src/rust/src/backend/kdf.rs Implemented new methods with parameter parsing
src/rust/Cargo.toml Added/upgraded base64 dependency
src/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi Added corresponding Python stub declarations
docs/spelling_wordlist.txt Updated wordlist with "PHC" entry
Files not reviewed (2)
  • CHANGELOG.rst: Language not supported
  • docs/hazmat/primitives/key-derivation-functions.rst: Language not supported
Comments suppressed due to low confidence (2)

tests/hazmat/primitives/test_argon2.py:175

  • [nitpick] The test asserts an exact string match for the PHC formatted output, which could be brittle if minor encoding details change. Consider validating key components (prefix, parameter segment, salt, hash) separately to allow for flexibility in the encoding format.
assert encoded == ( ... )

src/rust/src/backend/kdf.rs:379

  • [nitpick] Consider adding an inline comment explaining that the parameter order is enforced to adhere to the PHC specification, which would improve maintainability and clarity for future readers.
if !param_parts[0].starts_with("m=") || !param_parts[1].starts_with("t=") || !param_parts[2].starts_with("p=")

@reaperhulk
Copy link
Member

This generally looks fine, but can we add the test vector from the spec as one final sanity check? https://github.com/P-H-C/phc-string-format/blob/e8fbd333dcc9a8b0843fac6b33371cf157e91a48/phc-sf-spec.md

@reaperhulk reaperhulk enabled auto-merge (squash) May 6, 2025 21:40
@reaperhulk reaperhulk merged commit c93ee38 into pyca:main May 6, 2025
64 checks passed
@alex alex deleted the argon-phc branch May 6, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants