#hash #md5 #streamable

md5-rs

A streamable MD5 implementation, using no_std

5 releases

Uses new Rust 2021

0.1.5 Aug 11, 2022
0.1.4 Mar 24, 2022
0.1.3 Mar 24, 2022
0.1.1 Mar 24, 2022
0.1.0 Mar 24, 2022

#380 in Cryptography

32 downloads per month

MIT license

10KB
218 lines

md5-rs

A simple MD5 implementation with a focus on buffered reading, and is completely no_std.

This shouldn't be used in any security-critical software, as MD5 is vulnerable.

Motivations

I was working on a web project and realized I have no way of getting a checksum of a big file without reading it all into memory (which in some cases crashes the page!). The Web Crypto API doesn't have a MD5 implementation, so I figured rather than re-implementing a SHA algorithm, I'd implement MD5.

As such, the API may be slightly odd since it is mainly focused on WebAssembly.

Usage

This isn't as straight forward as other MD5 libraries may be, given that it is no_std through and through.

use md5_rs::Context;

// get the hash
let mut ctx = Context::new();
ctx.read(b"Hello, world");
let digest = ctx.finish();

// get digest as string
let hash = digest.iter().map(|x| format!("{:02x}", x)).collect::<String>();
println!("{hash}"); // "bc6e6f16b8a077ef5fbc8d59d0b931b9"

No runtime deps