leo.blog();

Gimli

Gimli is a 384-bit permutation function. It can be used in sponge constructions.

GIMLI-Hash

GIMLI-Hash is a simple hash function built on the Gimli permutation.

Test vectors

The test vectors on the Gimli paper are incorrect. The authors have provided corrected values here.

Useful links

Implementation in Rust

pub(crate) fn gimli(state: &mut [u32; 12]) {
  for round in (1..25).rev() {
    for col in 0..4 {
      let x = state[col].rotate_left(24);
      let y = state[col + 4].rotate_left(9);
      let z = state[col + 8];

      state[col + 8] = x ^ (z << 1) ^ ((y & z) << 2);
      state[col + 4] = y ^ x ^ ((x | z) << 1);
      state[col] = z ^ y ^ ((x & y) << 3);
    }

    if (round & 3) == 0 {
      // Small swap
      state.swap(0, 1);
      state.swap(2, 3);
    }

    if (round & 3) == 2 {
      // Big swap
      state.swap(0, 2);
      state.swap(1, 3);
    }

    if (round & 3) == 0 {
      // Add constant
      state[0] ^= 0x9e377900 | round as u32;
    }
  }
}

Leave a Comment