A small, no-std hashing / digest library supporting many usefull algorithms.
Find a file
2026-07-04 02:40:35 +02:00
macros Add clippy linting; fix potential unsound transmute 2026-07-04 00:49:08 +02:00
src md5: fix panic in process_chunk 2026-07-04 02:36:26 +02:00
.gitignore Fix repo in preparation to cargo publishing 2026-07-02 21:04:49 +02:00
Cargo.lock Bump version to 0.0.2 2026-07-04 02:40:35 +02:00
Cargo.toml Bump version to 0.0.2 2026-07-04 02:40:35 +02:00
LICENSE Initial commit; release alpha 0.0.1 2026-07-02 21:01:44 +02:00
readme.md Initial commit; release alpha 0.0.1 2026-07-02 21:01:44 +02:00

ninox.rs-digest

A small, no-std hashing / digest library supporting many usefull algorithms.

License

This project is licensed under AGPL-3.0-only. For more informations see the LICENSE file inside the repository here, or alternative online under https://www.gnu.org/licenses/.

Usage

The library uses an central Digest trait that all algorithms must implement. It's designed with streamability in mind, so you can update the value as many times as you want and even take an "snapshot" of the digest instead of consuming it outright if you so choose.

use ninox_digest::MD5;

let digest1 = MD5::default()
    .update("hello ".as_bytes()) // with .update you can update the digest;
    .update("world".as_bytes())  //   algorithms even support 1-byte updates!
    .finalize();  // Finalize the digest, consuming the MD5 struct

let mut hasher = MD5::default();
hasher.update("hello world".as_bytes());

// Also supports taking the hash at any time and continuing!
let mut buf = [0; MD5::LENGTH];
let digest2 = hasher.digest(&mut buf).unwrap();
hasher.update("!".as_bytes());

assert_eq!(digest1, digest2);

The algorithms itself are feature-gated and need to be activated seperately. Supported algorithms are:

  • crc32
  • md5

Encodings

The crate supports additionaly some features, that help with formatting / encoding the hashes:

  • hexencode: Allows usage of hexdigest and hexfinalize; results in an hexadecimal string representation of the produced hash.

Zeroing

By default, the zeroize feature is active; it allows algorithms to zero themself on drop, preventing that someone could read the hash afterwards, if they know the memory location. It is advised to keep this behaviour, unless having a VERY good reason to alter / disable it.

Roadmap

This library will evolve over time; in particular, more algorithms will be added:

  • sha*
  • md4,md6 (lowest priority)

Other areas to work on include:

  • adding convienience methods for working with Iterator<Item = u8> as a update source
  • implementing core::io::Write
  • re-designing the Digest trait (or adding a new one) to make it dyn-compatible, or atleast less redundant...
  • SIMD?

Stability

The crate is currently considered to be UNSTABLE. While the stability of the code itself is considered to be stable to be used in other applications (as in all agorithms are verified to produce the correct results), the crate's interface and the Digest trait are currently NOT.