Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go update #46

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'
cache: true

- name: Update Go modules
Expand All @@ -55,14 +55,14 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, windows-2022 ]
go_versions: [ '1.19', '1.20', '1.21' ]
go_versions: [ '1.20', '1.21', '1.22' ]
exclude:
- os: windows-2022
go_versions: '1.19'
- os: windows-2022
go_versions: '1.20'
- os: ubuntu-20.04
- os: windows-2022
go_versions: '1.21'
- os: ubuntu-20.04
go_versions: '1.22'
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/nspcc-dev/tzhash

go 1.19
go 1.20

require (
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.12.0
golang.org/x/sys v0.17.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
4 changes: 1 addition & 3 deletions tz/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func Sum(data []byte) [Size]byte {

// Sum implements hash.Hash.
func (d *digest) Sum(in []byte) []byte {
// Make a copy of d so that caller can keep writing and summing.
d0 := *d
h := d0.checkSum()
h := d.checkSum()
return append(in, h[:]...)
}

Expand Down
15 changes: 6 additions & 9 deletions tz/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package tz

import (
"crypto/subtle"
"errors"
"fmt"
)

// Concat performs combining of hashes based on homomorphic property.
Expand All @@ -25,9 +27,8 @@ func Concat(hs [][]byte) ([]byte, error) {
// Validate checks if hashes in hs combined are equal to h.
func Validate(h []byte, hs [][]byte) (bool, error) {
var (
b []byte
got, expected [Size]byte
err error
b []byte
err error
)

if len(h) != Size {
Expand All @@ -36,16 +37,12 @@ func Validate(h []byte, hs [][]byte) (bool, error) {
return false, errors.New("empty slice")
}

copy(expected[:], h)

b, err = Concat(hs)
if err != nil {
return false, errors.New("cant concatenate hashes")
return false, fmt.Errorf("can't concatenate hashes: %w", err)
}

copy(got[:], b)

return expected == got, nil
return subtle.ConstantTimeCompare(h, b) == 1, nil
}

// SubtractR returns hash a, such that Concat(a, b) == c
Expand Down
2 changes: 1 addition & 1 deletion tz/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestHomomorphism(t *testing.T) {
)

b = make([]byte, 64)
n, err = rand.Read(b)
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)

Expand Down
2 changes: 1 addition & 1 deletion tz/sl2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func init() {
rand.Seed(time.Now().UnixNano())
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) {
Expand Down
Loading