#const

nightly no-std sha3-const

const fn implementation of the SHA-3 family of hash and extendable-output functions

2 releases

0.1.1 Oct 12, 2022
0.1.0 May 23, 2022

#1194 in Cryptography

Download history 38/week @ 2024-07-14 1/week @ 2024-07-21 1/week @ 2024-07-28 2/week @ 2024-08-04 19/week @ 2024-08-11 4/week @ 2024-08-25 5/week @ 2024-09-01 45/week @ 2024-09-22 273/week @ 2024-09-29 73/week @ 2024-10-06 72/week @ 2024-10-13 1/week @ 2024-10-20 31/week @ 2024-10-27

178 downloads per month
Used in evm-coder

MIT/Apache

24KB
294 lines

sha3-const

Build status Crate Documentation

const fn implementation of the SHA-3 family of hash and extendable-output functions (inspired by sha2-const). This crate allows you to use use the Sha3 hash functions as constant expressions in rust. For all other usages, the sha3 crate includes more optimized implementations of these hash functions.

Based on the Keccak specification implementations.


lib.rs:

const fn implementation of the SHA-3 family of hash and extendable-output functions.

This crate allows you to use the SHA-3 hash and extendable-output functions as constant expressions in Rust. For all other usages, the sha3 crate includes more optimized implementations of these hash functions.

Examples

const PSEUDO_RANDOM_BYTES: [u8; 1000] = Shake256::new()
        .update(b"The quick brown fox ")
        .update(b"jumps over the lazy dog")
        .finalize();
#![feature(const_mut_refs)]
const ROUND_CONSTANTS: [u128; 8] = {
    let shake = Shake128::new()
        .update(b"The quick brown fox ")
        .update(b"jumps over the lazy dog");

    let mut reader = shake.finalize_xof();
    let mut output = [0; 8];

    let mut i = 0;
    while i < 8 {
        let mut buf = [0; 16];
        reader.read(&mut buf);
        output[i] = u128::from_be_bytes(buf);
        i += 1;
    }

    output
};

assert_eq!(
    [
        324498722242859095401832112442782838951,
        100470442341479765851591908475476895342,
        241049111671168257801898223573666863059,
        139197826094415251816510671569090212218,
        73371475849610774600276735485442220492,
        321031806373587100556524628628207173306,
        70553598458795679727810425741185559539,
        297273966300911440566694043047331846682,
    ],
    ROUND_CONSTANTS,
);

No runtime deps