mirror of
https://github.com/emmansun/gmsm.git
synced 2025-05-13 20:46:17 +08:00
supplement user key generation performance
This commit is contained in:
parent
d6a464f470
commit
ccdb7b0568
@ -37,4 +37,20 @@ This part codes mainly refer two projects:
|
|||||||
cpu: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
|
cpu: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
|
||||||
BenchmarkDecrypt-6 507 2345492 ns/op 202360 B/op 5228 allocs/op
|
BenchmarkDecrypt-6 507 2345492 ns/op 202360 B/op 5228 allocs/op
|
||||||
|
|
||||||
|
**SM9 Generate User Sign Private Key Benchmark**
|
||||||
|
|
||||||
|
goos: windows
|
||||||
|
goarch: amd64
|
||||||
|
pkg: github.com/emmansun/gmsm/sm9
|
||||||
|
cpu: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
|
||||||
|
BenchmarkGenerateSignPrivKey-6 8078 147638 ns/op 3176 B/op 47 allocs/op
|
||||||
|
|
||||||
|
**SM9 Generate User Encrypt Private Key Benchmark**
|
||||||
|
|
||||||
|
goos: windows
|
||||||
|
goarch: amd64
|
||||||
|
pkg: github.com/emmansun/gmsm/sm9
|
||||||
|
cpu: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
|
||||||
|
BenchmarkGenerateEncryptPrivKey-6 3445 326796 ns/op 3433 B/op 47 allocs/op
|
||||||
|
|
||||||
To further improve `Verify()/Decrypt()` performance, need to improve `Pair()` method performance.
|
To further improve `Verify()/Decrypt()` performance, need to improve `Pair()` method performance.
|
||||||
|
10
sm9/sm9.go
10
sm9/sm9.go
@ -260,16 +260,6 @@ func (pub *SignMasterPublicKey) Verify(uid []byte, hid byte, hash, sig []byte) b
|
|||||||
return VerifyASN1(pub, uid, hid, hash, sig)
|
return VerifyASN1(pub, uid, hid, hash, sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pub *EncryptMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *G1 {
|
|
||||||
var buffer []byte
|
|
||||||
buffer = append(buffer, uid...)
|
|
||||||
buffer = append(buffer, hid)
|
|
||||||
h1 := hashH1(buffer)
|
|
||||||
p := new(G1).ScalarBaseMult(h1)
|
|
||||||
p.Add(p, pub.MasterPublicKey)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pub *EncryptMasterPublicKey) Pair() *GT {
|
func (pub *EncryptMasterPublicKey) Pair() *GT {
|
||||||
pub.pairOnce.Do(func() {
|
pub.pairOnce.Do(func() {
|
||||||
pub.basePoint = Pair(pub.MasterPublicKey, Gen2)
|
pub.basePoint = Pair(pub.MasterPublicKey, Gen2)
|
||||||
|
@ -105,6 +105,17 @@ func (master *SignMasterPrivateKey) Public() *SignMasterPublicKey {
|
|||||||
return &master.SignMasterPublicKey
|
return &master.SignMasterPublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateUserPublicKey generate user sign public key
|
||||||
|
func (pub *SignMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *G2 {
|
||||||
|
var buffer []byte
|
||||||
|
buffer = append(buffer, uid...)
|
||||||
|
buffer = append(buffer, hid)
|
||||||
|
h1 := hashH1(buffer)
|
||||||
|
p := new(G2).ScalarBaseMult(h1)
|
||||||
|
p.Add(p, pub.MasterPublicKey)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
// MarshalASN1 marshal sign master public key to asn.1 format data according
|
// MarshalASN1 marshal sign master public key to asn.1 format data according
|
||||||
// SM9 cryptographic algorithm application specification
|
// SM9 cryptographic algorithm application specification
|
||||||
func (pub *SignMasterPublicKey) MarshalASN1() ([]byte, error) {
|
func (pub *SignMasterPublicKey) MarshalASN1() ([]byte, error) {
|
||||||
@ -132,17 +143,6 @@ func (pub *SignMasterPublicKey) UnmarshalASN1(der []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateUserPublicKey generate user sign public key
|
|
||||||
func (pub *SignMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *G2 {
|
|
||||||
var buffer []byte
|
|
||||||
buffer = append(buffer, uid...)
|
|
||||||
buffer = append(buffer, hid)
|
|
||||||
h1 := hashH1(buffer)
|
|
||||||
p := new(G2).ScalarBaseMult(h1)
|
|
||||||
p.Add(p, pub.MasterPublicKey)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
// MasterPublic returns the master public key corresponding to priv.
|
// MasterPublic returns the master public key corresponding to priv.
|
||||||
func (priv *SignPrivateKey) MasterPublic() *SignMasterPublicKey {
|
func (priv *SignPrivateKey) MasterPublic() *SignMasterPublicKey {
|
||||||
return &priv.SignMasterPublicKey
|
return &priv.SignMasterPublicKey
|
||||||
@ -243,6 +243,17 @@ func (master *EncryptMasterPrivateKey) UnmarshalASN1(der []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateUserPublicKey generate user encrypt public key
|
||||||
|
func (pub *EncryptMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *G1 {
|
||||||
|
var buffer []byte
|
||||||
|
buffer = append(buffer, uid...)
|
||||||
|
buffer = append(buffer, hid)
|
||||||
|
h1 := hashH1(buffer)
|
||||||
|
p := new(G1).ScalarBaseMult(h1)
|
||||||
|
p.Add(p, pub.MasterPublicKey)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
// MarshalASN1 marshal encrypt master public key to asn.1 format data according
|
// MarshalASN1 marshal encrypt master public key to asn.1 format data according
|
||||||
// SM9 cryptographic algorithm application specification
|
// SM9 cryptographic algorithm application specification
|
||||||
func (pub *EncryptMasterPublicKey) MarshalASN1() ([]byte, error) {
|
func (pub *EncryptMasterPublicKey) MarshalASN1() ([]byte, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user