Skip to content

Commit

Permalink
Merge pull request #52 from nspcc-dev/up-go
Browse files Browse the repository at this point in the history
Update Go to 1.22+
  • Loading branch information
roman-khimov authored Aug 20, 2024
2 parents 415c386 + 8d33bed commit baa1bc1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 44 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

test_cover:
name: Coverage
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

env:
CGO_ENABLED: 0
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: true

- name: Write coverage profile
Expand All @@ -54,15 +54,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04, windows-2022, macos-14 ]
go_versions: [ '1.21', '1.22' ]
os: [ ubuntu-24.04, windows-2022, macos-14 ]
go_versions: [ '1.22', '1.23' ]
exclude:
- os: macos-14
go_versions: '1.21'
go_versions: '1.22'
- os: windows-2022
go_versions: '1.21'
- os: ubuntu-22.04
go_versions: '1.22'
- os: ubuntu-24.04
go_versions: '1.23'
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions gf127/gf127.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"errors"
"math/bits"
"math/rand"
"math/rand/v2"
)

// GF127 represents element of GF(2^127).
Expand Down Expand Up @@ -35,13 +35,13 @@ func addGeneric(a, b, c *GF127) {
func mulGeneric(a, b, c *GF127) {
r := new(GF127)
d := *a
for i := uint(0); i < 64; i++ {
for i := range uint(64) {
if b[0]&(1<<i) != 0 {
addGeneric(r, &d, r)
}
mul10Generic(&d, &d)
}
for i := uint(0); i < 63; i++ {
for i := range uint(63) {
if b[1]&(1<<i) != 0 {
addGeneric(r, &d, r)
}
Expand Down
2 changes: 1 addition & 1 deletion gf127/gf127_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestInv(t *testing.T) {
require.Equal(t, tc[1], c)
}

for i := 0; i < 3; i++ {
for range 3 {
// 0 has no inverse
if a = Random(); a.Equals(&GF127{0, 0}) {
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nspcc-dev/tzhash

go 1.21
go 1.22

require (
github.com/stretchr/testify v1.9.0
Expand Down
2 changes: 1 addition & 1 deletion tz/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (d *digest) UnmarshalBinary(b []byte) error {
start, end int
)

for i := 0; i < 4; i++ {
for i := range d.x {
start = gf127.Size * i
end = start + gf127.Size

Expand Down
37 changes: 13 additions & 24 deletions tz/hash_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tz

import (
"bytes"
"encoding/hex"
"fmt"
"io"
"math/rand"
"slices"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -104,19 +104,8 @@ func prepareArch(t testing.TB, b arch) {
}
}

func newBuffer() (data []byte) {
data = make([]byte, benchDataSize)

r := rand.New(rand.NewSource(0))
_, err := io.ReadFull(r, data)
if err != nil {
panic("cant initialize buffer")
}
return
}

func BenchmarkSum(b *testing.B) {
data := newBuffer()
data := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, benchDataSize/5)

for i := range backends {
b.Run(backends[i].Name+" digest", func(b *testing.B) {
Expand All @@ -125,7 +114,7 @@ func BenchmarkSum(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
d := New()
for i := 0; i < b.N; i++ {
for range b.N {
d.Reset()
_, _ = d.Write(data)
d.Sum(nil)
Expand All @@ -136,24 +125,24 @@ func BenchmarkSum(b *testing.B) {
}

func TestHomomorphism(t *testing.T) {
const halfInputSize = 32
var (
c1, c2 sl2
n int
err error
h, h1, h2 [Size]byte
b []byte
)

b = make([]byte, 64)
n, err = rand.Read(b) //nolint:staticcheck // SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used
require.Equal(t, 64, n)
require.NoError(t, err)
b = slices.Concat(
bytes.Repeat([]byte{0x01}, halfInputSize),
bytes.Repeat([]byte{0x02}, halfInputSize),
)

// Test if our hashing is really homomorphic
h = Sum(b)
require.NotEqual(t, [64]byte{}, h)
h1 = Sum(b[:32])
h2 = Sum(b[32:])
h1 = Sum(b[:halfInputSize])
h2 = Sum(b[halfInputSize:])

err = c1.UnmarshalBinary(h1[:])
require.NoError(t, err)
Expand Down Expand Up @@ -195,7 +184,7 @@ func TestConcat(t *testing.T) {
require.NoError(t, err)

ps = make([][]byte, len(tc.Parts))
for j := 0; j < len(tc.Parts); j++ {
for j := range tc.Parts {
ps[j], err = hex.DecodeString(tc.Parts[j])
require.NoError(t, err)
}
Expand All @@ -219,7 +208,7 @@ func TestValidate(t *testing.T) {
require.NoError(t, err)

ps = make([][]byte, len(tc.Parts))
for j := 0; j < len(tc.Parts); j++ {
for j := range tc.Parts {
ps[j], _ = hex.DecodeString(tc.Parts[j])
require.NoError(t, err)
}
Expand Down
8 changes: 1 addition & 7 deletions tz/sl2_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package tz

import (
"math/rand"
"testing"
"time"

"github.com/nspcc-dev/tzhash/gf127"
"github.com/stretchr/testify/require"
)

func init() {
rand.Seed(time.Now().UnixNano()) //nolint:staticcheck // SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0
}

func random() (a *sl2) {
a = new(sl2)
a[0][0] = *gf127.Random()
Expand Down Expand Up @@ -50,7 +44,7 @@ func TestInv(t *testing.T) {
var a, b, c *sl2

c = new(sl2)
for i := 0; i < 5; i++ {
for range 5 {
a = random()
b = a.Inv()
c = c.Mul(a, b)
Expand Down

0 comments on commit baa1bc1

Please sign in to comment.