MCPcopy Index your code
hub / github.com/RustCrypto/hashes

github.com/RustCrypto/hashes @ripemd320-v0.9.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release ripemd320-v0.9.0 ↗ · + Follow
334 symbols 613 edges 119 files 62 documented · 19% 34 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RustCrypto: hashes

Collection of cryptographic hash functions written in pure Rust.

All algorithms reside in the separate crates and implemented using traits from digest crate. Additionally all crates do not require the standard library (i.e. no_std capable) and can be easily used for bare-metal or WebAssembly programming.

Supported algorithms

Note: For new applications, or where compatibility with other existing standards is not a primary concern, we strongly recommend to use either BLAKE2, SHA-2 or SHA-3.

Name Algorithm Crates.io Documentation Build Status Security
blake2 BLAKE2 crates.io Documentation build :green_heart:
gost94 GOST94 (GOST R 34.11-94) crates.io Documentation build :yellow_heart:
groestl Grøstl (Groestl) crates.io Documentation build :green_heart:
k12 KangarooTwelve crates.io Documentation build :green_heart:
md2 MD2 crates.io Documentation build :broken_heart:
md4 MD4 crates.io Documentation build :broken_heart:
md-5 :exclamation: MD5 crates.io Documentation build :broken_heart:
ripemd160 RIPEMD-160 crates.io Documentation build :green_heart:
ripemd320 RIPEMD-320 crates.io Documentation build :green_heart:*
sha-1 :exclamation: SHA-1 crates.io Documentation build :broken_heart:
sha2 SHA-2 crates.io Documentation build :green_heart:
sha3 SHA-3 (Keccak) crates.io Documentation build :green_heart:
shabal SHABAL crates.io Documentation build :green_heart:
streebog Streebog (GOST R 34.11-2012) crates.io Documentation build :yellow_heart:
whirlpool Whirlpool crates.io Documentation build :green_heart:

NOTE: the BLAKE3 crate implements the digest (and crypto-mac) traits used by the rest of the hashes in this repository, but is maintained by the BLAKE3 team.

* RIPEMD-320 provides only the same security as RIPEMD-160

Crate names

Whenever possible crates are published under the the same name as the crate folder. Owners of md5 and sha1 crates declined (1, 2) to participate in this project. This is why crates marked by :exclamation: are published under md-5 and sha-1 names respectively.

Security Level Legend

The following describes the security level ratings associated with each hash function (i.e. algorithms, not the specific implementation):

Heart Description
:green_heart: No known successful attacks
:yellow_heart: Theoretical break: security lower than claimed
:broken_heart: Attack demonstrated in practice: avoid if at all possible

See the Security page on Wikipedia for more information.

Minimum Supported Rust Version (MSRV)

All crates in this repository support Rust 1.21 or higher. In future minimally supported version of Rust can be changed, but it will be done with a minor version bump.

Usage

Let us demonstrate how to use crates in this repository using BLAKE2b as an example.

First add blake2 crate to your Cargo.toml:

[dependencies]
blake2 = "0.8"

Note that crates in this repository have an enabled by default std feature. So if you plan to use the crate in no_std enviroments, don't forget to disable it:

[dependencies]
blake2 = { version="0.8", default-features = false }

blake2 and other crates re-export digest crate and Digest trait for convenience, so you don't have to add digest crate as an explicit dependency.

Now you can write the following code:

use blake2::{Blake2b, Digest};

let mut hasher = Blake2b::new();
let data = b"Hello world!";
hasher.input(data);
// `input` can be called repeatedly and is generic over `AsRef<[u8]>`
hasher.input("String data");
// Note that calling `result()` consumes hasher
let hash = hasher.result();
println!("Result: {:x}", hash);

In this example hash has type GenericArray<u8, U64>, which is a generic alternative to [u8; 64].

Alternatively you can use chained approach, which is equivalent to the previous example:

let hash = Blake2b::new()
    .chain(b"Hello world!")
    .chain("String data")
    .result();
println!("Result: {:x}", hash);

If the whole message is available you also can use convinience digest method:

let hash = Blake2b::digest(b"my message");
println!("Result: {:x}", hash);

Hashing Readable objects

If you want to hash data from Read trait (e.g. from file) you can rely on implementation of Write trait (requires enabled-by-default std feature):

use blake2::{Blake2b, Digest};
use std::{fs, io};

let mut file = fs::File::open(&path)?;
let mut hasher = Blake2b::new();
let n = io::copy(&mut file, &mut hasher)?;
let hash = hasher.result();
println!("Path: {}", path);
println!("Bytes processed: {}", n);
println!("Hash value: {:x}", hash);

Hash-based Message Authentication Code (HMAC)

If you want to calculate Hash-based Message Authentication Code (HMAC), you can use generic implementation from hmac crate, which is a part of the RustCrypto/MACs repository.

Generic code

You can write generic code over Digest (or other traits from digest crate) trait which will work over different hash functions:

use digest::Digest;

// Toy example, do not use it in practice!
// Instead use crates from: https://github.com/RustCrypto/password-hashing
fn hash_password<D: Digest>(password: &str, salt: &str, output: &mut [u8]) {
    let mut hasher = D::new();
    hasher.input(password.as_bytes());
    hasher.input(b"$");
    hasher.input(salt.as_bytes());
    output.copy_from_slice(hasher.result().as_slice())
}

use blake2::Blake2b;
use sha2::Sha256;

hash_password::<Blake2b>("my_password", "abcd", &mut buf);
hash_password::<Sha256>("my_password", "abcd", &mut buf);

If you want to use hash functions with trait objects, use digest::DynDigest trait.

License

All crates licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Safe (Interface)
(no doc) [13 implementers]
blake2/src/as_bytes.rs
AsBytes (Interface)
(no doc) [1 implementers]
blake2/src/as_bytes.rs
Vector4 (Interface)
(no doc)
blake2/src/simd.rs

Core symbols most depended-on inside this repo

perm_elt
called by 48
shabal/src/shabal.rs
finalize
called by 18
groestl/src/groestl.rs
op_f
called by 16
md5/src/utils.rs
op_g
called by 16
md5/src/utils.rs
op_h
called by 16
md5/src/utils.rs
op_i
called by 16
md5/src/utils.rs
read
called by 10
k12/src/lib.rs
a
called by 9
gost94/src/gost94.rs

Shape

Function 169
Method 125
Class 37
Interface 3

Languages

Rust100%

Modules by API surface

shabal/src/shabal.rs27 symbols
groestl/src/state.rs19 symbols
gost94/src/gost94.rs19 symbols
md4/src/lib.rs14 symbols
sha2/src/sha512.rs13 symbols
sha2/src/sha256_utils.rs13 symbols
sha1/src/utils.rs13 symbols
streebog/src/streebog.rs11 symbols
sha2/src/sha256.rs11 symbols
k12/src/lib.rs11 symbols
whirlpool/src/lib.rs8 symbols
sha2/src/sha512_utils.rs8 symbols

For agents

$ claude mcp add hashes \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact