crypto-hash
crypto-hash copied to clipboard
Calling hasher.write_all() after hasher.finish() causes panic on Windows
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.