Skip to content

Commit

Permalink
sm9/bn256: gt use cyclo6 squaring
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Jul 25, 2023
1 parent ce07f3a commit 49513c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions sm9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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.
8 changes: 4 additions & 4 deletions sm9/bn256/gt.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func GenerateGTFieldTable(basePoint *GT) *[32 * 2]GTFieldTable {
for j := 1; j < 15; j += 2 {
table[i][j] = &GT{}
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] = &GT{}
table[i][j+1].p = &gfP12{}
table[i][j+1].Add(table[i][j], base)
Expand Down Expand Up @@ -274,7 +274,7 @@ func ScalarMultGT(a *GT, scalar []byte) (*GT, error) {
for i := 1; i < 15; i += 2 {
table[i] = &GT{}
table[i].p = &gfP12{}
table[i].p.SquareNC(table[i/2].p)
table[i].p.Cyclo6SquareNC(table[i/2].p)

table[i+1] = &GT{}
table[i+1].p = &gfP12{}
Expand All @@ -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)
Expand Down

0 comments on commit 49513c7

Please sign in to comment.