Crates.io | md5hash |
lib.rs | md5hash |
version | 0.1.1 |
source | src |
created_at | 2023-06-10 19:37:52.535219 |
updated_at | 2023-06-27 20:21:13.256743 |
description | A no_std MD5 hash implementation in safe Rust |
homepage | |
repository | https://github.com/QrkenBananen/md5hash |
max_upload_size | |
id | 887043 |
size | 19,404 |
This crate provides no_std compatible MD5 hashing without dependencies, written in safe Rust.
The crate consists of a [MD5Hasher
] type which takes in data using the digest method and then hashes it using
the MD5 algorithm. Once all the data has been "digested" using the digest method the finish method returns a [MD5Digest
] type representing
the result of the hash.
A MD5Hasher instance can be created and digest can be called repeatedly for disjointed slices.
use md5hash::MD5Hasher;
let mut hasher = MD5Hasher::new();
hasher.digest(&"message");
hasher.digest(&" ");
hasher.digest(&"digest"); // f96b697d7cb7938d525a2f31aaf161d0
assert_eq!(hasher.finish().as_ref(), &[0xf9,0x6b,0x69,0x7d,0x7c,0xb7,0x93,0x8d,
0x52,0x5a,0x2f,0x31,0xaa,0xf1,0x61,0xd0]);
Or the hash function can be used as a convenience function to hash a single slice.
use md5hash::MD5Hasher;
assert_eq!(MD5Hasher::hash(&"message digest").as_ref(), // f96b697d7cb7938d525a2f31aaf161d0
&[0xf9,0x6b,0x69,0x7d,0x7c,0xb7,0x93,0x8d,
0x52,0x5a,0x2f,0x31,0xaa,0xf1,0x61,0xd0]);
MD5 is a broken hashing algorithm, and should not be used for anything that requires any kind of security. It is also not recommended to be used for new systems even if security is not a concern. Instead this hash should only be used for situations that requires specifically MD5, such as legacy systems.