md5hash

Crates.iomd5hash
lib.rsmd5hash
version0.1.1
sourcesrc
created_at2023-06-10 19:37:52.535219
updated_at2023-06-27 20:21:13.256743
descriptionA no_std MD5 hash implementation in safe Rust
homepage
repositoryhttps://github.com/QrkenBananen/md5hash
max_upload_size
id887043
size19,404
Jonas Hansen (QrkenBananen)

documentation

README

md5hash

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.

Examples

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]);

Security

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.

Commit count: 6

cargo fmt