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

Enable linter in the CI #527

Merged
merged 82 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
52eb401
Setup golangci action
K1li4nL Feb 27, 2024
8b26390
Enable golangci-lint contextcheck
K1li4nL Feb 19, 2024
ce3e597
Add missing error handling
K1li4nL Feb 19, 2024
2d85251
Rename unused parameters
K1li4nL Feb 19, 2024
dae9ffc
ignore IDE .idea
K1li4nL Feb 19, 2024
fbd289c
Ignore interface bloat in group.go
K1li4nL Feb 19, 2024
9fc0d79
Fix some formatting
K1li4nL Feb 19, 2024
757dd4a
Add error handling
K1li4nL Feb 19, 2024
cd5d67e
Fix asalint
K1li4nL Feb 19, 2024
c3bc175
minor fixes
K1li4nL Feb 19, 2024
38d876c
Add false-positive exception
K1li4nL Feb 20, 2024
6dc12c9
Add line length exception
K1li4nL Feb 20, 2024
9ae3d4e
Correct capitalization
K1li4nL Feb 20, 2024
6fdd0f9
Fix lint issues package bn256
K1li4nL Feb 21, 2024
b7dd5ba
Fix lint issues package eddsa
K1li4nL Feb 21, 2024
a407e2d
Fix lint issues package util
K1li4nL Feb 22, 2024
ab9ecc0
Fix lint issues package keccak
K1li4nL Feb 22, 2024
c2b6dc2
Fix lint issues package int
K1li4nL Feb 22, 2024
9fb52f6
Fix lint issues package blake2x[s, b]
K1li4nL Feb 22, 2024
7779c77
Fix lint issues package curve25519
K1li4nL Feb 22, 2024
2677088
Fix lint issues package shuffle
K1li4nL Feb 23, 2024
111c5c7
Fix lint issues package dleq
K1li4nL Feb 23, 2024
1669ef3
Fix lint issues package share
K1li4nL Feb 23, 2024
3954ef5
Fix lint issues package curve25519
K1li4nL Feb 23, 2024
45a5b53
Fix lint issues package anon
K1li4nL Feb 23, 2024
3c95238
Fix lint issues package cosi
K1li4nL Feb 24, 2024
9927eaf
Fix lint issues package ecies
K1li4nL Feb 24, 2024
0a93074
Fix lint issues dkg-rabin
K1li4nL Feb 24, 2024
286e2b1
Fix most lint issues package proof
K1li4nL Feb 24, 2024
6f31be0
Fix most lint issues package nist
K1li4nL Feb 24, 2024
775cdcf
Fix lint issues sign
K1li4nL Feb 24, 2024
7f39397
Fix most lint issues share
K1li4nL Feb 24, 2024
82f8be6
Fix lint issues share
K1li4nL Feb 25, 2024
b122da6
Reduce cogn. complexity
K1li4nL Feb 25, 2024
29f5938
Fix linter issues package edwards25519
K1li4nL Feb 25, 2024
0c7007d
relax golangci rules
K1li4nL Feb 25, 2024
8923b04
Fix last linter error in group
K1li4nL Feb 25, 2024
64bbfd7
More linter fix
K1li4nL Feb 26, 2024
24c9ac7
Rename unused parameters
K1li4nL Feb 26, 2024
e394160
Divide large test
K1li4nL Feb 27, 2024
ba98be8
Fix new lint error shuffle
K1li4nL Mar 21, 2024
9053968
Fix lint error encoding
K1li4nL Mar 21, 2024
90ece0d
Make initBasePoint() a method of curve25519
K1li4nL Mar 21, 2024
cbee9c2
Fix forgotten conflict
K1li4nL May 24, 2024
712cbd9
Add back golangci rules
K1li4nL May 24, 2024
881bfdb
Add error handling
K1li4nL May 31, 2024
585b850
Remove println
K1li4nL May 31, 2024
47673af
Simplify if-else chain
K1li4nL May 31, 2024
c619822
Simplify function
K1li4nL May 31, 2024
b071528
Replace prints
K1li4nL May 31, 2024
126ac58
Remove unused
K1li4nL May 31, 2024
f0f2c02
Harmonize receivers name
K1li4nL May 31, 2024
fdbb16e
Simplify if-else
K1li4nL May 31, 2024
7de9cd4
Fix lint issue share package
K1li4nL May 31, 2024
6f87193
Ignore dup, lll and funlen for certain files
K1li4nL May 31, 2024
effe273
Lint fix for pairing package
K1li4nL May 31, 2024
215433b
Lint fix for sign package
K1li4nL May 31, 2024
d8b38c0
Lint fix curve25519
K1li4nL May 31, 2024
e56fec2
Lint fix xof package
K1li4nL May 31, 2024
67ff4a5
Update golangci rules
K1li4nL May 31, 2024
2e142d7
Better var name
K1li4nL Jun 6, 2024
adfe6eb
Add missing error handling
K1li4nL Jun 6, 2024
36ffc7b
Update golangci rules
K1li4nL Jun 11, 2024
96cf62e
Remove useless nolint
K1li4nL Jun 11, 2024
aabb0b8
ignore / fix lint errors
K1li4nL Jun 11, 2024
1530249
Allow capital var name for point convention
K1li4nL Jun 12, 2024
9f9e0f7
Make points name capital
K1li4nL Jun 12, 2024
35a55aa
Errors fix
K1li4nL Jun 12, 2024
f8d0235
Typos
K1li4nL Jun 12, 2024
496168c
Remove unused lint rules
K1li4nL Jun 12, 2024
4256cb3
Remove unnecessary checks
K1li4nL Jun 12, 2024
00b5900
Export dleq errors
K1li4nL Jun 14, 2024
b1a18ef
Rename test file
K1li4nL Jun 14, 2024
fee07a2
Export cast error
K1li4nL Jun 14, 2024
a8185f2
Wrap errors
K1li4nL Jun 14, 2024
99e4f5c
Minor refactoring
K1li4nL Jun 14, 2024
27d3630
Export errors
K1li4nL Jun 14, 2024
fe1f54f
Multiple fix
K1li4nL Jun 14, 2024
ee97c83
Fix ibe lint errors
K1li4nL Jun 14, 2024
d528c20
Add lint exceptions
K1li4nL Jun 14, 2024
872c62a
Fix mistake fe_test
K1li4nL Jun 14, 2024
5a15399
Clean up
K1li4nL Jun 14, 2024
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
32 changes: 0 additions & 32 deletions .github/workflows/go_lint.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Lint
on:
push:
branches: [ master ]
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.56.2

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ exit_tunnel
.DS_Store
*.cov
profile.tmp
Coding/
Coding/
.idea/
51 changes: 49 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ run:
# This file contains only configs which differ from defaults.
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
linters-settings:
staticcheck:
checks:
- all
- '-SA1019' # Ignore deprecated for now
cyclop:
# The maximal code complexity to report.
# Default: 10
Expand Down Expand Up @@ -93,6 +97,10 @@ linters-settings:
- G107 # variables in URLs
- G404 # use of weak random generator

gocritic:
disabled-checks:
- captLocal

linters:
disable-all: true
enable:
Expand All @@ -109,7 +117,7 @@ linters:
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
#- contextcheck # checks the function whether use a non-inherited context # TODO: enable after golangci-lint uses https://github.com/sylvia7788/contextcheck/releases/tag/v1.0.7
- contextcheck # checks the function whether use a non-inherited context
- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
- durationcheck # checks for two durations multiplied together
Expand Down Expand Up @@ -163,7 +171,7 @@ linters:
#- decorder # checks declaration order and count of types, constants, variables and functions
#- exhaustruct # checks if all structure fields are initialized
#- gci # controls golang package import order and makes it always deterministic
- godox # detects FIXME, TODO and other comment keywords
#- godox # detects FIXME, TODO and other comment keywords
#- goheader # checks is file header matches to pattern
- interfacebloat # checks the number of methods inside an interface
#- ireturn # accept interfaces, return concrete types
Expand Down Expand Up @@ -246,3 +254,42 @@ issues:
- linters:
- govet
text: "shadow: declaration of \"err\" shadows declaration"
- path: 'group.go'
linters:
- interfacebloat
- path: 'group/edwards25519/scalar.go'
linters:
- ineffassign
- funlen
- path: 'group/edwards25519/const.go'
linters:
- lll
- path: 'group/edwards25519/fe.go'
linters:
- funlen
- path: "share/dkg/pedersen"
linters:
- gocognit
- funlen
- gocyclo
- cyclop
- path: "group/edwards25519/scalar.go"
linters:
- ineffassign
- path: "pairing|group"
linters:
- revive
- stylecheck
text: "var-naming: don't use an underscore in package name|ST1003: should not use underscores in package names"
- path: "pairing/(circl_bls12381|bn254)/."
AnomalRoil marked this conversation as resolved.
Show resolved Hide resolved
linters:
- errcheck #TODO: proper error handling
text: "Error return value is not checked"
- path: "encrypt/ibe/ibe.go"
linters:
- stylecheck # Keep variable name as is
text: "var Gid should be GID|var hrGid should be hrGID|rGid should be rGID|var hGidT should be hGIDT|var GidT should be GIDT"
- path: "pairing/bls12381/circl/*|pairing/bls12381/kilic/*"
linters:
- errcheck
text: "Error return value is not checked"
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ lint: tidy
#golangci-lint run
#staticcheck go list ./...


vet: tidy
go vet ./...

Expand All @@ -24,4 +23,4 @@ coverage: tidy
# target to run all the possible checks; it's a good habit to run it before
# pushing code
check: lint vet test
echo "check done"
echo "check done"
18 changes: 9 additions & 9 deletions encrypt/ecies/ecies.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func Encrypt(group kyber.Group, public kyber.Point, message []byte, hash func()
// ephemeral key for every ECIES encryption and thus have a fresh
// HKDF-derived key for AES-GCM, the nonce for AES-GCM can be an arbitrary
// (even static) value. We derive it here simply via HKDF as well.)
len := 32 + 12
buf, err := deriveKey(hash, dh, len)
keyNonceLen := 32 + 12
buf, err := deriveKey(hash, dh, keyNonceLen)
if err != nil {
return nil, err
}
key := buf[:32]
nonce := buf[32:len]
nonce := buf[32:keyNonceLen]

// Encrypt message using AES-GCM
aes, err := aes.NewCipher(key)
Expand Down Expand Up @@ -91,13 +91,13 @@ func Decrypt(group kyber.Group, private kyber.Scalar, ctx []byte, hash func() ha

// Compute shared DH key and derive the symmetric key and nonce via HKDF
dh := group.Point().Mul(private, R)
len := 32 + 12
buf, err := deriveKey(hash, dh, len)
keyNonceLen := 32 + 12
buf, err := deriveKey(hash, dh, keyNonceLen)
if err != nil {
return nil, err
}
key := buf[:32]
nonce := buf[32:len]
nonce := buf[32:keyNonceLen]

// Decrypt message using AES-GCM
aes, err := aes.NewCipher(key)
Expand All @@ -111,18 +111,18 @@ func Decrypt(group kyber.Group, private kyber.Scalar, ctx []byte, hash func() ha
return aesgcm.Open(nil, nonce, ctx[l:], nil)
}

func deriveKey(hash func() hash.Hash, dh kyber.Point, len int) ([]byte, error) {
func deriveKey(hash func() hash.Hash, dh kyber.Point, l int) ([]byte, error) {
dhb, err := dh.MarshalBinary()
if err != nil {
return nil, err
}
hkdf := hkdf.New(hash, dhb, nil, nil)
key := make([]byte, len, len)
key := make([]byte, l)
n, err := hkdf.Read(key)
if err != nil {
return nil, err
}
if n < len {
if n < l {
return nil, errors.New("ecies: hkdf-derived key too short")
}
return key, nil
Expand Down
24 changes: 14 additions & 10 deletions encrypt/ibe/ibe.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func H4Tag() []byte {
// - msg is the actual message
// - seed is the random seed to generate the random element (sigma) of the encryption
// The suite must produce points which implements the `HashablePoint` interface.
//
//nolint:dupl // unavoidable
func EncryptCCAonG1(s pairing.Suite, master kyber.Point, ID, msg []byte) (*Ciphertext, error) {
if len(msg) > s.Hash().Size() {
return nil, errors.New("plaintext too long for the hash function provided")
Expand All @@ -62,7 +64,7 @@ func EncryptCCAonG1(s pairing.Suite, master kyber.Point, ID, msg []byte) (*Ciphe
// 2. Derive random sigma
sigma := make([]byte, len(msg))
if _, err := rand.Read(sigma); err != nil {
return nil, fmt.Errorf("err reading rand sigma: %v", err)
return nil, fmt.Errorf("err reading rand sigma: %w", err)
}
// 3. Derive r from sigma and msg
r, err := h3(s, sigma, msg)
Expand Down Expand Up @@ -141,23 +143,25 @@ func DecryptCCAonG1(s pairing.Suite, private kyber.Point, c *Ciphertext) ([]byte
// - msg is the actual message
// - seed is the random seed to generate the random element (sigma) of the encryption
// The suite must produce points which implements the `HashablePoint` interface.
//
//nolint:dupl // unavoidable
func EncryptCCAonG2(s pairing.Suite, master kyber.Point, ID, msg []byte) (*Ciphertext, error) {
if len(msg) > s.Hash().Size() {
return nil, errors.New("plaintext too long for the hash function provided")
}

// 1. Compute Gid = e(Q_id, master)
hG2, ok := s.G1().Point().(kyber.HashablePoint)
hG1, ok := s.G1().Point().(kyber.HashablePoint)
if !ok {
return nil, errors.New("point needs to implement `kyber.HashablePoint`")
}
Qid := hG2.Hash(ID)
Qid := hG1.Hash(ID)
Gid := s.Pair(Qid, master)

// 2. Derive random sigma
sigma := make([]byte, len(msg))
if _, err := rand.Read(sigma); err != nil {
return nil, fmt.Errorf("err reading rand sigma: %v", err)
return nil, fmt.Errorf("err reading rand sigma: %w", err)
}
// 3. Derive r from sigma and msg
r, err := h3(s, sigma, msg)
Expand Down Expand Up @@ -231,10 +235,10 @@ func h3(s pairing.Suite, sigma, msg []byte) (kyber.Scalar, error) {
h := s.Hash()

if _, err := h.Write(H3Tag()); err != nil {
return nil, fmt.Errorf("err hashing h3 tag: %v", err)
return nil, fmt.Errorf("err hashing h3 tag: %w", err)
}
if _, err := h.Write(sigma); err != nil {
return nil, fmt.Errorf("err hashing sigma: %v", err)
return nil, fmt.Errorf("err hashing sigma: %w", err)
}
_, _ = h.Write(msg)
// we hash it a first time: buffer = hash("IBE-H3" || sigma || msg)
Expand All @@ -258,7 +262,7 @@ func h3(s pairing.Suite, sigma, msg []byte) (kyber.Scalar, error) {
// but we assume that toMask is a few bits, at most 8.
// For instance when using BLS12-381 toMask == 1.
if hashable.ByteOrder() == kyber.BigEndian {
hashed[0] = hashed[0] >> toMask
hashed[0] >>= toMask
} else {
hashed[len(hashed)-1] = hashed[len(hashed)-1] >> toMask
}
Expand All @@ -280,10 +284,10 @@ func h4(s pairing.Suite, sigma []byte, length int) ([]byte, error) {
h4 := s.Hash()

if _, err := h4.Write(H4Tag()); err != nil {
return nil, fmt.Errorf("err writing h4tag: %v", err)
return nil, fmt.Errorf("err writing h4tag: %w", err)
}
if _, err := h4.Write(sigma); err != nil {
return nil, fmt.Errorf("err writing sigma to h4: %v", err)
return nil, fmt.Errorf("err writing sigma to h4: %w", err)
}
h4sigma := h4.Sum(nil)[:length]

Expand All @@ -305,7 +309,7 @@ func gtToHash(s pairing.Suite, gt kyber.Point, length int) ([]byte, error) {
if _, err := hashReader.Read(b); err != nil {
return nil, errors.New("couldn't read from hash output")
}
return b[:], nil
return b, nil
}

func xor(a, b []byte) []byte {
Expand Down
3 changes: 2 additions & 1 deletion group/edwards25519/const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package edwards25519

import (
Expand Down Expand Up @@ -44,6 +43,7 @@ var sqrtM1 = fieldElement{
-32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482,
}

//nolint:unused // May be used later
var paramA = fieldElement{
486662, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}
Expand All @@ -55,6 +55,7 @@ var baseext = extendedGroupElement{
fieldElement{6966464, -2456167, 7033433, 6781840, 28785542, 12262365, -2659449, 13959020, -21013759, -5262166},
}

//nolint:unused // May be used later
var bi = [8]preComputedGroupElement{
{
fieldElement{25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605},
Expand Down
4 changes: 2 additions & 2 deletions group/edwards25519/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func (c *Curve) Point() kyber.Point {
// requiring it to be a multiple of 8). It also returns the input and the digest used
// to generate the key.
func (c *Curve) NewKeyAndSeedWithInput(buffer []byte) (kyber.Scalar, []byte, []byte) {
digest := sha512.Sum512(buffer[:])
digest := sha512.Sum512(buffer)
digest[0] &= 0xf8
digest[31] &= 0x7f
digest[31] |= 0x40

secret := c.Scalar().(*scalar)
secret := c.Scalar().(*scalar) //nolint:errcheck // V4 may bring better error handling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like either a TODO, or an issue that should be created, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy(secret.v[:], digest[:])
return secret, buffer, digest[32:]
}
Expand Down
3 changes: 1 addition & 2 deletions group/edwards25519/fe.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package edwards25519

import (
Expand Down Expand Up @@ -78,7 +77,7 @@ func load4(in []byte) int64 {
}

func feFromBytes(dst *fieldElement, src []byte) {
h0 := load4(src[:])
h0 := load4(src)
h1 := load3(src[4:]) << 6
h2 := load3(src[7:]) << 5
h3 := load3(src[10:]) << 3
Expand Down
Loading
Loading