Skip to content
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

Calling hasher.write_all() after hasher.finish() causes panic on Windows #25

Open
Marcondiro opened this issue Dec 9, 2022 · 0 comments

Comments

@Marcondiro
Copy link

Hello, on Windows a call to write_all after finish causes panic.

Example:

use crypto_hash::{Algorithm, Hasher};
use std::io::Write;

fn main() {
    let mut hasher = Hasher::new(Algorithm::MD5);

    let message1 = b"Hello";
    hasher.write_all(message1).unwrap();
    let _hash1 = hasher.finish();

    let message2 = b"world!";
    hasher.write_all(message2).unwrap();
    let _hash2 = hasher.finish();
}

This is caused by the misusage of the Windows CryptoAPI.
As stated here in the Microsoft documentation:

  • The hash value can be retrieved by using CryptGetHashParam
  • [...]

After one of the functions from this list has been called, CryptHashData and CryptHashSessionKey cannot be called.

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

No branches or pull requests

1 participant