From 49513c74200c882546a44dfe4de16262a22769a8 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Tue, 25 Jul 2023 16:49:44 +0800 Subject: [PATCH] sm9/bn256: gt use cyclo6 squaring --- sm9/README.md | 3 +-- sm9/bn256/gt.go | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sm9/README.md b/sm9/README.md index ecdb52e7..e18de862 100644 --- a/sm9/README.md +++ b/sm9/README.md @@ -5,7 +5,7 @@ 4.Wrap/Unwrap Key 5.Encryption/Decryption -## SM9 current performance: +## SM9 current performance (for reference only): **SM9 Sign/Verify/Enc/Dec Benchmark** @@ -29,4 +29,3 @@ BenchmarkGenerateSignPrivKey-8 18608 65422 ns/op 944 B/op 14 allocs/op BenchmarkGenerateEncryptPrivKey-8 8486 151201 ns/op 1072 B/op 14 allocs/op -To further improve `Verify()/Decrypt()` performance, need to improve `Pair()` method performance. diff --git a/sm9/bn256/gt.go b/sm9/bn256/gt.go index 71b108ff..53f1a5c2 100644 --- a/sm9/bn256/gt.go +++ b/sm9/bn256/gt.go @@ -227,7 +227,7 @@ func GenerateGTFieldTable(basePoint *GT) *[32 * 2]GTFieldTable { for j := 1; j < 15; j += 2 { table[i][j] = >{} table[i][j].p = &gfP12{} - table[i][j].p.SquareNC(table[i][j/2].p) + table[i][j].p.Cyclo6SquareNC(table[i][j/2].p) table[i][j+1] = >{} table[i][j+1].p = &gfP12{} table[i][j+1].Add(table[i][j], base) @@ -274,7 +274,7 @@ func ScalarMultGT(a *GT, scalar []byte) (*GT, error) { for i := 1; i < 15; i += 2 { table[i] = >{} table[i].p = &gfP12{} - table[i].p.SquareNC(table[i/2].p) + table[i].p.Cyclo6SquareNC(table[i/2].p) table[i+1] = >{} table[i+1].p = &gfP12{} @@ -289,12 +289,12 @@ func ScalarMultGT(a *GT, scalar []byte) (*GT, error) { // No need to double on the first iteration, as p is the identity at // this point, and [N]∞ = ∞. if i != 0 { - e.p.Squares(e.p, 4) + e.p.Cyclo6Squares(e.p, 4) } windowValue := byte >> 4 table.Select(t, windowValue) e.Add(e, t) - e.p.Squares(e.p, 4) + e.p.Cyclo6Squares(e.p, 4) windowValue = byte & 0b1111 table.Select(t, windowValue) e.Add(e, t)