Skip to main content

construct_nonce

Function construct_nonce 

Source
pub fn construct_nonce(authentication_tag: &AuthTag) -> [u8; 24]
Expand description

Builds the 24-byte XChaCha8 nonce for ARX-KW-8-2-4-EX.

Concatenates the eight-byte ASCII prefix arbitrEX (0x6172626974724558) with the 16-byte authentication tag. Encryption and decryption call this internally; applications normally only need the ArxKW methods.

let mut t = AuthTag([0u8; 16]);
for i in (0u8..16u8) {
    t.0[i as usize] = i;
}

let nonce = construct_nonce(&t);
assert_eq!(nonce,
[0x61,0x72,0x62,0x69,0x74,0x72,0x45,0x58,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf]);

Using T and N from the test vectors for EX included in the ARX-KW paper:

 extern crate hex;
use hex::FromHex;
use arx_kw::{
    ex::construct_nonce,
    AuthTag,
    ConstantTimeEq,
    assert_ct_eq
};

let authentication_tag = AuthTag(<[u8;16]>::from_hex("c4f21d3b4dbcc566c3a73bbc59790f2f")?);
let nonce_expected = <[u8;24]>::from_hex("6172626974724558c4f21d3b4dbcc566c3a73bbc59790f2f")?;
let nonce = construct_nonce(&authentication_tag);
assert_ct_eq!(nonce, &nonce_expected);
Ok(())