#sha3 #keccak #crypto #sha-3 #kangarootwelve

no-std tiny-keccak

An implementation of the FIPS-202-defined SHA-3 and SHAKE functions

19 stable releases

✓ Uses Rust 2018 edition

1.5.0 Jun 25, 2019
1.4.2 May 20, 2018
1.4.1 Feb 26, 2018
1.4.0 Nov 24, 2017
0.3.0 Nov 27, 2015

#10 in Cryptography

Download history 3808/week @ 2019-04-13 3983/week @ 2019-04-20 3222/week @ 2019-04-27 3748/week @ 2019-05-04 3785/week @ 2019-05-11 4301/week @ 2019-05-18 4980/week @ 2019-05-25 5737/week @ 2019-06-01 6525/week @ 2019-06-08 11005/week @ 2019-06-15 8727/week @ 2019-06-22 7476/week @ 2019-06-29 7136/week @ 2019-07-06 6855/week @ 2019-07-13 6097/week @ 2019-07-20

22,010 downloads per month
Used in 190 crates (84 directly)

CC0 license

20KB
456 lines

tiny-keccak

An implementation of sha3, shake, keccak and KangarooTwelve functions.

Build Status

Documentation

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

Building

cargo build

Usage

Add this to your Cargo.toml:

[dependencies]
tiny-keccak = "1.5"

Example

use tiny_keccak::Keccak;

fn main() {
    let mut sha3 = Keccak::new_sha3_256();

    sha3.update("hello".as_ref());
    sha3.update(&[b' ']);
    sha3.update("world".as_ref());

    let mut res: [u8; 32] = [0; 32];
    sha3.finalize(&mut res);

    let expected: &[u8] = &[
        0x64, 0x4b, 0xcc, 0x7e, 0x56, 0x43, 0x73, 0x04,
        0x09, 0x99, 0xaa, 0xc8, 0x9e, 0x76, 0x22, 0xf3,
        0xca, 0x71, 0xfb, 0xa1, 0xd9, 0x72, 0xfd, 0x94,
        0xa3, 0x1c, 0x3b, 0xfb, 0xf2, 0x4e, 0x39, 0x38
    ];

    assert_eq!(&res, expected);
}

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

Why tiny-keccak is twice faster? It's optimized with:

Dependencies