#sha-256 #sha-2 #sha-512 #cryptography-hashing #hash

no-std hashes

Rust implementation of cryptographic hash function algorithms

10 releases

0.1.9 Jan 7, 2023
0.1.8 Jan 7, 2023

#1706 in Cryptography

Download history 238/week @ 2024-12-01 272/week @ 2024-12-08 416/week @ 2024-12-15 131/week @ 2024-12-22 50/week @ 2024-12-29 503/week @ 2025-01-05 343/week @ 2025-01-12 394/week @ 2025-01-19 321/week @ 2025-01-26 265/week @ 2025-02-02 395/week @ 2025-02-09 363/week @ 2025-02-16 548/week @ 2025-02-23 541/week @ 2025-03-02 597/week @ 2025-03-09 330/week @ 2025-03-16

2,029 downloads per month
Used in 2 crates

MIT/Apache

51KB
1K SLoC

Cryptographic Hash Functions in Rust

This is a Rust implementation of various cryptographic hash functions. The following algorithms are currently supported:

  • djb2

  • sdbm

  • MD5

  • SHA-1

  • SHA-2-224

  • SHA-2-256

  • SHA-2-384

  • SHA-2-512

  • SHA-3-224

  • SHA-3-256

  • SHA-3-384

  • SHA-3-512

Example

Here's an example of how to use the sha2::sha256 hash function:

use hashes::sha2::sha256::hash;

fn main() {
    let s = "abc";

    let digest = hash(s.as_bytes());

    assert_eq!(
        digest.into_bytes(),
        [
            0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae,
            0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61,
            0xf2, 0x00, 0x15, 0xad
        ]
    );
}

Enable "std" feature if you want to use Display, Debug of FromStr for the output of hash functions (i.e. for Digest struct).

License

This project is dual-licensed under the Apache License 2.0 and the MIT License. You may choose either license to use this software.

No runtime deps

Features