-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from sha256 to keccak256 (#23)
Switching from [sha256](https://crates.io/crates/sha2) to [keccak256](https://crates.io/crates/sha3) as the general-purpose hash function, to enhance compatibility with EVM/zkEVM. Closing BFT-361. --------- Co-authored-by: pompon0 <[email protected]>
- Loading branch information
Showing
18 changed files
with
375 additions
and
293 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#[test] | ||
fn test_keccak256() -> Result<(), Box<dyn std::error::Error>> { | ||
use crate::keccak256::Keccak256; | ||
|
||
// Test vectors obtained from https://emn178.github.io/online-tools/keccak_256.html | ||
let test_vectors: Vec<(&[u8], [u8; 32])> = vec![ | ||
( | ||
b"testing", | ||
hex::decode("5f16f4c7f149ac4f9510d9cf8cf384038ad348b3bcdc01915f95de12df9d1b02")? | ||
.try_into() | ||
.unwrap(), | ||
), | ||
( | ||
b"", | ||
hex::decode("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")? | ||
.try_into() | ||
.unwrap(), | ||
), | ||
( | ||
&[0x12, 0x34, 0x56], | ||
hex::decode("6adf031833174bbe4c85eafe59ddb54e6584648c2c962c6f94791ab49caa0ad4")? | ||
.try_into() | ||
.unwrap(), | ||
), | ||
]; | ||
|
||
for (input, expected_hash) in &test_vectors { | ||
let hash = Keccak256::new(input); | ||
assert_eq!(hash.as_bytes(), expected_hash); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Random hash generation, intended for use in testing | ||
use crate::keccak256::Keccak256; | ||
use rand::{ | ||
distributions::{Distribution, Standard}, | ||
Rng, | ||
}; | ||
|
||
impl Distribution<Keccak256> for Standard { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Keccak256 { | ||
Keccak256(rng.gen()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ pub mod bls12_381; | |
pub mod bn254; | ||
pub mod ed25519; | ||
mod fmt; | ||
pub mod sha256; | ||
pub mod keccak256; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.