summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-08-26 15:05:56 -0700
committerAdam Langley <agl@google.com>2015-08-26 15:09:04 -0700
commit550d88df8d246c0f8f04cb6b4ce0978303586c2b (patch)
tree4720afbe209ca8c6ba70633702e5d595082384bb
parent235aa498686d32912940f1c68d0e8ccda2f28d6f (diff)
downloaded25519-550d88df8d246c0f8f04cb6b4ce0978303586c2b.tar.xz
A few tweaks for performance.
Some operations that can be done safely in 32 bits were being done in 64-bit mode after the recent changes. This change moves some of them back to 32 bits when the benchmarks say that it's an improvement.
-rw-r--r--edwards25519/edwards25519.go46
1 files changed, 23 insertions, 23 deletions
diff --git a/edwards25519/edwards25519.go b/edwards25519/edwards25519.go
index 0484f35..f883a3a 100644
--- a/edwards25519/edwards25519.go
+++ b/edwards25519/edwards25519.go
@@ -259,8 +259,8 @@ func FeNeg(h, f *FieldElement) {
}
func FeCombine(h *FieldElement, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) {
-
var c0, c1, c2, c3, c4, c5, c6, c7, c8, c9 int64
+
/*
|h0| <= (1.1*1.1*2^52*(1+19+19+19+19)+1.1*1.1*2^50*(38+38+38+38+38))
i.e. |h0| <= 1.2*2^59; narrower ranges for h2, h4, h6, h8
@@ -386,11 +386,11 @@ func FeMul(h, f, g *FieldElement) {
f8 := int64(f[8])
f9 := int64(f[9])
- f1_2 := 2 * f1
- f3_2 := 2 * f3
- f5_2 := 2 * f5
- f7_2 := 2 * f7
- f9_2 := 2 * f9
+ f1_2 := int64(2 * f[1])
+ f3_2 := int64(2 * f[3])
+ f5_2 := int64(2 * f[5])
+ f7_2 := int64(2 * f[7])
+ f9_2 := int64(2 * f[9])
g0 := int64(g[0])
g1 := int64(g[1])
@@ -403,15 +403,15 @@ func FeMul(h, f, g *FieldElement) {
g8 := int64(g[8])
g9 := int64(g[9])
- g1_19 := 19 * g1 /* 1.4*2^29 */
- g2_19 := 19 * g2 /* 1.4*2^30; still ok */
- g3_19 := 19 * g3
- g4_19 := 19 * g4
- g5_19 := 19 * g5
- g6_19 := 19 * g6
- g7_19 := 19 * g7
- g8_19 := 19 * g8
- g9_19 := 19 * g9
+ g1_19 := int64(19 * g[1]) /* 1.4*2^29 */
+ g2_19 := int64(19 * g[2]) /* 1.4*2^30; still ok */
+ g3_19 := int64(19 * g[3])
+ g4_19 := int64(19 * g[4])
+ g5_19 := int64(19 * g[5])
+ g6_19 := int64(19 * g[6])
+ g7_19 := int64(19 * g[7])
+ g8_19 := int64(19 * g[8])
+ g9_19 := int64(19 * g[9])
h0 := f0*g0 + f1_2*g9_19 + f2*g8_19 + f3_2*g7_19 + f4*g6_19 + f5_2*g5_19 + f6*g4_19 + f7_2*g3_19 + f8*g2_19 + f9_2*g1_19
h1 := f0*g1 + f1*g0 + f2*g9_19 + f3*g8_19 + f4*g7_19 + f5*g6_19 + f6*g5_19 + f7*g4_19 + f8*g3_19 + f9*g2_19
@@ -438,14 +438,14 @@ func feSquare(f *FieldElement) (h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) {
f7 := int64(f[7])
f8 := int64(f[8])
f9 := int64(f[9])
- f0_2 := 2 * f0
- f1_2 := 2 * f1
- f2_2 := 2 * f2
- f3_2 := 2 * f3
- f4_2 := 2 * f4
- f5_2 := 2 * f5
- f6_2 := 2 * f6
- f7_2 := 2 * f7
+ f0_2 := int64(2 * f[0])
+ f1_2 := int64(2 * f[1])
+ f2_2 := int64(2 * f[2])
+ f3_2 := int64(2 * f[3])
+ f4_2 := int64(2 * f[4])
+ f5_2 := int64(2 * f[5])
+ f6_2 := int64(2 * f[6])
+ f7_2 := int64(2 * f[7])
f5_38 := 38 * f5 // 1.31*2^30
f6_19 := 19 * f6 // 1.31*2^30
f7_38 := 38 * f7 // 1.31*2^30