pub fn chacha_cbc_encrypt_file_many_keys(
    blocktree: &Arc<Blocktree>,
    segment: u64,
    ivecs: &mut [u8],
    samples: &[u64],
) -> io::Result<Vec<Hash>> {
    if ivecs.len() % CHACHA_BLOCK_SIZE != 0 {
        return Err(io::Error::new(
            io::ErrorKind::Other,
            format!(
                "bad IV length({}) not divisible by {} ",
                ivecs.len(),
                CHACHA_BLOCK_SIZE,
            ),
        ));
    }

    let mut buffer = [0; 8 * 1024];
    let num_keys = ivecs.len() / CHACHA_BLOCK_SIZE;
    let mut sha_states = vec![0; num_keys * size_of::<Hash>()];
    let mut int_sha_states = vec![0; num_keys * 112];
    let keys: Vec<u8> = vec![0; num_keys * CHACHA_KEY_SIZE]; // keys not used ATM, uniqueness comes from IV
    let mut entry = segment;
    let mut total_entries = 0;
    let mut total_entry_len = 0;
    let mut time: f32 = 0.0;
    unsafe {
        chacha_init_sha_state(int_sha_states.as_mut_ptr(), num_keys as u32);
    }
    loop {
        match blocktree.read_blobs_bytes(entry, SLOTS_PER_SEGMENT - total_entries, &mut buffer, 0) {
            Ok((num_entries, entry_len)) => {
                debug!(
                    "chacha_cuda: encrypting segment: {} num_entries: {} entry_len: {}",
                    segment, num_entries, entry_len
                );
                if num_entries == 0 {
                    break;
                }
                let entry_len_usz = entry_len as usize;
                unsafe {
                    chacha_cbc_encrypt_many_sample(
                        buffer[..entry_len_usz].as_ptr(),
                        int_sha_states.as_mut_ptr(),
                        entry_len_usz,
                        keys.as_ptr(),
                        ivecs.as_mut_ptr(),
                        num_keys as u32,
                        samples.as_ptr(),
                        samples.len() as u32,
                        total_entry_len,
                        &mut time,
                    );
                }

                total_entry_len += entry_len;
                total_entries += num_entries;
                entry += num_entries;
                debug!(
                    "total entries: {} entry: {} segment: {} entries_per_segment: {}",
                    total_entries, entry, segment, SLOTS_PER_SEGMENT
                );
                if (entry - segment) >= SLOTS_PER_SEGMENT {
                    break;
                }
            }
            Err(e) => {
                // info!("{}", Info(format!("Error encrypting file: {:?}", e).to_string()));
                let loginfo: String = format!("Error encrypting file: {:?}", e).to_string();
                println!("{}",
                    printLn(
                        loginfo,
                        module_path!().to_string()
                    )
                );
                break;
            }
        }
    }
    unsafe {
        chacha_end_sha_state(
            int_sha_states.as_ptr(),
            sha_states.as_mut_ptr(),
            num_keys as u32,
        );
    }
    let mut res = Vec::new();
    for x in 0..num_keys {
        let start = x * size_of::<Hash>();
        let end = start + size_of::<Hash>();
        res.push(Hash::new(&sha_states[start..end]));
    }
    Ok(res)
}
// Encrypt a file with multiple starting IV states, determined by ivecs.len()
//
// Then sample each block at the offsets provided by samples argument with sha256
// and return the vec of sha states
Encrypt a file with multiple starting IV states, determined by ivecs.len()
Then sample each block at the offsets provided by samples argument with sha256
and return the vec of sha states
Encrypt a file with multiple starting IV states determined by ivecs . len () Then sample each block at the offsets provided by samples argument with sha256 and return the vec of sha states
pub fn chacha_cbc_encrypt_file_many_keys(
    blocktree: &Arc<Blocktree>,
    segment: u64,
    ivecs: &mut [u8],
    samples: &[u64],
) -> io::Result<Vec<Hash>> {
    if ivecs.len() % CHACHA_BLOCK_SIZE != 0 {
        return Err(io::Error::new(
            io::ErrorKind::Other,
            format!(
                "bad IV length({}) not divisible by {} ",
                ivecs.len(),
                CHACHA_BLOCK_SIZE,
            ),
        ));
    }
    let mut buffer = [0; 8 * 1024];
    let num_keys = ivecs.len() / CHACHA_BLOCK_SIZE;
    let mut sha_states = vec![0; num_keys * size_of::<Hash>()];
    let mut int_sha_states = vec![0; num_keys * 112];
    let keys: Vec<u8> = vec![0; num_keys * CHACHA_KEY_SIZE]; // keys not used ATM, uniqueness comes from IV
    let mut entry = segment;
    let mut total_entries = 0;
    let mut total_entry_len = 0;
    let mut time: f32 = 0.0;
    unsafe {
        chacha_init_sha_state(int_sha_states.as_mut_ptr(), num_keys as u32);
    }
    loop {
        match blocktree.read_blobs_bytes(entry, SLOTS_PER_SEGMENT - total_entries, &mut buffer, 0) {
            Ok((num_entries, entry_len)) => {
                debug!(
                    "chacha_cuda: encrypting segment: {} num_entries: {} entry_len: {}",
                    segment, num_entries, entry_len
                );
                if num_entries == 0 {
                    break;
                }
                let entry_len_usz = entry_len as usize;
                unsafe {
                    chacha_cbc_encrypt_many_sample(
                        buffer[..entry_len_usz].as_ptr(),
                        int_sha_states.as_mut_ptr(),
                        entry_len_usz,
                        keys.as_ptr(),
                        ivecs.as_mut_ptr(),
                        num_keys as u32,
                        samples.as_ptr(),
                        samples.len() as u32,
                        total_entry_len,
                        &mut time,
                    );
                }
                total_entry_len += entry_len;
                total_entries += num_entries;
                entry += num_entries;
                debug!(
                    "total entries: {} entry: {} segment: {} entries_per_segment: {}",
                    total_entries, entry, segment, SLOTS_PER_SEGMENT
                );
                if (entry - segment) >= SLOTS_PER_SEGMENT {
                    break;
                }
            }
            Err(e) => {
                // info!("{}", Info(format!("Error encrypting file: {:?}", e).to_string()));
                let loginfo: String = format!("Error encrypting file: {:?}", e).to_string();
                println!("{}",
                    printLn(
                        loginfo,
                        module_path!().to_string()
                    )
                );
                break;
            }
        }
    }
    unsafe {
        chacha_end_sha_state(
            int_sha_states.as_ptr(),
            sha_states.as_mut_ptr(),
            num_keys as u32,
        );
    }
    let mut res = Vec::new();
    for x in 0..num_keys {
        let start = x * size_of::<Hash>();
        let end = start + size_of::<Hash>();
        res.push(Hash::new(&sha_states[start..end]));
    }
    Ok(res)
}
pub fn chacha_cbc_encrypt_file_many_keys ( blocktree : & Arc < Blocktree > , segment : u64 , ivecs : & mut [ u8 ] , samples : & [ u64 ] , ) -> io :: Result < Vec < Hash > > { if ivecs . len ( ) % CHACHA_BLOCK_SIZE != 0 { return Err ( io :: Error :: new ( io :: ErrorKind :: Other , format ! ( " " ivecs len ( ) CHACHA_BLOCK_SIZE ) , ) ) ; } let mut buffer = [ 0 ; 8 * 1024 ] ; let num_keys = ivecs . len ( ) / CHACHA_BLOCK_SIZE ; let mut sha_states = vec ! [ 0 num_keys size_of Hash ( ) ] ; let mut int_sha_states = vec ! [ 0 num_keys 112 ] ; let keys : Vec < u8 > = vec ! [ 0 num_keys CHACHA_KEY_SIZE ] ; // keys not used ATM, uniqueness comes from IV let mut entry = segment ; let mut total_entries = 0 ; let mut total_entry_len = 0 ; let mut time : f32 = 0.0 ; unsafe { chacha_init_sha_state ( int_sha_states . as_mut_ptr ( ) , num_keys as u32 ) ; } loop { match blocktree . read_blobs_bytes ( entry , SLOTS_PER_SEGMENT - total_entries , & mut buffer , 0 ) { Ok ( ( num_entries , entry_len ) ) => { debug ! ( " " segment num_entries entry_len ) ; if num_entries == 0 { break ; } let entry_len_usz = entry_len as usize ; unsafe { chacha_cbc_encrypt_many_sample ( buffer [ .. entry_len_usz ] . as_ptr ( ) , int_sha_states . as_mut_ptr ( ) , entry_len_usz , keys . as_ptr ( ) , ivecs . as_mut_ptr ( ) , num_keys as u32 , samples . as_ptr ( ) , samples . len ( ) as u32 , total_entry_len , & mut time , ) ; } total_entry_len += entry_len ; total_entries += num_entries ; entry += num_entries ; debug ! ( " " total_entries entry segment SLOTS_PER_SEGMENT ) ; if ( entry - segment ) >= SLOTS_PER_SEGMENT { break ; } } Err ( e ) => { // info!("{}", Info(format!("Error encrypting file: {:?}", e).to_string())); let loginfo : String = format ! ( " " e ) . to_string ( ) ; println ! ( " " printLn ( loginfo module_path ( ) to_string ( ) ) ) ; break ; } } } unsafe { chacha_end_sha_state ( int_sha_states . as_ptr ( ) , sha_states . as_mut_ptr ( ) , num_keys as u32 , ) ; } let mut res = Vec :: new ( ) ; for x in 0 .. num_keys { let start = x * size_of :: < Hash > ( ) ; let end = start + size_of :: < Hash > ( ) ; res . push ( Hash :: new ( & sha_states [ start .. end ] ) ) ; } Ok ( res ) }
Encrypt a file with multiple starting IV states, determined by ivecs.len()
Then sample each block at the offsets provided by samples argument with sha256
and return the vec of sha states
Encrypt a file with multiple starting IV states determined by ivecs . len () Then sample each block at the offsets provided by samples argument with sha256 and return the vec of sha states
blocktree
&Arc<Blocktree>
segment
u64
ivecs
&mut [u8]
samples
&[u64]
blocktree
&Arc<Blocktree>
segment
u64
ivecs
&mut [u8]
samples
&[u64]