RustCrypto / hashes

Collection of cryptographic hash functions written in pure Rust
1.82k stars 247 forks source link

reuse the hasher after finalized? #429

Closed ibigbug closed 1 year ago

ibigbug commented 1 year ago

it seems the finalize() will consume the hasher:

Retrieve result and consume hasher instance.

https://docs.rs/md-5/latest/md5/trait.Digest.html#tymethod.finalize

how ever it doesn't reset the state.

how to reuse and write more data into the hasher after finalized()?

tarcieri commented 1 year ago

Use finalize_reset

ibigbug commented 1 year ago

i think i didn't make it clear - it's not about resetting the state. i.e. continue to write more data after finalize() and finalize() again with more data.

tarcieri commented 1 year ago

Then you want to Clone prior to finalization

burdges commented 1 year ago

Also, merlin was more designed for this sort of thing.

As an aside, rust maybe needs some replace_with method that makes reset methods unnecessary by ensuring zero copies: https://github.com/rust-lang/rfcs/pull/2884#issuecomment-1304576176

burdges commented 1 year ago

It appears https://docs.rs/replace_with/ provides equivalent functionality to the *reset methods.