arnaucube
arnaucube/keccak256-circomPublic Self-hosted repository
Add Iota go impl
arnaucube root@arnaucube.com
Sun, 31 Oct 2021 14:42:56 +0100
commit

570fce4ae3331ff635c2e0fd9091144eca7f8bcb

parent

60513e5b9e98e297bac7338f6fca95f4e0750614

M go-keccak256-bits-impl/ref.go → go-keccak256-bits-impl/ref.go

@@ -135,3 +135,9 @@ a[23] ^= (^bc4) & bc0

a[24] ^= (^bc0) & bc1 return a } + +func iotU64Version(a [25]uint64, r int) [25]uint64 { + // iota + a[0] ^= roundConstantsU64[r] + return a +}
M go-keccak256-bits-impl/stepmappings.go → go-keccak256-bits-impl/stepmappings.go

@@ -1,5 +1,18 @@

package keccak +var roundConstantsU64 = []uint64{ + 0x0000000000000001, 0x0000000000008082, 0x800000000000808A, + 0x8000000080008000, 0x000000000000808B, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008A, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000A, + 0x000000008000808B, 0x800000000000008B, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800A, 0x800000008000000A, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008, +} + +var roundConstants = u64ArrayToBits(roundConstantsU64) + func theta(a [25 * 64]bool) [25 * 64]bool { var c0, c1, c2, c3, c4, d [64]bool var r [25 * 64]bool

@@ -216,3 +229,9 @@ copy(r[23*64:24*64], xor(a[23*64:24*64], and(xorSingle(c4[:]), c0[:])))

copy(r[24*64:25*64], xor(a[24*64:25*64], and(xorSingle(c0[:]), c1[:]))) return r } + +func iot(a [25 * 64]bool, r int) [25 * 64]bool { + // iota + copy(a[0:64], xor(a[0:64], roundConstants[r*64:r*64+64])) + return a +}
M go-keccak256-bits-impl/stepmappings_test.go → go-keccak256-bits-impl/stepmappings_test.go

@@ -81,3 +81,18 @@ s = chi(s)

sU64 = chiU64Version(sU64) qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:]) } + +func TestIota(t *testing.T) { + s, sU64 := newS() + + s = iot(s, 3) + sU64 = iotU64Version(sU64, 3) + + qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:]) + qt.Assert(t, bitsToU64(s[0:64]), qt.Equals, uint64(9223372039002292224)) + + // compute again theta on the current state + s = iot(s, 10) + sU64 = iotU64Version(sU64, 10) + qt.Assert(t, bitsToU64Array(s[:]), qt.DeepEquals, sU64[:]) +}