Skip to content
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
24 changes: 23 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.22.x', '1.23.x', '1.24.x']
go-version: ['1.23.x', '1.24.x']
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -33,3 +33,25 @@ jobs:
- name: Run fuzzy field tests
run: |
go test -tags=fuzz -fuzz=Fuzz -fuzztime=30s github.com/elliottech/poseidon_crypto/field

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Go 1.23.x
uses: actions/setup-go@v5
with:
go-version: 1.23.x

# TODO: update version
- name: Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0

- name: Run golangci-lint
run: |
golangci-lint run ./...
35 changes: 35 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
run:
# The default concurrency value is the number of available CPU.
concurrency: 4
timeout: 5m

linters:
enable:
- unparam
- bidichk
- durationcheck
- gocritic
- gosec
- unconvert
- exhaustruct

linters-settings:
govet:
enable:
- nilness
disable:
- composites
gocritic:
disabled-checks:
- captLocal
- ifElseChain

issues:
max-issues-per-linter: 100
max-same-issues: 100

exclude-rules:
- path: ".*_test.go"
linters:
- gosec
text: "G115"
18 changes: 6 additions & 12 deletions curve/ecgfp5/affine_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ func (p *AffinePoint) SetNeg() {
// i*P for i = 1 to n (win[0] contains P, win[1] contains 2*P, and
// so on). Index value k is an integer in the -n to n range; returned
// point is k*P.
func (p *AffinePoint) SetLookup(win []AffinePoint, k int32) {
func Lookup(win []AffinePoint, k int32) AffinePoint {
// sign = 0xFFFFFFFF if k < 0, 0x00000000 otherwise
sign := uint32(k >> 31)
sign := uint32(k >> 31) //nolint:gosec
// ka = abs(k)
ka := (uint32(k) ^ sign) - sign
ka := (uint32(k) ^ sign) - sign //nolint:gosec
// km1 = ka - 1
km1 := ka - 1

x := gFp5.FP5_ZERO
u := gFp5.FP5_ZERO
for i := 0; i < len(win); i++ {
m := km1 - uint32(i)
m := km1 - uint32(i) //nolint:gosec
c_1 := (m | (^m + 1)) >> 31
c := uint64(c_1) - 1
if c != 0 {
Expand All @@ -55,18 +55,12 @@ func (p *AffinePoint) SetLookup(win []AffinePoint, k int32) {

// If k < 0, then we must negate the point.
c := uint64(sign) | (uint64(sign) << 32)
p.x = x
p.u = u

if c != 0 {
p.u = gFp5.Neg(p.u)
u = gFp5.Neg(u)
}
}

func Lookup(win []AffinePoint, k int32) AffinePoint {
r := AFFINE_NEUTRAL
r.SetLookup(win, k)
return r
return AffinePoint{x, u}
}

// Same as lookup(), except this implementation is variable-time.
Expand Down
Loading