Skip to content

Conversation

@wysiwys
Copy link
Contributor

@wysiwys wysiwys commented Sep 10, 2025

This pull request begins implementing a public Digest API with multiplexing (as part of #1039).

  • Oneshot API for all implementations (including Blake2s/Blake2b)
  • Consistent Hasher struct initialization via DigestIncrementalBase::new()
  • Reexport libcrux_traits::digest::Hasher structs in new libcrux-digest crate
    • Add crate documentation and README
  • Multiplexed Hash in libcrux-digest

@wysiwys wysiwys self-assigned this Sep 10, 2025
@wysiwys wysiwys changed the title Digest: Public API (prerequisites) Digest: Public API (draft) Sep 11, 2025
Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

I'm not sure what the usages are exactly because of the missing docs. We should have public APIs that can do something like

// oneshot, algorithm specific
let digest = Sha256::hash(b"input");

// oneshot, "multiplexed"
let digest = Digest::hash(Algorithm::Sha256, b"input");

// oneshot, "multiplexed" with caller provided memory
let mut digest = [0u8; 32];
Digest::hash(Algorithm::Blake2b, &mut digest, b"input");

// incremental
let mut hasher = Sha256::new();
hasher.update(b"input");
let digest = hasher.finalize();

// or with caller provided memory
hasher.finalize(&mut digest);

// Similar for the "multiplexed" version.

Without docs it's hard to tell if this is possible. But looking at the tests, this looks way more complex right now.

@@ -0,0 +1,3 @@
pub trait HashConsts {
const DIGEST_SIZE: usize;
Copy link
Member

Choose a reason for hiding this comment

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

Shall we add max input length here as well?

@@ -0,0 +1,104 @@
#[derive(Debug)]
Copy link
Member

Choose a reason for hiding this comment

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

Some doc comments would be nice 😊

}

impl<Algo> DigestMut<'_, Algo> {
pub fn algo(&self) -> &Algo {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe algorithm? algo sounds a little off.

Comment on lines +247 to +249
let algo = Blake2sHash::<RuntimeDigestLen>::default();
let digest_mut = DigestMut::new_for_algo(algo, &mut digest).unwrap();
algo.hash(digest_mut, b"this is a test").unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a lot of code for just calling a hash function.
I'd want to call something like Blake2sHash::hash(digest_mut, b"this is a test"). It's not clear why the extra two lines are necessary.

@github-actions
Copy link

This PR has been marked as stale due to a lack of activity for 60 days. If you believe this pull request is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 12, 2025
@franziskuskiefer
Copy link
Member

@wysiwys is this still something you work on or should it be closed?

@github-actions github-actions bot removed the stale label Nov 19, 2025
@github-actions
Copy link

This PR has been marked as stale due to a lack of activity for 60 days. If you believe this pull request is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

@github-actions github-actions bot added the stale label Jan 18, 2026
@jschneider-bensch jschneider-bensch added the waiting-on-author Status: This is awaiting some action from the author. label Jan 20, 2026
@jschneider-bensch
Copy link
Collaborator

@wysiwys Can you say what the current state is, here? Did we merge something for this already somewhere else?

@wysiwys
Copy link
Contributor Author

wysiwys commented Jan 20, 2026

This PR was an earlier draft to address issue #1039 for implementing the Digest trait, but that issue was closed after merging other PRs that implemented most of the functionality that this PR includes, including the libcrux-digest crate.

One thing that's implemented here that wasn't merged by another PR is providing an API in libcrux-digest that allows runtime selection of the hash algorithm to use (in multiplexed.rs). It could make sense to close this larger PR, and separately address the runtime selection of the hash algorithm, if needed.

@jschneider-bensch
Copy link
Collaborator

Thanks for the update! Yes, let's file an issue for runtime selection of digest algorithms and address it separately. 👍

@github-actions github-actions bot removed the stale label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-author Status: This is awaiting some action from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants