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 #498

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
92f9ab0
Add golangci-lint
K1li4nL Feb 16, 2024
bf910d7
Add golangci-lint install in Makefile
K1li4nL Feb 16, 2024
67e5ba2
Hide golangci install command in logs
K1li4nL Feb 16, 2024
5ab9200
Enable golangci-lint contextcheck
K1li4nL Feb 19, 2024
544ec0f
Add missing error handling
K1li4nL Feb 19, 2024
8dcd61d
Rename unused parameters
K1li4nL Feb 19, 2024
342d3c5
ignore IDE .idea
K1li4nL Feb 19, 2024
282feb4
Ignore interface bloat in group.go
K1li4nL Feb 19, 2024
9f82f49
Fix some formatting
K1li4nL Feb 19, 2024
43864ca
Add error handling
K1li4nL Feb 19, 2024
5f6afd7
Fix asalint
K1li4nL Feb 19, 2024
1fe1527
minor fixes
K1li4nL Feb 19, 2024
c144a8e
Add false-positive exception
K1li4nL Feb 20, 2024
56874b3
Add line length exception
K1li4nL Feb 20, 2024
3149ecf
Correct capitalization
K1li4nL Feb 20, 2024
fae7ebf
Fix lint issues package bn256
K1li4nL Feb 21, 2024
72e8157
Fix lint issues package eddsa
K1li4nL Feb 21, 2024
6959397
Fix lint issues package pvss
K1li4nL Feb 21, 2024
0dabcf6
Fix lint issues package util
K1li4nL Feb 22, 2024
e479300
Fix lint issues package keccak
K1li4nL Feb 22, 2024
41aa552
Fix lint issues package int
K1li4nL Feb 22, 2024
3bc58d4
Fix lint issues package blake2x[s, b]
K1li4nL Feb 22, 2024
e58a5ff
Fix lint issues package curve25519
K1li4nL Feb 22, 2024
a69ac4c
Fix lint issues package shuffle
K1li4nL Feb 23, 2024
da38859
Fix lint issues package dleq
K1li4nL Feb 23, 2024
b82af93
Fix lint issues package share
K1li4nL Feb 23, 2024
9827768
Fix lint issues package curve25519
K1li4nL Feb 23, 2024
b1504e1
Fix lint issues package anon
K1li4nL Feb 23, 2024
c1b4c40
Fix lint issues package cosi
K1li4nL Feb 24, 2024
dfb7d27
Fix lint issues package ecies
K1li4nL Feb 24, 2024
891fbf0
Fix lint issues dkg-rabin
K1li4nL Feb 24, 2024
5daa04b
Fix most lint issues package proof
K1li4nL Feb 24, 2024
be595d3
Fix most lint issues package nist
K1li4nL Feb 24, 2024
11c203b
Fix lint issues sign
K1li4nL Feb 24, 2024
440649d
Fix most lint issues share
K1li4nL Feb 24, 2024
5149a1f
Fix lint issues share
K1li4nL Feb 25, 2024
d551b65
Reduce cogn. complexity
K1li4nL Feb 25, 2024
755961d
Fix linter issues package edwards25519
K1li4nL Feb 25, 2024
225d36c
relax golangci rules
K1li4nL Feb 25, 2024
4db0c56
Fix last linter error in group
K1li4nL Feb 25, 2024
ee2f9c7
More linter fix
K1li4nL Feb 26, 2024
f05993e
Rename unused parameters
K1li4nL Feb 26, 2024
f9fa357
Setup golangci action
K1li4nL Feb 27, 2024
1f7b472
Divide large test
K1li4nL Feb 27, 2024
f5fcf0e
Fix new lint error shuffle
K1li4nL Mar 21, 2024
67df27b
Fix lint error encoding
K1li4nL Mar 21, 2024
798e66a
Make initBasePoint() a method of curve25519
K1li4nL Mar 21, 2024
0adfea0
Fix forgotten conflict
K1li4nL May 24, 2024
7cd82b7
Add back golangci rules
K1li4nL May 24, 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/
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,3 @@ issues:
- linters:
- govet
text: "shadow: declaration of \"err\" shadows declaration"
- path: ".*_decl.go"
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ generate: tidy

# Coding style static check.
lint: tidy
@echo "Please setup a linter!"
#golangci-lint run
#staticcheck go list ./...

golangci-lint run

vet: tidy
go vet ./...
Expand Down
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)
l := 32 + 12
buf, err := deriveKey(hash, dh, l)
if err != nil {
return nil, err
}
key := buf[:32]
nonce := buf[32:len]
nonce := buf[32:l]

// 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)
length := 32 + 12
buf, err := deriveKey(hash, dh, length)
if err != nil {
return nil, err
}
key := buf[:32]
nonce := buf[32:len]
nonce := buf[32:length]

// 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
98 changes: 48 additions & 50 deletions group/curve25519/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,41 @@ func (c *curve) NewKey(stream cipher.Stream) kyber.Scalar {
return secret
}

func (c *curve) initBasePoint(self kyber.Group, p *Param, fullGroup bool, base point) {
var bx, by *big.Int
if fullGroup {
bx, by = &p.FBX, &p.FBY
base.initXY(&p.FBX, &p.FBY, self)
} else {
bx, by = &p.PBX, &p.PBY
}

if by.Sign() == 0 {
// No standard base point was defined, so pick one.
// Find the lowest-numbered y-coordinate that works.
var x, y mod.Int
for y.Init64(2, &c.P); ; y.Add(&y, &c.one) {
if !c.solveForX(&x, &y) {
continue // try another y
}
if c.coordSign(&x) != 0 {
x.Neg(&x) // try positive x first
}
base.initXY(&x.V, &y.V, self)
if c.validPoint(base) {
break // got one
}
x.Neg(&x) // try -bx
if c.validPoint(base) {
break // got one
}
}

bx, by = &x.V, &y.V
}
base.initXY(bx, by, self)
}

