mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
Merge fa3cc24302 into 9feec51e2d
This commit is contained in:
commit
700347ea4e
3 changed files with 156 additions and 106 deletions
|
|
@ -110,61 +110,75 @@ var bn256AddTests = []precompiledTest{
|
||||||
expected: "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204",
|
expected: "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204",
|
||||||
name: "chfast2",
|
name: "chfast2",
|
||||||
}, {
|
}, {
|
||||||
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio1",
|
name: "cdetrio1",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio2",
|
name: "cdetrio2",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio3",
|
name: "cdetrio3",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "",
|
input: "",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio4",
|
name: "cdetrio4",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio5",
|
name: "cdetrio5",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
input: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
name: "cdetrio6",
|
name: "cdetrio6",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
name: "cdetrio7",
|
name: "cdetrio7",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
input: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
name: "cdetrio8",
|
name: "cdetrio8",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
name: "cdetrio9",
|
name: "cdetrio9",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
expected: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
name: "cdetrio10",
|
name: "cdetrio10",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
input: "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
|
||||||
expected: "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4",
|
expected: "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4",
|
||||||
name: "cdetrio11",
|
name: "cdetrio11",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4",
|
expected: "030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd315ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4",
|
||||||
name: "cdetrio12",
|
name: "cdetrio12",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98",
|
input: "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98",
|
||||||
expected: "15bf2bb17880144b5d1cd2b1f46eff9d617bffd1ca57c37fb5a49bd84e53cf66049c797f9ce0d17083deb32b5e36f2ea2a212ee036598dd7624c168993d1355f",
|
expected: "15bf2bb17880144b5d1cd2b1f46eff9d617bffd1ca57c37fb5a49bd84e53cf66049c797f9ce0d17083deb32b5e36f2ea2a212ee036598dd7624c168993d1355f",
|
||||||
name: "cdetrio13",
|
name: "cdetrio13",
|
||||||
|
noBenchmark: true,
|
||||||
}, {
|
}, {
|
||||||
input: "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa92e83f8d734803fc370eba25ed1f6b8768bd6d83887b87165fc2434fe11a830cb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
input: "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa92e83f8d734803fc370eba25ed1f6b8768bd6d83887b87165fc2434fe11a830cb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
expected: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||||
name: "cdetrio14",
|
name: "cdetrio14",
|
||||||
|
noBenchmark: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,24 +89,38 @@ func (c *curvePoint) Add(a, b *curvePoint, pool *bnPool) {
|
||||||
// Normalize the points by replacing a = [x1:y1:z1] and b = [x2:y2:z2]
|
// Normalize the points by replacing a = [x1:y1:z1] and b = [x2:y2:z2]
|
||||||
// by [u1:s1:z1·z2] and [u2:s2:z1·z2]
|
// by [u1:s1:z1·z2] and [u2:s2:z1·z2]
|
||||||
// where u1 = x1·z2², s1 = y1·z2³ and u1 = x2·z1², s2 = y2·z1³
|
// where u1 = x1·z2², s1 = y1·z2³ and u1 = x2·z1², s2 = y2·z1³
|
||||||
z1z1 := pool.Get().Mul(a.z, a.z)
|
tmp := pool.Get()
|
||||||
z1z1.Mod(z1z1, P)
|
|
||||||
z2z2 := pool.Get().Mul(b.z, b.z)
|
|
||||||
z2z2.Mod(z2z2, P)
|
|
||||||
u1 := pool.Get().Mul(a.x, z2z2)
|
|
||||||
u1.Mod(u1, P)
|
|
||||||
u2 := pool.Get().Mul(b.x, z1z1)
|
|
||||||
u2.Mod(u2, P)
|
|
||||||
|
|
||||||
t := pool.Get().Mul(b.z, z2z2)
|
z1z1 := pool.Get()
|
||||||
t.Mod(t, P)
|
tmp.Mul(a.z, a.z)
|
||||||
s1 := pool.Get().Mul(a.y, t)
|
z1z1.Mod(tmp, P)
|
||||||
s1.Mod(s1, P)
|
|
||||||
|
|
||||||
t.Mul(a.z, z1z1)
|
z2z2 := pool.Get()
|
||||||
t.Mod(t, P)
|
tmp.Mul(b.z, b.z)
|
||||||
s2 := pool.Get().Mul(b.y, t)
|
z2z2.Mod(tmp, P)
|
||||||
s2.Mod(s2, P)
|
|
||||||
|
u1 := pool.Get()
|
||||||
|
tmp.Mul(a.x, z2z2)
|
||||||
|
u1.Mod(tmp, P)
|
||||||
|
|
||||||
|
u2 := pool.Get()
|
||||||
|
tmp.Mul(b.x, z1z1)
|
||||||
|
u2.Mod(tmp, P)
|
||||||
|
|
||||||
|
t := pool.Get()
|
||||||
|
tmp.Mul(b.z, z2z2)
|
||||||
|
t.Mod(tmp, P)
|
||||||
|
|
||||||
|
s1 := pool.Get()
|
||||||
|
tmp.Mul(a.y, t)
|
||||||
|
s1.Mod(tmp, P)
|
||||||
|
|
||||||
|
tmp.Mul(a.z, z1z1)
|
||||||
|
t.Mod(tmp, P)
|
||||||
|
|
||||||
|
s2 := pool.Get()
|
||||||
|
tmp.Mul(b.y, t)
|
||||||
|
s2.Mod(tmp, P)
|
||||||
|
|
||||||
// Compute x = (2h)²(s²-u1-u2)
|
// Compute x = (2h)²(s²-u1-u2)
|
||||||
// where s = (s2-s1)/(u2-u1) is the slope of the line through
|
// where s = (s2-s1)/(u2-u1) is the slope of the line through
|
||||||
|
|
@ -120,11 +134,13 @@ func (c *curvePoint) Add(a, b *curvePoint, pool *bnPool) {
|
||||||
|
|
||||||
t.Add(h, h)
|
t.Add(h, h)
|
||||||
// i = 4h²
|
// i = 4h²
|
||||||
i := pool.Get().Mul(t, t)
|
i := pool.Get()
|
||||||
i.Mod(i, P)
|
tmp.Mul(t, t)
|
||||||
|
i.Mod(tmp, P)
|
||||||
// j = 4h³
|
// j = 4h³
|
||||||
j := pool.Get().Mul(h, i)
|
j := pool.Get()
|
||||||
j.Mod(j, P)
|
tmp.Mul(h, i)
|
||||||
|
j.Mod(tmp, P)
|
||||||
|
|
||||||
t.Sub(s2, s1)
|
t.Sub(s2, s1)
|
||||||
yEqual := t.Sign() == 0
|
yEqual := t.Sign() == 0
|
||||||
|
|
@ -134,12 +150,15 @@ func (c *curvePoint) Add(a, b *curvePoint, pool *bnPool) {
|
||||||
}
|
}
|
||||||
r := pool.Get().Add(t, t)
|
r := pool.Get().Add(t, t)
|
||||||
|
|
||||||
v := pool.Get().Mul(u1, i)
|
v := pool.Get()
|
||||||
v.Mod(v, P)
|
tmp.Mul(u1, i)
|
||||||
|
v.Mod(tmp, P)
|
||||||
|
|
||||||
// t4 = 4(s2-s1)²
|
// t4 = 4(s2-s1)²
|
||||||
t4 := pool.Get().Mul(r, r)
|
t4 := pool.Get()
|
||||||
t4.Mod(t4, P)
|
tmp.Mul(r, r)
|
||||||
|
t4.Mod(tmp, P)
|
||||||
|
|
||||||
t.Add(v, v)
|
t.Add(v, v)
|
||||||
t6 := pool.Get().Sub(t4, j)
|
t6 := pool.Get().Sub(t4, j)
|
||||||
c.x.Sub(t6, t)
|
c.x.Sub(t6, t)
|
||||||
|
|
@ -147,22 +166,22 @@ func (c *curvePoint) Add(a, b *curvePoint, pool *bnPool) {
|
||||||
// Set y = -(2h)³(s1 + s*(x/4h²-u1))
|
// Set y = -(2h)³(s1 + s*(x/4h²-u1))
|
||||||
// This is also
|
// This is also
|
||||||
// y = - 2·s1·j - (s2-s1)(2x - 2i·u1) = r(v-x) - 2·s1·j
|
// y = - 2·s1·j - (s2-s1)(2x - 2i·u1) = r(v-x) - 2·s1·j
|
||||||
t.Sub(v, c.x) // t7
|
t.Sub(v, c.x) // t7
|
||||||
t4.Mul(s1, j) // t8
|
tmp.Mul(s1, j) // t8
|
||||||
t4.Mod(t4, P)
|
t4.Mod(tmp, P)
|
||||||
t6.Add(t4, t4) // t9
|
t6.Add(t4, t4) // t9
|
||||||
t4.Mul(r, t) // t10
|
tmp.Mul(r, t) // t10
|
||||||
t4.Mod(t4, P)
|
t4.Mod(tmp, P)
|
||||||
c.y.Sub(t4, t6)
|
c.y.Sub(t4, t6)
|
||||||
|
|
||||||
// Set z = 2(u2-u1)·z1·z2 = 2h·z1·z2
|
// Set z = 2(u2-u1)·z1·z2 = 2h·z1·z2
|
||||||
t.Add(a.z, b.z) // t11
|
t.Add(a.z, b.z) // t11
|
||||||
t4.Mul(t, t) // t12
|
tmp.Mul(t, t) // t12
|
||||||
t4.Mod(t4, P)
|
t4.Mod(tmp, P)
|
||||||
t.Sub(t4, z1z1) // t13
|
t.Sub(t4, z1z1) // t13
|
||||||
t4.Sub(t, z2z2) // t14
|
t4.Sub(t, z2z2) // t14
|
||||||
c.z.Mul(t4, h)
|
tmp.Mul(t4, h)
|
||||||
c.z.Mod(c.z, P)
|
c.z.Mod(tmp, P)
|
||||||
|
|
||||||
pool.Put(z1z1)
|
pool.Put(z1z1)
|
||||||
pool.Put(z2z2)
|
pool.Put(z2z2)
|
||||||
|
|
@ -178,27 +197,37 @@ func (c *curvePoint) Add(a, b *curvePoint, pool *bnPool) {
|
||||||
pool.Put(v)
|
pool.Put(v)
|
||||||
pool.Put(t4)
|
pool.Put(t4)
|
||||||
pool.Put(t6)
|
pool.Put(t6)
|
||||||
|
pool.Put(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
|
func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
|
||||||
// See http://hyperelliptic.org/EFD/g1p/auto-code/shortw/jacobian-0/doubling/dbl-2009-l.op3
|
// See http://hyperelliptic.org/EFD/g1p/auto-code/shortw/jacobian-0/doubling/dbl-2009-l.op3
|
||||||
A := pool.Get().Mul(a.x, a.x)
|
tmp := pool.Get()
|
||||||
A.Mod(A, P)
|
|
||||||
B := pool.Get().Mul(a.y, a.y)
|
A := pool.Get()
|
||||||
B.Mod(B, P)
|
tmp.Mul(a.x, a.x)
|
||||||
C_ := pool.Get().Mul(B, B)
|
A.Mod(tmp, P)
|
||||||
C_.Mod(C_, P)
|
|
||||||
|
B := pool.Get()
|
||||||
|
tmp.Mul(a.y, a.y)
|
||||||
|
B.Mod(tmp, P)
|
||||||
|
|
||||||
|
C_ := pool.Get()
|
||||||
|
tmp.Mul(B, B)
|
||||||
|
C_.Mod(tmp, P)
|
||||||
|
|
||||||
t := pool.Get().Add(a.x, B)
|
t := pool.Get().Add(a.x, B)
|
||||||
t2 := pool.Get().Mul(t, t)
|
t2 := pool.Get()
|
||||||
t2.Mod(t2, P)
|
tmp.Mul(t, t)
|
||||||
|
t2.Mod(tmp, P)
|
||||||
t.Sub(t2, A)
|
t.Sub(t2, A)
|
||||||
t2.Sub(t, C_)
|
t2.Sub(t, C_)
|
||||||
d := pool.Get().Add(t2, t2)
|
d := pool.Get().Add(t2, t2)
|
||||||
t.Add(A, A)
|
t.Add(A, A)
|
||||||
e := pool.Get().Add(t, A)
|
e := pool.Get().Add(t, A)
|
||||||
f := pool.Get().Mul(e, e)
|
f := pool.Get()
|
||||||
f.Mod(f, P)
|
tmp.Mul(e, e)
|
||||||
|
f.Mod(tmp, P)
|
||||||
|
|
||||||
t.Add(d, d)
|
t.Add(d, d)
|
||||||
c.x.Sub(f, t)
|
c.x.Sub(f, t)
|
||||||
|
|
@ -207,12 +236,12 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
|
||||||
t2.Add(t, t)
|
t2.Add(t, t)
|
||||||
t.Add(t2, t2)
|
t.Add(t2, t2)
|
||||||
c.y.Sub(d, c.x)
|
c.y.Sub(d, c.x)
|
||||||
t2.Mul(e, c.y)
|
tmp.Mul(e, c.y)
|
||||||
t2.Mod(t2, P)
|
t2.Mod(tmp, P)
|
||||||
c.y.Sub(t2, t)
|
c.y.Sub(t2, t)
|
||||||
|
|
||||||
t.Mul(a.y, a.z)
|
tmp.Mul(a.y, a.z)
|
||||||
t.Mod(t, P)
|
t.Mod(tmp, P)
|
||||||
c.z.Add(t, t)
|
c.z.Add(t, t)
|
||||||
|
|
||||||
pool.Put(A)
|
pool.Put(A)
|
||||||
|
|
@ -223,6 +252,7 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
|
||||||
pool.Put(d)
|
pool.Put(d)
|
||||||
pool.Put(e)
|
pool.Put(e)
|
||||||
pool.Put(f)
|
pool.Put(f)
|
||||||
|
pool.Put(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *curvePoint) Mul(a *curvePoint, scalar *big.Int, pool *bnPool) *curvePoint {
|
func (c *curvePoint) Mul(a *curvePoint, scalar *big.Int, pool *bnPool) *curvePoint {
|
||||||
|
|
@ -249,23 +279,30 @@ func (c *curvePoint) MakeAffine(pool *bnPool) *curvePoint {
|
||||||
if words := c.z.Bits(); len(words) == 1 && words[0] == 1 {
|
if words := c.z.Bits(); len(words) == 1 && words[0] == 1 {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
tmp := pool.Get()
|
||||||
|
|
||||||
zInv := pool.Get().ModInverse(c.z, P)
|
zInv := pool.Get().ModInverse(c.z, P)
|
||||||
t := pool.Get().Mul(c.y, zInv)
|
|
||||||
t.Mod(t, P)
|
t := pool.Get()
|
||||||
zInv2 := pool.Get().Mul(zInv, zInv)
|
tmp.Mul(c.y, zInv)
|
||||||
zInv2.Mod(zInv2, P)
|
t.Mod(tmp, P)
|
||||||
c.y.Mul(t, zInv2)
|
|
||||||
c.y.Mod(c.y, P)
|
zInv2 := pool.Get()
|
||||||
|
tmp.Mul(zInv, zInv)
|
||||||
|
zInv2.Mod(tmp, P)
|
||||||
|
|
||||||
|
tmp.Mul(t, zInv2)
|
||||||
|
c.y.Mod(tmp, P)
|
||||||
|
|
||||||
t.Mul(c.x, zInv2)
|
t.Mul(c.x, zInv2)
|
||||||
t.Mod(t, P)
|
c.x.Mod(t, P)
|
||||||
c.x.Set(t)
|
|
||||||
c.z.SetInt64(1)
|
c.z.SetInt64(1)
|
||||||
c.t.SetInt64(1)
|
c.t.SetInt64(1)
|
||||||
|
|
||||||
pool.Put(zInv)
|
pool.Put(zInv)
|
||||||
pool.Put(t)
|
pool.Put(t)
|
||||||
pool.Put(zInv2)
|
pool.Put(zInv2)
|
||||||
|
pool.Put(tmp)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,13 +130,13 @@ func (e *gfP2) Mul(a, b *gfP2, pool *bnPool) *gfP2 {
|
||||||
tx := pool.Get().Mul(a.x, b.y)
|
tx := pool.Get().Mul(a.x, b.y)
|
||||||
t := pool.Get().Mul(b.x, a.y)
|
t := pool.Get().Mul(b.x, a.y)
|
||||||
tx.Add(tx, t)
|
tx.Add(tx, t)
|
||||||
tx.Mod(tx, P)
|
|
||||||
|
t.Mul(a.x, b.x)
|
||||||
|
e.x.Mod(tx, P)
|
||||||
|
|
||||||
ty := pool.Get().Mul(a.y, b.y)
|
ty := pool.Get().Mul(a.y, b.y)
|
||||||
t.Mul(a.x, b.x)
|
|
||||||
ty.Sub(ty, t)
|
ty.Sub(ty, t)
|
||||||
e.y.Mod(ty, P)
|
e.y.Mod(ty, P)
|
||||||
e.x.Set(tx)
|
|
||||||
|
|
||||||
pool.Put(tx)
|
pool.Put(tx)
|
||||||
pool.Put(ty)
|
pool.Put(ty)
|
||||||
|
|
@ -177,13 +177,12 @@ func (e *gfP2) Square(a *gfP2, pool *bnPool) *gfP2 {
|
||||||
t1 := pool.Get().Sub(a.y, a.x)
|
t1 := pool.Get().Sub(a.y, a.x)
|
||||||
t2 := pool.Get().Add(a.x, a.y)
|
t2 := pool.Get().Add(a.x, a.y)
|
||||||
ty := pool.Get().Mul(t1, t2)
|
ty := pool.Get().Mul(t1, t2)
|
||||||
ty.Mod(ty, P)
|
|
||||||
|
|
||||||
t1.Mul(a.x, a.y)
|
t1.Mul(a.x, a.y)
|
||||||
t1.Lsh(t1, 1)
|
t1.Lsh(t1, 1)
|
||||||
|
|
||||||
e.x.Mod(t1, P)
|
e.x.Mod(t1, P)
|
||||||
e.y.Set(ty)
|
e.y.Mod(ty, P)
|
||||||
|
|
||||||
pool.Put(t1)
|
pool.Put(t1)
|
||||||
pool.Put(t2)
|
pool.Put(t2)
|
||||||
|
|
@ -205,11 +204,11 @@ func (e *gfP2) Invert(a *gfP2, pool *bnPool) *gfP2 {
|
||||||
inv.ModInverse(t, P)
|
inv.ModInverse(t, P)
|
||||||
|
|
||||||
e.x.Neg(a.x)
|
e.x.Neg(a.x)
|
||||||
e.x.Mul(e.x, inv)
|
t.Mul(e.x, inv)
|
||||||
e.x.Mod(e.x, P)
|
e.x.Mod(t, P)
|
||||||
|
|
||||||
e.y.Mul(a.y, inv)
|
t.Mul(a.y, inv)
|
||||||
e.y.Mod(e.y, P)
|
e.y.Mod(t, P)
|
||||||
|
|
||||||
pool.Put(t)
|
pool.Put(t)
|
||||||
pool.Put(t2)
|
pool.Put(t2)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue