chacha_quarter_round
stdlib/chacha/chacha_quarter_round.nbv
chacha_quarter_round(state)
Four ChaCha quarter rounds in parallel on a 512-bit state, word i at bits 32 i .. 32 i + 32. The rows a = words 0..4, b = words 4..8, c = words 8..12 and d = words 12..16 are operated on as whole vectors, quarter round i acts on word i of each row.
a += b; d ^= a; d <<<= 16;
c += d; b ^= c; b <<<= 12;
a += b; d ^= a; d <<<= 8;
c += d; b ^= c; b <<<= 7;
- Calls
bits/add32_bits,bits/rotl32_bits,slice,bits/xor_bits_vec_wtns- Precompiles
assert_eq!,clone!,concat!,len!- Used by
chacha/chacha_block
Source
# Four ChaCha quarter rounds in parallel on a 512-bit state, word i at bits
# 32 i .. 32 i + 32. The rows a = words 0..4, b = words 4..8, c = words 8..12
# and d = words 12..16 are operated on as whole vectors, quarter round i acts
# on word i of each row.
#
# a += b; d ^= a; d <<<= 16;
# c += d; b ^= c; b <<<= 12;
# a += b; d ^= a; d <<<= 8;
# c += d; b ^= c; b <<<= 7;
(state)
assert_eq! 512, len! state
let mut a = slice((clone! state), 0, 128)
let mut b = slice((clone! state), 128, 128)
let mut c = slice((clone! state), 256, 128)
let mut d = slice(state, 384, 128)
# the xors are materialized so b and d, which are only ever xored, do not
# accumulate linear combinations across rounds
a = add32_bits((clone! a) + (clone! b), 2)
d = rotl32_bits(xor_bits_vec_wtns((clone! d), (clone! a)), 16)
c = add32_bits((clone! c) + (clone! d), 2)
b = rotl32_bits(xor_bits_vec_wtns((clone! b), (clone! c)), 12)
a = add32_bits((clone! a) + (clone! b), 2)
d = rotl32_bits(xor_bits_vec_wtns((clone! d), (clone! a)), 8)
c = add32_bits((clone! c) + (clone! d), 2)
b = rotl32_bits(xor_bits_vec_wtns((clone! b), (clone! c)), 7)
concat! a, b, c, d