wire / wire-format / chacha20-block

ChaCha20 stream cipher block

ChaCha20 is a stream cipher (RFC 8439) that generates a 64-byte keystream block from a 256-bit key, 96-bit nonce, and 32-bit counter. The state is a 4x4 matrix of 32-bit words: 4 constants ('expa', 'nd 3', '2-by', 'te k'), 8 key words, 1 counter word, 3 nonce words. 20 rounds (10 double-rounds) of quarter-round operations produce the keystream.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: ChaCha20 stream cipher block

wire format

spec: RFC 8439

ChaCha20 is a stream cipher (RFC 8439) that generates a 64-byte keystream block from a 256-bit key, 96-bit nonce, and 32-bit counter. The state is a 4x4 matrix of 32-bit words: 4 constants ('expa', 'nd 3', '2-by', 'te k'), 8 key words, 1 counter word, 3 nonce words. 20 rounds (10 double-rounds) of quarter-round operations produce the keystream.

fieldsizemeaning
Constants4 x 4 bytes'expa' (0x61707865), 'nd 3' (0x3320646E), '2-by' (0x79622D32), 'te k' (0x6B206574).
Key8 x 4 bytes256-bit key as 8 little-endian 32-bit words.
Counter1 x 4 bytes32-bit block counter (little-endian), starts at 1 for the first block.
Nonce3 x 4 bytes96-bit nonce as 3 little-endian 32-bit words.
Quarter roundin-placeQR(a,b,c,d): a+=b; d^=a; d<<<=16; c+=d; b^=c; b<<<=12; a+=b; d^=a; d<<<=8; c+=d; b^=c; b<<<=7.
Output64 bytesXOR the final state with the initial state to produce the keystream block.

example:

65 78 70 61 6e 64 20 33 32 2d 62 79 74 65 20 6b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ChaCha20 state: constants + zero key + counter 0 + zero nonce


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/chacha20-block or /wire-format/chacha20-block.json