#kangaroo-twelve #hash #k12 #bindings #xkcp #hasher #xkcp-k12

marsupial

safe bindings to the xkcp/k12 implementation of the kangarootwelve hash function

7 releases

0.1.0 Jul 7, 2024
0.0.6 Jul 3, 2024
0.0.5 Jun 26, 2024

#2 in #kangaroo-twelve

Download history 30/week @ 2024-07-28 18/week @ 2024-09-15 4/week @ 2024-09-22 2/week @ 2024-09-29

426 downloads per month

CC0 license

360KB
7.5K SLoC

C 5K SLoC // 0.1% comments GNU Style Assembly 2K SLoC // 0.0% comments Rust 671 SLoC // 0.1% comments

marsupial

a rust wrapper for xkcp/k12, derived from oconnor663/kangarootwelve_xkcp.rs

usage

in order to use the crate, you need:

  • a c compiler
  • rust
  • gnuplot (if you want plot generation when benchmarking)

then, just add a dependency upon the marsupial crate in Cargo.toml, and then you can use it like this:

use marsupial::{KT128, Hasher};

// hash an input all at once
let hash1 = marsupial::hash::<KT128>(b"foobarbaz");

// hash an input incrementally
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
let hash2 = hasher.finalize();
assert_eq!(hash1, hash2);

// extended output. `OutputReader` also implements `Read`
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foobarbaz");
let mut output_reader = hasher.finalize_xof();
let mut output = [0; 1000];
output_reader.squeeze(&mut output);
assert_eq!(&output[..32], hash1.as_bytes());

// emit the hash as hexadecimal (does not work for now)
//println!("{}", hash1.to_hex());

is it fast?

benchmarks done on an intel i5-1135G7 using rust 1.79.0 on debian linux trixie/sid

benchmark of marsupial's safe KT128 bindings against tiny-keccak and k12

benchmark of marsupial's safe KT256 bindings

license

as is with kangarootwelve_xkcp.rs, all of the rust wrapping code is dedicated to the public domain via cc0. the vendored xkcp code is covered by a mixture of licenses

Dependencies

~0–2.2MB
~44K SLoC