Skip to content

Commit

Permalink
Accept number of rounds as uint32
Browse files Browse the repository at this point in the history
go-ethereum F precompile accepts the number of rounds as uint32. The
conversion between uint32->int could be dangerous on 32-bit systems.
That's why we decided to keep the types aligned and accept the number of
rounds as uint32 everywhere.
  • Loading branch information
pdyraga committed Jun 28, 2019
1 parent cf26032 commit 1caa470
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions f.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var precomputed = [10][16]byte{
// vector `h`, message block vector `mb`, offset counter `t`, final
// block indicator flag `f`, and number of rounds `rounds`. The state vector
// provided as the first parameter is modified by the function.
func F(h *[8]uint64, mb [BlockSize]byte, t [2]uint64, f bool, rounds int) {
func F(h *[8]uint64, mb [BlockSize]byte, t [2]uint64, f bool, rounds uint32) {
var m [16]uint64
t0, t1 := t[0], t[1]

Expand All @@ -65,7 +65,7 @@ func F(h *[8]uint64, mb [BlockSize]byte, t [2]uint64, f bool, rounds int) {
i += 8
}

for j := 0; j < rounds; j++ {
for j := uint32(0); j < rounds; j++ {
s := &(precomputed[j%10])

v0 += m[s[0]]
Expand Down
2 changes: 1 addition & 1 deletion f_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ type testVector struct {
hIn [8]uint64
t [2]uint64
f bool
rounds int
rounds uint32
hOut [8]uint64
}

0 comments on commit 1caa470

Please sign in to comment.