~/bend-docscommunity

src/math/random/chacha8/block.bend checks

raw source on the hub · import 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/random/chacha8/block.bend as Block

Generated by tools/generators/chacha8rand_gen.py; do not edit. The ChaCha8 core of ChaCha8Rand (C2SP chacha8rand; Go's internal/chacha8rand block_generic). One double round is fully unrolled (four column and four diagonal quarter rounds, RFC 8439 section 2.1-2.3, constant rotations); a block is four double rounds (eight rounds). As C2SP specifies, only the key words 4..11 are added back after the rounds: the constants and the counter are not (the standard ChaCha output minus them). A group is four consecutive blocks interleaved word by word, read as 32 little-endian 64-bit words: word 2w of the group is word w of the first block (low half) and of the second (high half), word 2w + 1 the same for the third and fourth block.

Proved equal to spec/math/random/chacha8rand.bend for every key and counter (proofs/math/random/chacha8/).

2 imports
import Base
import ../../u64.bend as W

Types

type Key source · line 19 · raw

Data

the 256-bit key as eight little-endian words

type Vector source · line 23 · raw

Data

the ChaCha state x[0..15]

Definitions

def init source · line 27 · raw

@k:Key -> @+ctr:U32 -> Vector

the initial state: constants, key, 32-bit block counter, zero nonce

def dr source · line 33 · raw

@v:Vector -> Vector

one double round: four column quarter rounds, then four diagonal ones

def finish source · line 135 · raw

@k:Key -> @v:Vector -> Vector

the key words added back to words 4..11

def block source · line 141 · raw

@+k:Key -> @+ctr:U32 -> Vector

the ChaCha8Rand block with counter ctr: eight rounds

def interleave source · line 145 · raw

@a:Vector -> @b:Vector -> @c:Vector -> @d:Vector -> List<&2, 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64>

four blocks interleaved word by word, as 32 little-endian 64-bit words

def group source · line 151 · raw

@+k:Key -> @+ctr:U32 -> List<&2, 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64>

the group of the blocks ctr, ctr + 1, ctr + 2, ctr + 3