| 1 |
# tiny-keccak |
| 2 |
|
| 3 |
An implementation of Keccak derived functions specified in [`FIPS-202`], [`SP800-185`] and [`KangarooTwelve`]. |
| 4 |
|
| 5 |
[![Build Status][travis-image]][travis-url] |
| 6 |
|
| 7 |
[travis-image]: https://travis-ci.org/debris/tiny-keccak.svg?branch=master |
| 8 |
[travis-url]: https://travis-ci.org/debris/tiny-keccak |
| 9 |
[`FIPS-202`]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf |
| 10 |
[`SP800-185`]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf |
| 11 |
[`KangarooTwelve`]: https://eprint.iacr.org/2016/770.pdf |
| 12 |
|
| 13 |
[`Documentation`](https://docs.rs/tiny-keccak) |
| 14 |
|
| 15 |
The `Keccak-f[1600]` permutation is fully unrolled; it's nearly as fast |
| 16 |
as the Keccak team's optimized permutation. |
| 17 |
|
| 18 |
## Usage |
| 19 |
|
| 20 |
In your `Cargo.toml` specify what features (hash functions, you are intending to use). |
| 21 |
Available options are: `cshake`, `fips202`, `k12`, `keccak`, `kmac`, `parallel_hash`, `sha3`, |
| 22 |
`shake`, `sp800`, `tuple_hash`. |
| 23 |
|
| 24 |
```toml |
| 25 |
[dependencies] |
| 26 |
tiny-keccak = { version = "2.0", features = ["sha3"] } |
| 27 |
``` |
| 28 |
|
| 29 |
## Example |
| 30 |
|
| 31 |
```rust |
| 32 |
use tiny_keccak::Sha3; |
| 33 |
|
| 34 |
fn main() { |
| 35 |
let mut sha3 = Sha3::v256(); |
| 36 |
let mut output = [0u8; 32]; |
| 37 |
let expected = b"\ |
| 38 |
\x64\x4b\xcc\x7e\x56\x43\x73\x04\x09\x99\xaa\xc8\x9e\x76\x22\xf3\ |
| 39 |
\xca\x71\xfb\xa1\xd9\x72\xfd\x94\xa3\x1c\x3b\xfb\xf2\x4e\x39\x38\ |
| 40 |
"; |
| 41 |
|
| 42 |
sha3.update(b"hello"); |
| 43 |
sha3.update(b" "); |
| 44 |
sha3.update(b"world"); |
| 45 |
sha3.finalize(&mut output); |
| 46 |
|
| 47 |
assert_eq!(expected, &output); |
| 48 |
} |
| 49 |
``` |
| 50 |
|
| 51 |
## Benchmarks |
| 52 |
|
| 53 |
Benchmarked with [rust-crypto](https://github.com/RustCrypto) sha3 on: |
| 54 |
|
| 55 |
``` |
| 56 |
MacBook Pro (Retina, 15-inch, Mid 2015) |
| 57 |
2,5 GHz Intel Core i7 |
| 58 |
16 GB 1600 MHz DDR3 |
| 59 |
Intel Iris Pro 1536 MB |
| 60 |
``` |
| 61 |
|
| 62 |
Benchmark code is available [here](https://github.com/debris/tiny-keccak/blob/master/comparison/benches/sha3.rs) |
| 63 |
|
| 64 |
``` |
| 65 |
running 4 tests |
| 66 |
test rust_crypto_sha3_256_input_32_bytes ... bench: 677 ns/iter (+/- 113) = 47 MB/s |
| 67 |
test rust_crypto_sha3_256_input_4096_bytes ... bench: 17,619 ns/iter (+/- 4,174) = 232 MB/s |
| 68 |
test tiny_keccak_sha3_256_input_32_bytes ... bench: 569 ns/iter (+/- 204) = 56 MB/s |
| 69 |
test tiny_keccak_sha3_256_input_4096_bytes ... bench: 17,185 ns/iter (+/- 4,575) = 238 MB/s |
| 70 |
``` |