def blocks

bend-collections@1.0.0.0 · src/crypto/kdf.bend:26

import bend-collections@1.0.0.0/src/crypto/kdf.bend as Kdf
import Base
import bend-collections@1.0.0.0/src/crypto/mac.bend as MAC

26# The blocks T(i), T(i+1), ... cut to rem bytes: prev is T(i-1) and ctr the
27# counter byte i. Generation stops as soon as rem bytes are out, and no
28# block count is computed.
29def blocks(rem: Nat, +prk: List<&2, U32>, +info: List<&2, U32>, prev: List<&2, U32>, +ctr: U32) -> List<&2, U32>:
30  match rem:
31    case 0n:
32      Nil{}
33    case 32n+r:
34      +t = MAC.sign(prk, List.append(&2, U32, prev, List.append(&2, U32, info, [ctr])))
35      List.append(&2, U32, t, blocks(r, prk, info, t, U32.inc(ctr)))
36    case 1n+p:
37      List.take(&2, U32, MAC.sign(prk, List.append(&2, U32, prev, List.append(&2, U32, info, [ctr]))), 1n+p)

Uses (7)

Used by (1)