fn xchachapoly_open(
    data: &mut [u8],
    tag: &[u8],
    ad: &[u8],
    key: &[u8],
    nonce: &[u8],
) -> Result<(), Box<dyn Error + 'static>> {
    // build footer
    let mut foot = Vec::with_capacity(16);
    foot.extend_from_slice(&(ad.len() as u64).to_le_bytes());
    foot.extend_from_slice(&(data.len() as u64).to_le_bytes());

    // get poly1305 key and auth tag
    let (mut pkey, mut verify_tag) = (vec![0; 32], vec![0; 16]);
    XChaCha20::xor(key, nonce, 0, &mut pkey);
    Poly1305::chachapoly_auth(&mut verify_tag, ad, data, &foot, &pkey);

    // validate the tags.
    if !eq_const_time!(&tag, &verify_tag) {
        return Err(crate::Error::InvalidData.into());
    }
    XChaCha20::xor(key, nonce, 1, data);
    Ok(())
}
/// decrypts data in-place after validation
decrypts data in-place after validation
decrypts data in - place after validation
fn xchachapoly_open(
    data: &mut [u8],
    tag: &[u8],
    ad: &[u8],
    key: &[u8],
    nonce: &[u8],
) -> Result<(), Box<dyn Error + 'static>> {
    // build footer
    let mut foot = Vec::with_capacity(16);
    foot.extend_from_slice(&(ad.len() as u64).to_le_bytes());
    foot.extend_from_slice(&(data.len() as u64).to_le_bytes());
    // get poly1305 key and auth tag
    let (mut pkey, mut verify_tag) = (vec![0; 32], vec![0; 16]);
    XChaCha20::xor(key, nonce, 0, &mut pkey);
    Poly1305::chachapoly_auth(&mut verify_tag, ad, data, &foot, &pkey);
    // validate the tags.
    if !eq_const_time!(&tag, &verify_tag) {
        return Err(crate::Error::InvalidData.into());
    }
    XChaCha20::xor(key, nonce, 1, data);
    Ok(())
}
fn xchachapoly_open ( data : & mut [ u8 ] , tag : & [ u8 ] , ad : & [ u8 ] , key : & [ u8 ] , nonce : & [ u8 ] , ) -> Result < ( ) , Box < dyn Error + ' static > > { // build footer let mut foot = Vec :: with_capacity ( 16 ) ; foot . extend_from_slice ( & ( ad . len ( ) as u64 ) . to_le_bytes ( ) ) ; foot . extend_from_slice ( & ( data . len ( ) as u64 ) . to_le_bytes ( ) ) ; // get poly1305 key and auth tag let ( mut pkey , mut verify_tag ) = ( vec ! [ 0 32 ] , vec ! [ 0 16 ] ) ; XChaCha20 :: xor ( key , nonce , 0 , & mut pkey ) ; Poly1305 :: chachapoly_auth ( & mut verify_tag , ad , data , & foot , & pkey ) ; // validate the tags. if ! eq_const_time ! ( tag verify_tag ) { return Err ( crate :: Error :: InvalidData . into ( ) ) ; } XChaCha20 :: xor ( key , nonce , 1 , data ) ; Ok ( ( ) ) }
decrypts data in-place after validation
decrypts data in - place after validation
data
&mut [u8]
tag
&[u8]
ad
&[u8]
key
&[u8]
nonce
&[u8]