wire / wire-format / chacha20-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.
aka: ChaCha20 stream cipher block
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.
| field | size | meaning |
|---|---|---|
| Constants | 4 x 4 bytes | 'expa' (0x61707865), 'nd 3' (0x3320646E), '2-by' (0x79622D32), 'te k' (0x6B206574). |
| Key | 8 x 4 bytes | 256-bit key as 8 little-endian 32-bit words. |
| Counter | 1 x 4 bytes | 32-bit block counter (little-endian), starts at 1 for the first block. |
| Nonce | 3 x 4 bytes | 96-bit nonce as 3 little-endian 32-bit words. |
| Quarter round | in-place | QR(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. |
| Output | 64 bytes | XOR 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
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/chacha20-block
or /wire-format/chacha20-block.json