Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Remove the Keccak C library and use the pure Rust impl #8657

Merged
merged 15 commits into from
May 20, 2018
24 changes: 10 additions & 14 deletions util/hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ pub fn keccak<T: AsRef<[u8]>>(s: T) -> H256 {
H256(result)
}

pub fn keccak_256_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) {
unsafe {
Keccak::keccak256(
slice::from_raw_parts(input, inputlen),
slice::from_raw_parts_mut(out, outlen)
);
}
pub unsafe fn keccak_256_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) {
Copy link
Contributor

@rphmeier rphmeier May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's document these and their invariants as well -- general style for the codebase is to provide a little bit of documentation on every public item, but this is especially important for unsafe functions.

Keccak::keccak256(
slice::from_raw_parts(input, inputlen),
slice::from_raw_parts_mut(out, outlen)
);
}

pub fn keccak_512_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) {
unsafe {
Keccak::keccak512(
slice::from_raw_parts(input, inputlen),
slice::from_raw_parts_mut(out, outlen)
);
}
pub unsafe fn keccak_512_unchecked(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) {
Keccak::keccak512(
slice::from_raw_parts(input, inputlen),
slice::from_raw_parts_mut(out, outlen)
);
}

pub fn keccak_256(input: &[u8], mut output: &mut [u8]) { Keccak::keccak256(input, &mut output); }
Expand Down