pub fn chacha20_block(key: &[u8], nonce: &[u8], n: u64, buf: &mut [u8]) {
    // create buffer
    let mut state = vec![0u32; 32];
    let (init, mixed) = state.split_at_mut(16);

    // initialize buffer
    (0..4).for_each(|i| init[i] = BASIS[i]);
    (4..12).for_each(|i| init[i] = read32_little_endian!(&key[(i - 4) * 4..]));
    split64_little_endian!(n => &mut init[12..]);
    (14..16).for_each(|i| init[i] = read32_little_endian!(&nonce[(i - 14) * 4..]));

    // mix the buffer
    mixed.copy_from_slice(init);
    chacha20_rounds(mixed);

    // write the mixed state into the buffer
    (0..16).for_each(|i| mixed[i] = add!(mixed[i], init[i]));
    (0..16).for_each(|i| write32_little_endian!(mixed[i] => &mut buf[i * 4..]));
}
/// calculates the nth ChaCha20 block into a buffer
calculates the nth ChaCha20 block into a buffer
calculates the nth ChaCha20 block into a buffer
pub fn chacha20_block(key: &[u8], nonce: &[u8], n: u64, buf: &mut [u8]) {
    // create buffer
    let mut state = vec![0u32; 32];
    let (init, mixed) = state.split_at_mut(16);
    // initialize buffer
    (0..4).for_each(|i| init[i] = BASIS[i]);
    (4..12).for_each(|i| init[i] = read32_little_endian!(&key[(i - 4) * 4..]));
    split64_little_endian!(n => &mut init[12..]);
    (14..16).for_each(|i| init[i] = read32_little_endian!(&nonce[(i - 14) * 4..]));
    // mix the buffer
    mixed.copy_from_slice(init);
    chacha20_rounds(mixed);
    // write the mixed state into the buffer
    (0..16).for_each(|i| mixed[i] = add!(mixed[i], init[i]));
    (0..16).for_each(|i| write32_little_endian!(mixed[i] => &mut buf[i * 4..]));
}
pub fn chacha20_block ( key : & [ u8 ] , nonce : & [ u8 ] , n : u64 , buf : & mut [ u8 ] ) { // create buffer let mut state = vec ! [ 0u32 32 ] ; let ( init , mixed ) = state . split_at_mut ( 16 ) ; // initialize buffer ( 0 .. 4 ) . for_each ( | i | init [ i ] = BASIS [ i ] ) ; ( 4 .. 12 ) . for_each ( | i | init [ i ] = read32_little_endian ! ( key [ ( i 4 ) 4 ] ) ) ; split64_little_endian ! ( n mut init [ 12 ] ) ; ( 14 .. 16 ) . for_each ( | i | init [ i ] = read32_little_endian ! ( nonce [ ( i 14 ) 4 ] ) ) ; // mix the buffer mixed . copy_from_slice ( init ) ; chacha20_rounds ( mixed ) ; // write the mixed state into the buffer ( 0 .. 16 ) . for_each ( | i | mixed [ i ] = add ! ( mixed [ i ] init [ i ] ) ) ; ( 0 .. 16 ) . for_each ( | i | write32_little_endian ! ( mixed [ i ] mut buf [ i 4 ] ) ) ; }
calculates the nth ChaCha20 block into a buffer
calculates the nth ChaCha20 block into a buffer
key
&[u8]
nonce
&[u8]
n
u64
buf
&mut [u8]