def stream

bend-collections-laws-crypto@1.0.0.0 · src/crypto/chacha/chacha20.bend:78

import bend-collections-laws-crypto@1.0.0.0/src/crypto/chacha/chacha20.bend as Chacha20
import Base

78# Blocks of 64 bytes, block j under counter + j; fuel bounds the number of
79# blocks (the length of xs is enough).
80def stream(fuel: Nat, +xs: List<&2, U32>, +r: Nat, +k: Key, +counter: U32, +n: Nonce) -> List<&2, U32>:
81  match fuel xs:
82    case 0n _: Nil{}
83    case 1n+p Nil{}: Nil{}
84    case 1n+p x <> xt:
85      List.append(&2, U32, xor_front(keystream(r, k, counter, n), x <> xt),
86        stream(p, skip(64n, x <> xt), r, k, U32.add(counter, 1), n))

Uses (10)

Used by (2)