// Initialize a twisted Edwards curve with given parameters.
// Caller passes pointers to null and base point prototypes to be initialized.
func (c *curve) init(self kyber.Group, p *Param, fullGroup bool,
Expand All @@ -101,10 +136,10 @@ func (c *curve) init(self kyber.Group, p *Param, fullGroup bool,
// Note that we do NOT initialize c.order with Init(),
// as that would normalize to the modulus, resulting in zero.
// Just to be sure it's never used, we leave c.order.M set to nil.
// We want it to be in a ModInt so we can pass it to P.Mul(),
// We want it to be in a ModInt, so we can pass it to P.Mul(),
// but the scalar's modulus isn't needed for point multiplication.
if fullGroup {
// Scalar modulus is prime-order times the ccofactor
// Scalar modulus is prime-order times the cofactor
c.order.V.SetInt64(int64(p.R)).Mul(&c.order.V, &p.Q)
} else {
c.order.V.Set(&p.Q) // Prime-order subgroup
Expand All @@ -118,39 +153,7 @@ func (c *curve) init(self kyber.Group, p *Param, fullGroup bool,
null.initXY(zero, one, self)

// Base point B
var bx, by *big.Int
if !fullGroup {
bx, by = &p.PBX, &p.PBY
} else {
bx, by = &p.FBX, &p.FBY
base.initXY(&p.FBX, &p.FBY, self)
}
if by.Sign() == 0 {
// No standard base point was defined, so pick one.
// Find the lowest-numbered y-coordinate that works.
//println("Picking base point:")
var x, y mod.Int
for y.Init64(2, &c.P); ; y.Add(&y, &c.one) {
if !c.solveForX(&x, &y) {
continue // try another y
}
if c.coordSign(&x) != 0 {
x.Neg(&x) // try positive x first
}
base.initXY(&x.V, &y.V, self)
if c.validPoint(base) {
break // got one
}
x.Neg(&x) // try -bx
if c.validPoint(base) {
break // got one
}
}
//println("BX: "+x.V.String())
//println("BY: "+y.V.String())
bx, by = &x.V, &y.V
}
base.initXY(bx, by, self)
c.initBasePoint(self, p, fullGroup, base)

// Sanity checks
if !c.validPoint(null) {
Expand Down Expand Up @@ -209,7 +212,6 @@ func (c *curve) encodePoint(x, y *mod.Int) []byte {
func (c *curve) decodePoint(bb []byte, x, y *mod.Int) error {

// Convert from little-endian
//fmt.Printf("decoding:\n%s\n", hex.Dump(bb))
b := make([]byte, len(bb))
reverse(b, bb)

Expand Down Expand Up @@ -267,22 +269,19 @@ func (c *curve) onCurve(x, y *mod.Int) bool {

// Sanity-check a point to ensure that it is on the curve
// and within the appropriate subgroup.
func (c *curve) validPoint(P point) bool {
func (c *curve) validPoint(p point) bool {

// Check on-curve
x, y := P.getXY()
x, y := p.getXY()
if !c.onCurve(x, y) {
return false
}

// Check in-subgroup by multiplying by subgroup order
Q := c.self.Point()
Q.Mul(&c.order, P)
if !Q.Equal(c.null) {
return false
}
Q.Mul(&c.order, p)

return true
return Q.Equal(c.null)
}

// Return number of bytes that can be embedded into points on this curve.
Expand All @@ -295,7 +294,7 @@ func (c *curve) embedLen() int {

// Pick a [pseudo-]random curve point with optional embedded data,
// filling in the point's x,y coordinates
func (c *curve) embed(P point, data []byte, rand cipher.Stream) {
func (c *curve) embed(p point, data []byte, rand cipher.Stream) {

// How much data to embed?
dl := c.embedLen()
Expand Down Expand Up @@ -334,7 +333,7 @@ func (c *curve) embed(P point, data []byte, rand cipher.Stream) {
}

// Initialize the point
P.initXY(&x.V, &y.V, c.self)
p.initXY(&x.V, &y.V, c.self)
if c.full {
// If we're using the full group,
// we just need any point on the curve, so we're done.
Expand All @@ -347,8 +346,8 @@ func (c *curve) embed(P point, data []byte, rand cipher.Stream) {
// we can convert our point into one in the subgroup
// simply by multiplying it by the cofactor.
if data == nil {
P.Mul(&c.cofact, P) // multiply by cofactor
if P.Equal(c.null) {
p.Mul(&c.cofact, p) // multiply by cofactor
if p.Equal(c.null) {
continue // unlucky; try again
}
return
Expand All @@ -360,7 +359,7 @@ func (c *curve) embed(P point, data []byte, rand cipher.Stream) {
if Q == nil {
Q = c.self.Point()
}
Q.Mul(&c.order, P)
Q.Mul(&c.order, p)
if Q.Equal(c.null) {
return
}
Expand All @@ -383,12 +382,11 @@ func (c *curve) data(x, y *mod.Int) ([]byte, error) {
// reverse copies src into dst in byte-reversed order and returns dst,
// such that src[0] goes into dst[len-1] and vice versa.
// dst and src may be the same slice but otherwise must not overlap.
func reverse(dst, src []byte) []byte {
func reverse(dst, src []byte) {
l := len(dst)
for i, j := 0, l-1; i < (l+1)/2; {
dst[i], dst[j] = src[j], src[i]
i++
j--
}
return dst
}
Loading
Loading