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.

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.

2 participants