Index Mathematics Conjectures nbv lettuce Widgets

lattice_digest

stdlib/lattice/lattice_digest.nbv

lattice_digest(pending, static a_absorb)

The lattice state after absorbing pending and padding (dags LatticeSponge::digest): the elements are cut into blocks of lattice_rate, the last block is padded with a 1 and zeros (a whole new block when the buffer is full), and every block is compressed with lattice_absorb. Returns lattice_kappa witness elements.

The padding is known at compile time, so its bits are static; only the pending elements and the carried state are decomposed with constraints.

Calls
calloc, lattice/lattice_absorb, lattice/lattice_bits_static, lattice/lattice_bits_vec, dilithium/lattice/lattice_kappa, lattice/lattice_rate, slice, slice_from_start
Precompiles
clone!, concat!, div_floor!, field_bit_width!, if_lt!, if_ne!, len!, loop!, wtns!
Used by
lattice/lattice_squeeze

Source

# The lattice state after absorbing `pending` and padding (dags LatticeSponge::digest):
# the elements are cut into blocks of `lattice_rate`, the last block is padded with a 1 and
# zeros (a whole new block when the buffer is full), and every block is compressed with
# lattice_absorb. Returns `lattice_kappa` witness elements.
#
# The padding is known at compile time, so its bits are static; only the pending elements
# and the carried state are decomposed with constraints.
(pending, static a_absorb)

static kappa = lattice_kappa()
static rate = lattice_rate()
static e = field_bit_width!
static n = len! pending
static full = div_floor! n, rate
# pad10*: a 1, then zeros to the block boundary, always one more block
static blocks = full + 1

# bits of the padding of a block with `pad_len` padding elements: bits(1) then zeros
static pad_bits_all = concat! lattice_bits_static(1), calloc(rate * e)

let mut state = calloc(kappa)
loop! blocks, b {
  # the initial state is zero, its bits are static zeros
  let mut state_bits = calloc(kappa * e)
  if_ne! b, 0 {
    state_bits = lattice_bits_vec(clone! state)
  }
  # pending elements of this block, then the padding
  static start = b * rate
  static mut fill = rate
  if_lt! n - start, rate {
    fill = n - start
  }
  let block_bits = concat! lattice_bits_vec(slice((clone! pending), start, fill)), slice_from_start((clone! pad_bits_all), (rate - fill) * e)
  state = wtns! lattice_absorb(state_bits, block_bits, clone! a_absorb)
}

state