1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Keccak system call interception
#[cfg(zisk_guest)]
use core::arch::asm;
#[cfg(zisk_guest)]
use crate::ziskos_syscall;
#[cfg(not(zisk_guest))]
use tiny_keccak::keccakf;
/// Executes the Keccak256 permutation on the given state.
///
/// The Keccak256 permutation operates on an array of twenty-five `u64` elements, which represents the internal state of the Keccak algorithm.
/// The input state is modified in place to produce the output.
///
/// ### Safety
///
/// The caller must ensure that the data is aligned to a 64-bit boundary.
#[allow(unused_variables)]
#[cfg_attr(not(feature = "hints"), no_mangle)]
#[cfg_attr(feature = "hints", export_name = "hints_syscall_keccak_f")]
pub unsafe extern "C" fn syscall_keccak_f(
state: *mut [u64; 25],
#[cfg(feature = "hints")] hints: &mut Vec<u64>,
) {
#[cfg(zisk_guest)]
ziskos_syscall!(zisk_definitions::SYSCALL_KECCAKF_ID, state);
#[cfg(not(zisk_guest))]
{
// Register the input state if fcall_set_keccakf_cache_index() asked for it, mirroring
// what the emulator does before running the permutation
crate::zisklib::keccakf_cache::keccakf_cache_on_keccakf(unsafe { &*state });
// Call keccakf
keccakf(unsafe { &mut *state });
// Store results in hints vector
#[cfg(feature = "hints")]
if zisk_definitions::KECCAK_RESULTS {
hints.extend_from_slice(unsafe { &*state });
}
}
}