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-GX.

Concatenates the eight-byte ASCII prefix arbitrGX (0x6172626974724758) 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;
}
// t contains [0x0, 0x1, 0x2 .. 0xf]

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

Using the authentication tag (T) and resulting nonce (N) for GX from the test vectors included in the ARX-KW paper:

 extern crate hex;
 use hex::FromHex;
    AuthTag,
    gx::construct_nonce,
};

let authentication_tag = AuthTag(<[u8;16]>::from_hex("016325cf6a3c4b2e3b039675e1ccbc65")?);
let nonce_expected = <[u8;24]>::from_hex("6172626974724758016325cf6a3c4b2e3b039675e1ccbc65")?;
let nonce = construct_nonce(&authentication_tag);
assert_eq!(nonce,nonce_expected);