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

Updating linter version to v1.41 #237

Merged
merged 3 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions .etc/golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---
linters:
disable-all: true
enable:
# - lll
# - gocritic
# - gocognit
# - lll
# - gocritic
# - gocognit
# - interfacer (deprecated since v1.38.0)
# - scopelint (deprecated since v1.39.0)
# - golint (deprecated since v1.41.0)
- bodyclose
- deadcode
- depguard
Expand All @@ -14,15 +18,12 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- nakedret
- scopelint
- staticcheck
- structcheck
- stylecheck
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Linting
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
version: v1.41
args: --config=./.etc/golangci.yml ./...
- name: Setup Go-${{ matrix.GOVER }}
uses: actions/setup-go@v2
Expand Down
27 changes: 24 additions & 3 deletions pke/kyber/internal/common/field_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package common

import (
"crypto/rand"
"encoding/binary"
"flag"
mathRand "math/rand"
"testing"
)

Expand Down Expand Up @@ -35,9 +36,29 @@ func TestBarrettReduceFull(t *testing.T) {
}
}

func randSliceUint32WithMax(length uint, max uint32) []uint32 {
bytes := make([]uint8, 4*length)
n, err := rand.Read(bytes)
if err != nil {
panic(err)
} else if n < len(bytes) {
panic("short read from RNG")
}
x := make([]uint32, length)
for i := range x {
x[i] = binary.LittleEndian.Uint32(bytes[4*i:]) % max
}
return x
}

