Skip to content

Commit 6988b53

Browse files
committed
Format templates using gtfmt tool
1 parent 9c69f9f commit 6988b53

File tree

14 files changed

+173
-173
lines changed

14 files changed

+173
-173
lines changed

dh/sidh/internal/templates/arith_decl.gotemp

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//go:build {{if .OPT_ARM}}({{end}}amd64 && !noasm{{if .OPT_ARM}}) || (arm64 && !noasm){{end}}
55
// +build amd64,!noasm{{if .OPT_ARM}} arm64,!noasm{{end}}
66

7-
package {{ .PACKAGE}}
7+
package {{.PACKAGE}}
88

99
import (
1010
. "github.com/cloudflare/circl/dh/sidh/internal/common"
@@ -14,39 +14,39 @@ import (
1414
// If choice is neither 0 nor 1 then behaviour is undefined.
1515
// This function executes in constant time.
1616
//go:noescape
17-
func cmov{{ .FIELD}}(x, y *Fp, choice uint8)
17+
func cmov{{.FIELD}}(x, y *Fp, choice uint8)
1818

1919
// If choice = 0, leave x,y unchanged. If choice = 1, set x,y = y,x.
2020
// If choice is neither 0 nor 1 then behaviour is undefined.
2121
// This function executes in constant time.
2222
//go:noescape
23-
func cswap{{ .FIELD}}(x, y *Fp, choice uint8)
23+
func cswap{{.FIELD}}(x, y *Fp, choice uint8)
2424

2525
// Compute z = x + y (mod p).
2626
//go:noescape
27-
func add{{ .FIELD}}(z, x, y *Fp)
27+
func add{{.FIELD}}(z, x, y *Fp)
2828

2929
// Compute z = x - y (mod p).
3030
//go:noescape
31-
func sub{{ .FIELD}}(z, x, y *Fp)
31+
func sub{{.FIELD}}(z, x, y *Fp)
3232

3333
// Compute z = x + y, without reducing mod p.
3434
//go:noescape
35-
func adl{{ .FIELD}}(z, x, y *FpX2)
35+
func adl{{.FIELD}}(z, x, y *FpX2)
3636

3737
// Compute z = x - y, without reducing mod p.
3838
//go:noescape
39-
func sul{{ .FIELD}}(z, x, y *FpX2)
39+
func sul{{.FIELD}}(z, x, y *FpX2)
4040

4141
// Reduce a field element in [0, 2*p) to one in [0,p).
4242
//go:noescape
43-
func mod{{ .FIELD}}(x *Fp)
43+
func mod{{.FIELD}}(x *Fp)
4444

4545
// Computes z = x * y.
4646
//go:noescape
47-
func mul{{ .FIELD}}(z *FpX2, x, y *Fp)
47+
func mul{{.FIELD}}(z *FpX2, x, y *Fp)
4848

4949
// Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value
5050
// of x may be changed. z=x not allowed.
5151
//go:noescape
52-
func rdc{{ .FIELD}}(z *Fp, x *FpX2)
52+
func rdc{{.FIELD}}(z *Fp, x *FpX2)

dh/sidh/internal/templates/arith_generic.gotemp

+22-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//go:build {{if .OPT_ARM}}noasm || (!amd64 && !arm64){{else}}noasm || !amd64{{end}}
55
// +build {{if .OPT_ARM}}noasm !amd64,!arm64{{else}}noasm !amd64{{end}}
66

7-
package {{ .PACKAGE}}
7+
package {{.PACKAGE}}
88

99
import (
1010
"math/bits"
@@ -13,30 +13,30 @@ import (
1313
)
1414

1515
// Compute z = x + y (mod p).
16-
func add{{ .FIELD }}(z, x, y *common.Fp) {
16+
func add{{.FIELD}}(z, x, y *common.Fp) {
1717
var carry uint64
1818

19-
// z=x+y % {{ .FIELD }}
19+
// z=x+y % {{.FIELD}}
2020
for i := 0; i < FpWords; i++ {
2121
z[i], carry = bits.Add64(x[i], y[i], carry)
2222
}
2323

24-
// z = z - {{ .FIELD}}x2
24+
// z = z - {{.FIELD}}x2
2525
carry = 0
2626
for i := 0; i < FpWords; i++ {
27-
z[i], carry = bits.Sub64(z[i], {{ .FIELD}}x2[i], carry)
27+
z[i], carry = bits.Sub64(z[i], {{.FIELD}}x2[i], carry)
2828
}
2929

30-
// if z<0 add {{ .FIELD}}x2 back
30+
// if z<0 add {{.FIELD}}x2 back
3131
mask := uint64(0 - carry)
3232
carry = 0
3333
for i := 0; i < FpWords; i++ {
34-
z[i], carry = bits.Add64(z[i], {{ .FIELD}}x2[i]&mask, carry)
34+
z[i], carry = bits.Add64(z[i], {{.FIELD}}x2[i]&mask, carry)
3535
}
3636
}
3737

3838
// Compute z = x - y (mod p).
39-
func sub{{ .FIELD }}(z, x, y *common.Fp) {
39+
func sub{{.FIELD}}(z, x, y *common.Fp) {
4040
var borrow uint64
4141

4242
for i := 0; i < FpWords; i++ {
@@ -47,14 +47,14 @@ func sub{{ .FIELD }}(z, x, y *common.Fp) {
4747
borrow = 0
4848

4949
for i := 0; i < FpWords; i++ {
50-
z[i], borrow = bits.Add64(z[i], {{ .FIELD}}x2[i]&mask, borrow)
50+
z[i], borrow = bits.Add64(z[i], {{.FIELD}}x2[i]&mask, borrow)
5151
}
5252
}
5353

5454
// If choice = 0, leave x unchanged. If choice = 1, sets x to y.
5555
// If choice is neither 0 nor 1 then behaviour is undefined.
5656
// This function executes in constant time.
57-
func cmov{{ .FIELD }}(x, y *common.Fp, choice uint8) {
57+
func cmov{{.FIELD}}(x, y *common.Fp, choice uint8) {
5858
mask := 0 - uint64(choice)
5959
for i := 0; i < FpWords; i++ {
6060
x[i] ^= mask & (x[i] ^ y[i])
@@ -66,7 +66,7 @@ func cmov{{ .FIELD }}(x, y *common.Fp, choice uint8) {
6666
// For details see "Hackers Delight, 2.20"
6767
//
6868
// Implementation doesn't actually depend on a prime field.
69-
func cswap{{ .FIELD }}(x, y *common.Fp, mask uint8) {
69+
func cswap{{.FIELD}}(x, y *common.Fp, mask uint8) {
7070
var tmp, mask64 uint64
7171

7272
mask64 = 0 - uint64(mask)
@@ -79,17 +79,17 @@ func cswap{{ .FIELD }}(x, y *common.Fp, mask uint8) {
7979

8080
// Perform Montgomery reduction: set z = x R^{-1} (mod 2*p)
8181
// with R=2^(FpWords*64). Destroys the input value.
82-
func rdc{{ .FIELD }}(z *common.Fp, x *common.FpX2) {
82+
func rdc{{.FIELD}}(z *common.Fp, x *common.FpX2) {
8383
var carry, t, u, v uint64
8484
var hi, lo uint64
8585
var count int
8686

87-
count = {{ .FIELD}}p1Zeros
87+
count = {{.FIELD}}p1Zeros
8888

8989
for i := 0; i < FpWords; i++ {
9090
for j := 0; j < i; j++ {
9191
if j < (i - count + 1) {
92-
hi, lo = bits.Mul64(z[j], {{ .FIELD }}p1[i-j])
92+
hi, lo = bits.Mul64(z[j], {{.FIELD}}p1[i-j])
9393
v, carry = bits.Add64(lo, v, 0)
9494
u, carry = bits.Add64(hi, u, carry)
9595
t += carry
@@ -111,7 +111,7 @@ func rdc{{ .FIELD }}(z *common.Fp, x *common.FpX2) {
111111
}
112112
for j := i - FpWords + 1; j < FpWords; j++ {
113113
if j < (FpWords - count) {
114-
hi, lo = bits.Mul64(z[j], {{ .FIELD }}p1[i-j])
114+
hi, lo = bits.Mul64(z[j], {{.FIELD}}p1[i-j])
115115
v, carry = bits.Add64(lo, v, 0)
116116
u, carry = bits.Add64(hi, u, carry)
117117
t += carry
@@ -131,7 +131,7 @@ func rdc{{ .FIELD }}(z *common.Fp, x *common.FpX2) {
131131
}
132132

133133
// Compute z = x * y.
134-
func mul{{ .FIELD }}(z *common.FpX2, x, y *common.Fp) {
134+
func mul{{.FIELD}}(z *common.FpX2, x, y *common.Fp) {
135135
var u, v, t uint64
136136
var hi, lo uint64
137137
var carry uint64
@@ -165,30 +165,30 @@ func mul{{ .FIELD }}(z *common.FpX2, x, y *common.Fp) {
165165
}
166166

167167
// Compute z = x + y, without reducing mod p.
168-
func adl{{ .FIELD }}(z, x, y *common.FpX2) {
168+
func adl{{.FIELD}}(z, x, y *common.FpX2) {
169169
var carry uint64
170170
for i := 0; i < 2*FpWords; i++ {
171171
z[i], carry = bits.Add64(x[i], y[i], carry)
172172
}
173173
}
174174

175175
// Reduce a field element in [0, 2*p) to one in [0,p).
176-
func mod{{ .FIELD }}(x *common.Fp) {
176+
func mod{{.FIELD}}(x *common.Fp) {
177177
var borrow, mask uint64
178178
for i := 0; i < FpWords; i++ {
179-
x[i], borrow = bits.Sub64(x[i], {{ .FIELD }}[i], borrow)
179+
x[i], borrow = bits.Sub64(x[i], {{.FIELD}}[i], borrow)
180180
}
181181

182182
// Sets all bits if borrow = 1
183183
mask = 0 - borrow
184184
borrow = 0
185185
for i := 0; i < FpWords; i++ {
186-
x[i], borrow = bits.Add64(x[i], {{ .FIELD }}[i]&mask, borrow)
186+
x[i], borrow = bits.Add64(x[i], {{.FIELD}}[i]&mask, borrow)
187187
}
188188
}
189189

190190
// Compute z = x - y, without reducing mod p.
191-
func sul{{ .FIELD }}(z, x, y *common.FpX2) {
191+
func sul{{.FIELD}}(z, x, y *common.FpX2) {
192192
var borrow, mask uint64
193193
for i := 0; i < 2*FpWords; i++ {
194194
z[i], borrow = bits.Sub64(x[i], y[i], borrow)
@@ -198,6 +198,6 @@ func sul{{ .FIELD }}(z, x, y *common.FpX2) {
198198
mask = 0 - borrow
199199
borrow = 0
200200
for i := FpWords; i < 2*FpWords; i++ {
201-
z[i], borrow = bits.Add64(z[i], {{ .FIELD }}[i-FpWords]&mask, borrow)
201+
z[i], borrow = bits.Add64(z[i], {{.FIELD}}[i-FpWords]&mask, borrow)
202202
}
203203
}

dh/sidh/internal/templates/arith_test.gotemp

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Code generated by go generate; DO NOT EDIT.
22
// This file was generated by robots.
33

4-
package {{ .PACKAGE}}
4+
package {{.PACKAGE}}
55

66
import (
77
"testing"
@@ -26,14 +26,14 @@ func TestFpCswap(t *testing.T) {
2626
x := one
2727
y := two
2828

29-
cswap{{ .FIELD}}(&x, &y, 0)
29+
cswap{{.FIELD}}(&x, &y, 0)
3030
for i := 0; i < FpWords; i++ {
3131
if (x[i] != one[i]) || (y[i] != two[i]) {
3232
t.Error("Found", x, "expected", one)
3333
}
3434
}
3535

36-
cswap{{ .FIELD}}(&x, &y, 1)
36+
cswap{{.FIELD}}(&x, &y, 1)
3737
for i := 0; i < FpWords; i++ {
3838
if (x[i] != two[i]) || (y[i] != one[i]) {
3939
t.Error("Found", x, "expected", two)
@@ -48,7 +48,7 @@ func TestFpCmov(t *testing.T) {
4848
x := one
4949
y := two
5050

51-
cmov{{ .FIELD}}(&x, &y, 0)
51+
cmov{{.FIELD}}(&x, &y, 0)
5252
for i := 0; i < FpWords; i++ {
5353
if x[i] != one[i] {
5454
t.Error("Found", x, "expected", one)
@@ -58,7 +58,7 @@ func TestFpCmov(t *testing.T) {
5858
}
5959
}
6060

61-
cmov{{ .FIELD}}(&x, &y, 1)
61+
cmov{{.FIELD}}(&x, &y, 1)
6262
for i := 0; i < FpWords; i++ {
6363
if x[i] != two[i] {
6464
t.Error("Found", x, "expected", two)
@@ -72,58 +72,58 @@ func TestFpCmov(t *testing.T) {
7272
// Benchmarking for field arithmetic
7373
func BenchmarkMul(b *testing.B) {
7474
for n := 0; n < b.N; n++ {
75-
mul{{ .FIELD}}(&benchmarkFpX2, &bench_x, &bench_y)
75+
mul{{.FIELD}}(&benchmarkFpX2, &bench_x, &bench_y)
7676
}
7777
}
7878

7979
func BenchmarkRdc(b *testing.B) {
8080
z := bench_z
8181

8282
// This benchmark actually computes garbage, because
83-
// rdc{{ .FIELD}} mangles its input, but since it's
83+
// rdc{{.FIELD}} mangles its input, but since it's
8484
// constant-time that shouldn't matter for the benchmarks.
8585
for n := 0; n < b.N; n++ {
86-
rdc{{ .FIELD}}(&benchmarkFp, &z)
86+
rdc{{.FIELD}}(&benchmarkFp, &z)
8787
}
8888
}
8989

9090
func BenchmarkAdd(b *testing.B) {
9191
for n := 0; n < b.N; n++ {
92-
add{{ .FIELD}}(&benchmarkFp, &bench_x, &bench_y)
92+
add{{.FIELD}}(&benchmarkFp, &bench_x, &bench_y)
9393
}
9494
}
9595

9696
func BenchmarkSub(b *testing.B) {
9797
for n := 0; n < b.N; n++ {
98-
sub{{ .FIELD}}(&benchmarkFp, &bench_x, &bench_y)
98+
sub{{.FIELD}}(&benchmarkFp, &bench_x, &bench_y)
9999
}
100100
}
101101

102102
func BenchmarkCswap(b *testing.B) {
103103
x, y := bench_x, bench_y
104104
for n := 0; n < b.N; n++ {
105-
cswap{{ .FIELD}}(&x, &y, 1)
106-
cswap{{ .FIELD}}(&x, &y, 0)
105+
cswap{{.FIELD}}(&x, &y, 1)
106+
cswap{{.FIELD}}(&x, &y, 0)
107107
}
108108
}
109109

110110
func BenchmarkMod(b *testing.B) {
111111
x := bench_x
112112
for n := 0; n < b.N; n++ {
113-
mod{{ .FIELD}}(&x)
113+
mod{{.FIELD}}(&x)
114114
}
115115
}
116116

117117
func BenchmarkX2AddLazy(b *testing.B) {
118118
x, y, z := bench_z, bench_z, bench_z
119119
for n := 0; n < b.N; n++ {
120-
adl{{ .FIELD}}(&x, &y, &z)
120+
adl{{.FIELD}}(&x, &y, &z)
121121
}
122122
}
123123

124124
func BenchmarkX2SubLazy(b *testing.B) {
125125
x, y, z := bench_z, bench_z, bench_z
126126
for n := 0; n < b.N; n++ {
127-
sul{{ .FIELD}}(&x, &y, &z)
127+
sul{{.FIELD}}(&x, &y, &z)
128128
}
129129
}

dh/sidh/internal/templates/core.gotemp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Code generated by go generate; DO NOT EDIT.
22
// This file was generated by robots.
33

4-
package {{ .PACKAGE}}
4+
package {{.PACKAGE}}
55

66
import (
77
crand "crypto/rand"

dh/sidh/internal/templates/curve.gotemp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Code generated by go generate; DO NOT EDIT.
22
// This file was generated by robots.
33

4-
package {{ .PACKAGE}}
4+
package {{.PACKAGE}}
55

66
import (
77
"math"

dh/sidh/internal/templates/curve_test.gotemp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Code generated by go generate; DO NOT EDIT.
22
// This file was generated by robots.
33

4-
package {{ .PACKAGE}}
4+
package {{.PACKAGE}}
55

66
import (
77
"bytes"

0 commit comments

Comments
 (0)