Skip to content

Commit

Permalink
delete portable::xof_many and blake3_xof_many_portable
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Aug 19, 2024
1 parent 5c4c351 commit dcff6b6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 76 deletions.
9 changes: 0 additions & 9 deletions c/blake3_c_rust_bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,6 @@ pub mod ffi {
flags_end: u8,
out: *mut u8,
);
pub fn blake3_xof_many_portable(
cv: *const u32,
block: *const u8,
block_len: u8,
counter: u64,
flags: u8,
out: *mut u8,
outblocks: usize,
);
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand Down
29 changes: 13 additions & 16 deletions c/blake3_c_rust_bindings/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ fn test_hash_many_neon() {
test_hash_many_fn(crate::ffi::neon::blake3_hash_many_neon);
}

#[allow(unused)]
type XofManyFunction = unsafe extern "C" fn(
cv: *const u32,
block: *const u8,
Expand All @@ -370,6 +371,7 @@ type XofManyFunction = unsafe extern "C" fn(
);

// A shared helper function for platform-specific tests.
#[allow(unused)]
pub fn test_xof_many_fn(xof_many_function: XofManyFunction) {
let mut block = [0; BLOCK_LEN];
let block_len = 42;
Expand All @@ -390,16 +392,17 @@ pub fn test_xof_many_fn(xof_many_function: XofManyFunction) {
const OUTPUT_SIZE: usize = 31 * BLOCK_LEN;

let mut portable_out = [0u8; OUTPUT_SIZE];
unsafe {
crate::ffi::blake3_xof_many_portable(
cv.as_ptr(),
block.as_ptr(),
block_len as u8,
counter,
flags,
portable_out.as_mut_ptr(),
OUTPUT_SIZE / BLOCK_LEN,
);
for (i, out_block) in portable_out.chunks_exact_mut(BLOCK_LEN).enumerate() {
unsafe {
crate::ffi::blake3_compress_xof_portable(
cv.as_ptr(),
block.as_ptr(),
block_len as u8,
counter + i as u64,
flags,
out_block.as_mut_ptr(),
);
}
}

let mut test_out = [0u8; OUTPUT_SIZE];
Expand Down Expand Up @@ -445,12 +448,6 @@ pub fn test_xof_many_fn(xof_many_function: XofManyFunction) {
}
}

// Testing the portable implementation against itself is circular, but why not.
#[test]
fn test_xof_many_portable() {
test_xof_many_fn(crate::ffi::blake3_xof_many_portable);
}

#[test]
#[cfg(unix)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand Down
8 changes: 0 additions & 8 deletions c/blake3_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@ void blake3_compress_xof_portable(const uint32_t cv[8],
uint8_t block_len, uint64_t counter,
uint8_t flags, uint8_t out[64]);

// This function is test-only. When blake3_xof_many doesn't have an optimized implementation,
// it loops over blake3_compress_xof instead of falling back to this, so it still benefits
// from compress optimizations.
void blake3_xof_many_portable(const uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len, uint64_t counter, uint8_t flags,
uint8_t out[64], size_t outblocks);

void blake3_hash_many_portable(const uint8_t *const *inputs, size_t num_inputs,
size_t blocks, const uint32_t key[8],
uint64_t counter, bool increment_counter,
Expand Down
10 changes: 0 additions & 10 deletions c/blake3_portable.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ void blake3_compress_xof_portable(const uint32_t cv[8],
store32(&out[15 * 4], state[15] ^ cv[7]);
}

void blake3_xof_many_portable(const uint32_t cv[8],
const uint8_t block[BLAKE3_BLOCK_LEN],
uint8_t block_len, uint64_t counter, uint8_t flags,
uint8_t out[BLAKE3_BLOCK_LEN], size_t outblocks)
{
for(size_t i = 0; i < outblocks; ++i) {
blake3_compress_xof_portable(cv, block, block_len, counter + i, flags, out + 64*i);
}
}

INLINE void hash_one_portable(const uint8_t *input, size_t blocks,
const uint32_t key[8], uint64_t counter,
uint8_t flags, uint8_t flags_start,
Expand Down
25 changes: 0 additions & 25 deletions src/portable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,6 @@ pub fn hash_many<const N: usize>(
}
}

// This function is test-only. When platform::xof_many() doesn't have an optimized implementation,
// it loops over platform::compress_xof() instead of falling back to this, so it still benefits
// from compress optimizations.
#[cfg(test)]
pub fn xof_many(
cv: &CVWords,
block: &[u8; BLOCK_LEN],
block_len: u8,
mut counter: u64,
flags: u8,
out: &mut [u8],
) {
debug_assert_eq!(0, out.len() % BLOCK_LEN, "whole blocks only");
for out_block in out.chunks_exact_mut(64) {
out_block.copy_from_slice(&compress_xof(cv, block, block_len, counter, flags));
counter += 1;
}
}

#[cfg(test)]
pub mod test {
use super::*;
Expand All @@ -214,10 +195,4 @@ pub mod test {
fn test_hash_many() {
crate::test::test_hash_many_fn(hash_many, hash_many);
}

// Ditto.
#[test]
fn test_xof_many() {
crate::test::test_xof_many_fn(xof_many);
}
}
19 changes: 11 additions & 8 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub fn test_hash_many_fn(
}
}

#[allow(unused)]
type XofManyFunction = unsafe fn(
cv: &CVWords,
block: &[u8; BLOCK_LEN],
Expand All @@ -216,6 +217,7 @@ type XofManyFunction = unsafe fn(
);

// A shared helper function for platform-specific tests.
#[allow(unused)]
pub fn test_xof_many_fn(xof_many_function: XofManyFunction) {
let mut block = [0; BLOCK_LEN];
let block_len = 42;
Expand All @@ -237,14 +239,15 @@ pub fn test_xof_many_fn(xof_many_function: XofManyFunction) {
const OUTPUT_SIZE: usize = 31 * BLOCK_LEN;

let mut portable_out = [0u8; OUTPUT_SIZE];
crate::portable::xof_many(
&cv,
&block,
block_len as u8,
counter,
flags,
&mut portable_out,
);
for (i, out_block) in portable_out.chunks_exact_mut(64).enumerate() {
out_block.copy_from_slice(&crate::portable::compress_xof(
&cv,
&block,
block_len as u8,
counter + i as u64,
flags,
));
}

let mut test_out = [0u8; OUTPUT_SIZE];
unsafe {
Expand Down

0 comments on commit dcff6b6

Please sign in to comment.