func TestMontReduce(t *testing.T) {
for i := 0; i < 1000; i++ {
x := mathRand.Int31n(int32(Q)*(1<<16)) - int32(Q)*(1<<15)
N := 1000
max := uint32(Q) * (1 << 16)
mid := int32(Q) * (1 << 15)
r := randSliceUint32WithMax(uint(N), max)

for i := 0; i < N; i++ {
x := int32(r[i]) - mid
y := montReduce(x)
if modQ32(x) != modQ32(int32(y)*(1<<16)) {
t.Fatalf("%d", x)
Expand Down
13 changes: 7 additions & 6 deletions pke/kyber/internal/common/ntt_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package common

import (
mathRand "math/rand"
"testing"
)
import "testing"

func BenchmarkNTT(b *testing.B) {
var a Poly
Expand Down Expand Up @@ -34,14 +31,18 @@ func BenchmarkInvNTTGeneric(b *testing.B) {
}

func (p *Poly) Rand() {
max := uint32(Q)
r := randSliceUint32WithMax(uint(N), max)
for i := 0; i < N; i++ {
p[i] = int16(mathRand.Intn(int(Q)))
p[i] = int16(r[i])
}
}

func (p *Poly) RandAbsLeQ() {
max := 2 * uint32(Q)
r := randSliceUint32WithMax(uint(N), max)
for i := 0; i < N; i++ {
p[i] = int16(mathRand.Intn(int(2*Q))) - Q
p[i] = int16(int32(r[i]) - int32(Q))
}
}

Expand Down
14 changes: 10 additions & 4 deletions pke/kyber/internal/common/poly_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package common

import (
cryptoRand "crypto/rand"
"crypto/rand"
"fmt"
mathRand "math/rand"
"testing"
)

func (p *Poly) RandAbsLe9Q() {
max := 9 * uint32(Q)
r := randSliceUint32WithMax(uint(N), max)
for i := 0; i < N; i++ {
p[i] = int16(mathRand.Intn(18*int(Q) - 9*int(Q)))
p[i] = int16(int32(r[i]))
}
}

Expand All @@ -26,7 +27,12 @@ func TestDecompressMessage(t *testing.T) {
var m, m2 [PlaintextSize]byte
var p Poly
for i := 0; i < 1000; i++ {
_, _ = cryptoRand.Read(m[:])
if n, err := rand.Read(m[:]); err != nil {
t.Error(err)
armfazh marked this conversation as resolved.
Show resolved Hide resolved
} else if n != len(m) {
t.Fatal("short read from RNG")
}

p.DecompressMessage(m[:])
p.CompressMessageTo(m2[:])
if m != m2 {
Expand Down
32 changes: 27 additions & 5 deletions sign/dilithium/internal/common/field_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package common

import (
"crypto/rand"
"encoding/binary"
"flag"
"math/rand"
"math"
"testing"
)

var runVeryLongTest = flag.Bool("very-long", false, "runs very long tests")

func randSliceUint32(length uint) []uint32 { return randSliceUint32WithMax(length, math.MaxUint32) }

func randSliceUint32WithMax(length uint, max uint32) []uint32 {
bytes := make([]uint8, 4*length)
if n, err := rand.Read(bytes); err != nil {
panic(err)
} else if n < len(bytes) {
panic("short read from RNG")
}
x := make([]uint32, length)
for i := range x {
x[i] = binary.LittleEndian.Uint32(bytes[4*i:]) % max
}
return x
}

func TestModQ(t *testing.T) {
for i := 0; i < 1000; i++ {
x := rand.Uint32()
const testTimes = 1000
cjpatton marked this conversation as resolved.
Show resolved Hide resolved
r := randSliceUint32(testTimes)
for i := 0; i < testTimes; i++ {
x := r[i]
y := modQ(x)
if y > Q {
t.Fatalf("modQ(%d) > Q", x)
Expand All @@ -22,8 +42,10 @@ func TestModQ(t *testing.T) {
}

func TestReduceLe2Q(t *testing.T) {
for i := 0; i < 1000; i++ {
x := rand.Uint32()
const testTimes = 1000
r := randSliceUint32(testTimes)
for i := 0; i < testTimes; i++ {
x := r[i]
y := reduceLe2Q(x)
if y > 2*Q {
t.Fatalf("reduce_le2q(%d) > 2Q", x)
Expand Down
11 changes: 4 additions & 7 deletions sign/dilithium/internal/common/ntt_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package common

import (
"math/rand"
"testing"
)
import "testing"

func (p *Poly) RandLe2Q() {
for i := uint(0); i < N; i++ {
p[i] = uint32(rand.Intn(int(2 * Q)))
}
max := 2 * uint32(Q)
r := randSliceUint32WithMax(N, max)
copy(p[:], r)
}

func TestNTTAgainstGeneric(t *testing.T) {
Expand Down
11 changes: 4 additions & 7 deletions sign/dilithium/internal/common/pack_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package common

import (
"math/rand"
"testing"
)
import "testing"

func TestPackLe16AgainstGeneric(t *testing.T) {
var p Poly
var buf1, buf2 [PolyLe16Size]byte

for j := 0; j < 1000; j++ {
for i := 0; i < 256; i++ {
p[i] = uint32(rand.Intn(16))
}
pp := randSliceUint32WithMax(N, 16)
copy(p[:], pp)
p.PackLe16(buf1[:])
p.packLe16Generic(buf2[:])
if buf1 != buf2 {
Expand Down
15 changes: 5 additions & 10 deletions sign/dilithium/internal/common/poly_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package common

import (
"math/rand"
"testing"
)
import "testing"

func TestExceeds(t *testing.T) {
for i := 0; i < N; i++ {
Expand Down Expand Up @@ -116,9 +113,8 @@ func TestMulHatAgainstGeneric(t *testing.T) {
func TestReduceLe2QAgainstGeneric(t *testing.T) {
for k := 0; k < 1000; k++ {
var a Poly
for j := 0; j < N; j++ {
a[j] = rand.Uint32()
}
r := randSliceUint32(N)
copy(a[:], r)
p1 := a
p2 := a
p1.reduceLe2QGeneric()
Expand All @@ -132,9 +128,8 @@ func TestReduceLe2QAgainstGeneric(t *testing.T) {
func TestNormalizeAgainstGeneric(t *testing.T) {
for k := 0; k < 1000; k++ {
var a Poly
for j := 0; j < N; j++ {
a[j] = rand.Uint32()
}
r := randSliceUint32(N)
copy(a[:], r)
p1 := a
p2 := a
p1.normalizeGeneric()
Expand Down