mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-09 23:48:10 -05:00
Add Sha3 (#560)
## Describe the changes This PR... ## Linked Issues Resolves #
This commit is contained in:
@@ -25,6 +25,22 @@ extern "C" {
|
||||
config: &HashConfig,
|
||||
) -> CudaError;
|
||||
|
||||
pub(crate) fn sha3_256_cuda(
|
||||
input: *const u8,
|
||||
input_block_size: u32,
|
||||
number_of_blocks: u32,
|
||||
output: *mut u8,
|
||||
config: &HashConfig,
|
||||
) -> CudaError;
|
||||
|
||||
pub(crate) fn sha3_512_cuda(
|
||||
input: *const u8,
|
||||
input_block_size: u32,
|
||||
number_of_blocks: u32,
|
||||
output: *mut u8,
|
||||
config: &HashConfig,
|
||||
) -> CudaError;
|
||||
|
||||
pub(crate) fn build_keccak256_merkle_tree_cuda(
|
||||
leaves: *const u8,
|
||||
digests: *mut u64,
|
||||
@@ -40,6 +56,22 @@ extern "C" {
|
||||
input_block_len: u32,
|
||||
config: &TreeBuilderConfig,
|
||||
) -> CudaError;
|
||||
|
||||
pub(crate) fn build_sha3_256_merkle_tree_cuda(
|
||||
leaves: *const u8,
|
||||
digests: *mut u64,
|
||||
height: u32,
|
||||
input_block_len: u32,
|
||||
config: &TreeBuilderConfig,
|
||||
) -> CudaError;
|
||||
|
||||
pub(crate) fn build_sha3_512_merkle_tree_cuda(
|
||||
leaves: *const u8,
|
||||
digests: *mut u64,
|
||||
height: u32,
|
||||
input_block_len: u32,
|
||||
config: &TreeBuilderConfig,
|
||||
) -> CudaError;
|
||||
}
|
||||
|
||||
pub fn keccak256(
|
||||
@@ -86,6 +118,50 @@ pub fn keccak512(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sha3_256(
|
||||
input: &(impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
input_block_size: u32,
|
||||
number_of_blocks: u32,
|
||||
output: &mut (impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
config: &HashConfig,
|
||||
) -> IcicleResult<()> {
|
||||
let mut local_cfg = config.clone();
|
||||
local_cfg.are_inputs_on_device = input.is_on_device();
|
||||
local_cfg.are_outputs_on_device = output.is_on_device();
|
||||
unsafe {
|
||||
sha3_256_cuda(
|
||||
input.as_ptr(),
|
||||
input_block_size,
|
||||
number_of_blocks,
|
||||
output.as_mut_ptr(),
|
||||
&local_cfg,
|
||||
)
|
||||
.wrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sha3_512(
|
||||
input: &(impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
input_block_size: u32,
|
||||
number_of_blocks: u32,
|
||||
output: &mut (impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
config: &HashConfig,
|
||||
) -> IcicleResult<()> {
|
||||
let mut local_cfg = config.clone();
|
||||
local_cfg.are_inputs_on_device = input.is_on_device();
|
||||
local_cfg.are_outputs_on_device = output.is_on_device();
|
||||
unsafe {
|
||||
sha3_512_cuda(
|
||||
input.as_ptr(),
|
||||
input_block_size,
|
||||
number_of_blocks,
|
||||
output.as_mut_ptr(),
|
||||
&local_cfg,
|
||||
)
|
||||
.wrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_keccak256_merkle_tree(
|
||||
leaves: &(impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
digests: &mut (impl HostOrDeviceSlice<u64> + ?Sized),
|
||||
@@ -123,3 +199,41 @@ pub fn build_keccak512_merkle_tree(
|
||||
.wrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_sha3_256_merkle_tree(
|
||||
leaves: &(impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
digests: &mut (impl HostOrDeviceSlice<u64> + ?Sized),
|
||||
height: usize,
|
||||
input_block_len: usize,
|
||||
config: &TreeBuilderConfig,
|
||||
) -> IcicleResult<()> {
|
||||
unsafe {
|
||||
build_sha3_256_merkle_tree_cuda(
|
||||
leaves.as_ptr(),
|
||||
digests.as_mut_ptr(),
|
||||
height as u32,
|
||||
input_block_len as u32,
|
||||
config,
|
||||
)
|
||||
.wrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_sha3_512_merkle_tree(
|
||||
leaves: &(impl HostOrDeviceSlice<u8> + ?Sized),
|
||||
digests: &mut (impl HostOrDeviceSlice<u64> + ?Sized),
|
||||
height: usize,
|
||||
input_block_len: usize,
|
||||
config: &TreeBuilderConfig,
|
||||
) -> IcicleResult<()> {
|
||||
unsafe {
|
||||
build_sha3_512_merkle_tree_cuda(
|
||||
leaves.as_ptr(),
|
||||
digests.as_mut_ptr(),
|
||||
height as u32,
|
||||
input_block_len as u32,
|
||||
config,
|
||||
)
|
||||
.wrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub(crate) mod tests {
|
||||
let number_of_hashes = 1024;
|
||||
|
||||
let preimages = vec![1u8; number_of_hashes * input_block_len];
|
||||
let mut digests = vec![0u8; number_of_hashes * 64];
|
||||
let mut digests = vec![0u8; number_of_hashes * 32];
|
||||
|
||||
let preimages_slice = HostSlice::from_slice(&preimages);
|
||||
let digests_slice = HostSlice::from_mut_slice(&mut digests);
|
||||
|
||||
Reference in New Issue
Block a user