Skip to content

Commit 3c4888a

Browse files
authored
optimize quintic extension & signing/validating signatures (#23)
1 parent 69d013a commit 3c4888a

File tree

26 files changed

+1355
-1991
lines changed

26 files changed

+1355
-1991
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
go-version: ['1.22.x', '1.23.x', '1.24.x']
15+
go-version: ['1.23.x', '1.24.x']
1616
steps:
1717
- uses: actions/checkout@v4
1818
with:
@@ -33,3 +33,25 @@ jobs:
3333
- name: Run fuzzy field tests
3434
run: |
3535
go test -tags=fuzz -fuzz=Fuzz -fuzztime=30s github.com/elliottech/poseidon_crypto/field
36+
37+
lint:
38+
name: Lint
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
ref: ${{ github.event.pull_request.head.sha }}
44+
45+
- name: Setup Go 1.23.x
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: 1.23.x
49+
50+
# TODO: update version
51+
- name: Install golangci-lint
52+
run: |
53+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
54+
55+
- name: Run golangci-lint
56+
run: |
57+
golangci-lint run ./...

.golangci.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
run:
2+
# The default concurrency value is the number of available CPU.
3+
concurrency: 4
4+
timeout: 5m
5+
6+
linters:
7+
enable:
8+
- unparam
9+
- bidichk
10+
- durationcheck
11+
- gocritic
12+
- gosec
13+
- unconvert
14+
- exhaustruct
15+
16+
linters-settings:
17+
govet:
18+
enable:
19+
- nilness
20+
disable:
21+
- composites
22+
gocritic:
23+
disabled-checks:
24+
- captLocal
25+
- ifElseChain
26+
27+
issues:
28+
max-issues-per-linter: 100
29+
max-same-issues: 100
30+
31+
exclude-rules:
32+
- path: ".*_test.go"
33+
linters:
34+
- gosec
35+
text: "G115"

curve/ecgfp5/affine_point.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ func (p *AffinePoint) SetNeg() {
3232
// i*P for i = 1 to n (win[0] contains P, win[1] contains 2*P, and
3333
// so on). Index value k is an integer in the -n to n range; returned
3434
// point is k*P.
35-
func (p *AffinePoint) SetLookup(win []AffinePoint, k int32) {
35+
func Lookup(win []AffinePoint, k int32) AffinePoint {
3636
// sign = 0xFFFFFFFF if k < 0, 0x00000000 otherwise
37-
sign := uint32(k >> 31)
37+
sign := uint32(k >> 31) //nolint:gosec
3838
// ka = abs(k)
39-
ka := (uint32(k) ^ sign) - sign
39+
ka := (uint32(k) ^ sign) - sign //nolint:gosec
4040
// km1 = ka - 1
4141
km1 := ka - 1
4242

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

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

6159
if c != 0 {
62-
p.u = gFp5.Neg(p.u)
60+
u = gFp5.Neg(u)
6361
}
64-
}
6562

66-
func Lookup(win []AffinePoint, k int32) AffinePoint {
67-
r := AFFINE_NEUTRAL
68-
r.SetLookup(win, k)
69-
return r
63+
return AffinePoint{x, u}
7064
}
7165

7266
// Same as lookup(), except this implementation is variable-time.

0 commit comments

Comments
 (0)