mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 20:56:18 +08:00
sm9: get around assignment copies lock value to issue
This commit is contained in:
parent
66eae26312
commit
a1b44f1a64
@ -16,7 +16,7 @@ import (
|
||||
|
||||
// SignMasterPrivateKey master private key for sign, generated by KGC
|
||||
type SignMasterPrivateKey struct {
|
||||
SignMasterPublicKey // master public key
|
||||
*SignMasterPublicKey // master public key
|
||||
D *big.Int // master private key
|
||||
}
|
||||
|
||||
@ -32,12 +32,12 @@ type SignMasterPublicKey struct {
|
||||
// SignPrivateKey user private key for sign, generated by KGC
|
||||
type SignPrivateKey struct {
|
||||
PrivateKey *bn256.G1 // user private key
|
||||
SignMasterPublicKey // master public key
|
||||
*SignMasterPublicKey // master public key
|
||||
}
|
||||
|
||||
// EncryptMasterPrivateKey master private key for encryption, generated by KGC
|
||||
type EncryptMasterPrivateKey struct {
|
||||
EncryptMasterPublicKey // master public key
|
||||
*EncryptMasterPublicKey // master public key
|
||||
D *big.Int // master private key
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ type EncryptMasterPublicKey struct {
|
||||
// EncryptPrivateKey user private key for encryption, generated by KGC
|
||||
type EncryptPrivateKey struct {
|
||||
PrivateKey *bn256.G2 // user private key
|
||||
EncryptMasterPublicKey // master public key
|
||||
*EncryptMasterPublicKey // master public key
|
||||
}
|
||||
|
||||
// GenerateSignMasterKey generates a master public and private key pair for DSA usage.
|
||||
@ -70,6 +70,7 @@ func GenerateSignMasterKey(rand io.Reader) (*SignMasterPrivateKey, error) {
|
||||
|
||||
priv := new(SignMasterPrivateKey)
|
||||
priv.D = new(big.Int).SetBytes(kBytes)
|
||||
priv.SignMasterPublicKey = new(SignMasterPublicKey)
|
||||
priv.MasterPublicKey = p
|
||||
return priv, nil
|
||||
}
|
||||
@ -102,6 +103,7 @@ func (master *SignMasterPrivateKey) UnmarshalASN1(der []byte) error {
|
||||
return errors.New("sm9: invalid sign master private key asn1 data")
|
||||
}
|
||||
master.D = d
|
||||
master.SignMasterPublicKey = new(SignMasterPublicKey)
|
||||
p, err := new(bn256.G2).ScalarBaseMult(bn256.NormalizeScalar(d.Bytes()))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -144,7 +146,7 @@ func (master *SignMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*Sign
|
||||
|
||||
// Public returns the public key corresponding to priv.
|
||||
func (master *SignMasterPrivateKey) Public() *SignMasterPublicKey {
|
||||
return &master.SignMasterPublicKey
|
||||
return master.SignMasterPublicKey
|
||||
}
|
||||
|
||||
// pair generate the basepoint once
|
||||
@ -257,13 +259,13 @@ func (pub *SignMasterPublicKey) ParseFromPEM(data []byte) error {
|
||||
|
||||
// MasterPublic returns the master public key corresponding to priv.
|
||||
func (priv *SignPrivateKey) MasterPublic() *SignMasterPublicKey {
|
||||
return &priv.SignMasterPublicKey
|
||||
return priv.SignMasterPublicKey
|
||||
}
|
||||
|
||||
// SetMasterPublicKey bind the sign master public key to it.
|
||||
func (priv *SignPrivateKey) SetMasterPublicKey(pub *SignMasterPublicKey) {
|
||||
if priv.SignMasterPublicKey.MasterPublicKey == nil {
|
||||
priv.SignMasterPublicKey = *pub
|
||||
priv.SignMasterPublicKey = pub
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,6 +359,7 @@ func GenerateEncryptMasterKey(rand io.Reader) (*EncryptMasterPrivateKey, error)
|
||||
|
||||
priv := new(EncryptMasterPrivateKey)
|
||||
priv.D = new(big.Int).SetBytes(kBytes)
|
||||
priv.EncryptMasterPublicKey = new(EncryptMasterPublicKey)
|
||||
p, err := new(bn256.G1).ScalarBaseMult(kBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -399,7 +402,7 @@ func (master *EncryptMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*E
|
||||
|
||||
// Public returns the public key corresponding to priv.
|
||||
func (master *EncryptMasterPrivateKey) Public() *EncryptMasterPublicKey {
|
||||
return &master.EncryptMasterPublicKey
|
||||
return master.EncryptMasterPublicKey
|
||||
}
|
||||
|
||||
// MarshalASN1 marshal encrypt master private key to asn.1 format data according
|
||||
@ -430,6 +433,7 @@ func (master *EncryptMasterPrivateKey) UnmarshalASN1(der []byte) error {
|
||||
return errors.New("sm9: invalid encrypt master private key asn1 data")
|
||||
}
|
||||
master.D = d
|
||||
master.EncryptMasterPublicKey = new(EncryptMasterPublicKey)
|
||||
p, err := new(bn256.G1).ScalarBaseMult(bn256.NormalizeScalar(d.Bytes()))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -529,13 +533,13 @@ func (pub *EncryptMasterPublicKey) UnmarshalASN1(der []byte) error {
|
||||
|
||||
// MasterPublic returns the master public key corresponding to priv.
|
||||
func (priv *EncryptPrivateKey) MasterPublic() *EncryptMasterPublicKey {
|
||||
return &priv.EncryptMasterPublicKey
|
||||
return priv.EncryptMasterPublicKey
|
||||
}
|
||||
|
||||
// SetMasterPublicKey bind the encrypt master public key to it.
|
||||
func (priv *EncryptPrivateKey) SetMasterPublicKey(pub *EncryptMasterPublicKey) {
|
||||
if priv.EncryptMasterPublicKey.MasterPublicKey == nil {
|
||||
priv.EncryptMasterPublicKey = *pub
|
||||
priv.EncryptMasterPublicKey = pub
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user