ziskos 1.1.0-alpha

Guest runtime and entrypoint for programs targeting the ZisK zkVM
//! Blake2br system call interception

#[cfg(zisk_guest)]
use core::arch::asm;

#[cfg(zisk_guest)]
use crate::ziskos_syscall;

#[cfg(not(zisk_guest))]
use zisk_precomp_helpers::blake2b_round;

#[derive(Debug)]
#[repr(C)]
pub struct SyscallBlake2bRoundParams<'a> {
    pub index: u64, // a number in [0,10)
    pub state: &'a mut [u64; 16],
    pub input: &'a [u64; 16],
}

/// Executes the `Blake2bRound` operation, performing one round of the Blake2b compression function.
///
/// `Blake2bRound` operates on arrays of sixteen `u64` elements. The first parameter is a pointer to a structure
/// containing three values: `index`, `state`, and `input`. The `index` parameter specifies which round to execute (a number in [0,10)).
/// The `state` parameter is a mutable reference to the current state of the Blake2b compression function, which will be updated in place.
/// The `input` parameter is a reference to the message block being processed.
///
/// ### 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_blake2b_round")]
pub extern "C" fn syscall_blake2b_round(
    params: &mut SyscallBlake2bRoundParams,
    #[cfg(feature = "hints")] hints: &mut Vec<u64>,
) {
    #[cfg(zisk_guest)]
    ziskos_syscall!(zisk_definitions::SYSCALL_BLAKE2B_ROUND_ID, params);

    #[cfg(not(zisk_guest))]
    {
        blake2b_round(params.state, params.input, params.index as u32);

        #[cfg(feature = "hints")]
        {
            hints.extend_from_slice(params.state);
        }
    }
}