Browse Source

Add Iota go impl

master
arnaucube 3 years ago
parent
commit
570fce4ae3
3 changed files with 40 additions and 0 deletions
  1. +6
    -0
      go-keccak256-bits-impl/ref.go
  2. +19
    -0
      go-keccak256-bits-impl/stepmappings.go
  3. +15
    -0
      go-keccak256-bits-impl/stepmappings_test.go

+ 6
- 0
go-keccak256-bits-impl/ref.go

@ -135,3 +135,9 @@ func chiU64Version(a [25]uint64) [25]uint64 {
a[24] ^= (^bc0) & bc1
return a
}
func iotU64Version(a [25]uint64, r int) [25]uint64 {
// iota
a[0] ^= roundConstantsU64[r]
return a
}

+ 19
- 0
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 @@ func chi(a [25 * 64]bool) [25 * 64]bool {
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
}

+ 15
- 0
go-keccak256-bits-impl/stepmappings_test.go

@ -81,3 +81,18 @@ func TestChi(t *testing.T) {
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[:])
}

Loading…
Cancel
Save