#keccak #sha-3 #hash #kangaroo-twelve #crypto

no-std tiny-keccak

An implementation of Keccak derived functions

28 releases (stable)

2.0.2 Apr 1, 2020
2.0.1 Nov 11, 2019
1.5.0 Jun 25, 2019
1.4.2 May 20, 2018
0.3.0 Nov 27, 2015

#25 in Cryptography

Download history 710508/week @ 2024-08-05 761105/week @ 2024-08-12 779269/week @ 2024-08-19 739433/week @ 2024-08-26 716421/week @ 2024-09-02 745924/week @ 2024-09-09 689281/week @ 2024-09-16 760230/week @ 2024-09-23 757277/week @ 2024-09-30 817576/week @ 2024-10-07 775658/week @ 2024-10-14 793788/week @ 2024-10-21 761438/week @ 2024-10-28 781047/week @ 2024-11-04 781809/week @ 2024-11-11 785941/week @ 2024-11-18

3,146,333 downloads per month
Used in 4,227 crates (306 directly)

CC0 license

47KB
874 lines

tiny-keccak

An implementation of Keccak derived functions specified in FIPS-202, SP800-185 and KangarooTwelve.

Build Status

Documentation

The Keccak-f[1600] permutation is fully unrolled; it's nearly as fast as the Keccak team's optimized permutation.

Usage

In your Cargo.toml specify what features (hash functions, you are intending to use). Available options are: cshake, fips202, k12, keccak, kmac, parallel_hash, sha3, shake, sp800, tuple_hash.

[dependencies]
tiny-keccak = { version = "2.0", features = ["sha3"] }

Example

use tiny_keccak::Sha3;

fn main() {
    let mut sha3 = Sha3::v256();
    let mut output = [0u8; 32];
    let expected = b"\
        \x64\x4b\xcc\x7e\x56\x43\x73\x04\x09\x99\xaa\xc8\x9e\x76\x22\xf3\
        \xca\x71\xfb\xa1\xd9\x72\xfd\x94\xa3\x1c\x3b\xfb\xf2\x4e\x39\x38\
    ";

    sha3.update(b"hello");
    sha3.update(b" ");
    sha3.update(b"world");
    sha3.finalize(&mut output);

    assert_eq!(expected, &output);
}

Benchmarks

Benchmarked with rust-crypto sha3 on:

MacBook Pro (Retina, 15-inch, Mid 2015)
2,5 GHz Intel Core i7
16 GB 1600 MHz DDR3
Intel Iris Pro 1536 MB

Benchmark code is available here

running 4 tests
test rust_crypto_sha3_256_input_32_bytes   ... bench:         677 ns/iter (+/- 113) = 47 MB/s
test rust_crypto_sha3_256_input_4096_bytes ... bench:      17,619 ns/iter (+/- 4,174) = 232 MB/s
test tiny_keccak_sha3_256_input_32_bytes   ... bench:         569 ns/iter (+/- 204) = 56 MB/s
test tiny_keccak_sha3_256_input_4096_bytes ... bench:      17,185 ns/iter (+/- 4,575) = 238 MB/s

Dependencies