cairo_lang_starknet_classes/
keccak.rs

1use num_bigint::BigUint;
2use sha3::{Digest, Keccak256};
3
4#[cfg(test)]
5#[path = "keccak_test.rs"]
6mod test;
7
8/// A variant of eth-keccak that computes a value that fits in a Starknet field element.
9pub fn starknet_keccak(data: &[u8]) -> BigUint {
10    let mut hasher = Keccak256::new();
11    hasher.update(data);
12    let mut result = hasher.finalize();
13
14    // Truncate result to 250 bits.
15    result[0] &= 3;
16    BigUint::from_bytes_be(&result)
17}