Skip to content
This repository has been 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
8 changes: 6 additions & 2 deletions ethash/src/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub mod keccak_512 {
pub fn inplace(input: &mut [u8]) {
// This is safe since `sha3_*` uses an internal buffer and copies the result to the output. This
// means that we can reuse the input buffer for both input and output.
hash::keccak_512_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
unsafe {
hash::keccak_512_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rphmeier should these functions also be pub unsafe …?

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.

nope. &mut [T] has type-system guarantees to point to valid data. there is no way, using only safe code, to create a &mut T which is invalid. If you did it with unsafe code, then the error would be in that unsafe code and not in this function.

}
}

Expand All @@ -47,6 +49,8 @@ pub mod keccak_256 {
pub fn inplace(input: &mut [u8]) {
// This is safe since `sha3_*` uses an internal buffer and copies the result to the output. This
// means that we can reuse the input buffer for both input and output.
hash::keccak_256_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
unsafe {
hash::keccak_256_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len());
}
}
}