#sha-3 #const #keccak #crypto

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

#1355 in Cryptography

Download history 1/week @ 2023-12-29 33/week @ 2024-01-05 13/week @ 2024-01-12 69/week @ 2024-02-02 179/week @ 2024-02-09 202/week @ 2024-02-16 179/week @ 2024-02-23 17/week @ 2024-03-01 21/week @ 2024-03-08 13/week @ 2024-03-15 39/week @ 2024-03-22 458/week @ 2024-03-29 11/week @ 2024-04-05 1/week @ 2024-04-12

514 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