Documentation ¶
Index ¶
- Constants
- Variables
- func Compress(a *PublicKey) []byte
- func Decrypt(priv *PrivateKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func Encrypt(pub *PublicKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func GenerateKey(rand io.Reader) (*PrivateKey, *PublicKey, error)
- func MarshalCipher(in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func ResponderConfirm(responderS2 []byte, initiatorS2 []byte) bool
- func SigToPub(hash, sig, userId []byte, ee *big.Int) (*ecdsa.PublicKey, error)
- func Sign(priv *PrivateKey, userId []byte, in []byte) ([]byte, *big.Int, error)
- func SignToRS(priv *PrivateKey, userId []byte, in []byte) (r, s, ee *big.Int, err error)
- func ToECDSAPublickey(key *PublicKey) *ecdsa.PublicKey
- func ToEcdsaPrivate(key *PrivateKey) *ecdsa.PrivateKey
- func UnmarshalCipher(in []byte, cipherTextType Sm2CipherTextType) (out []byte, err error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func Verify(pub *PublicKey, userId []byte, src []byte, sign []byte) bool
- func VerifyByRS(pub *PublicKey, userId []byte, src []byte, r, s *big.Int) bool
- type ExchangeResult
- type P256V1Curve
- func (curve P256V1Curve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)
- func (curve P256V1Curve) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
- func (curve P256V1Curve) IsOnCurve(X, Y *big.Int) bool
- func (curve P256V1Curve) Params() *elliptic.CurveParams
- func (curve P256V1Curve) QPlus1Div4() *big.Int
- func (curve P256V1Curve) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
- func (curve P256V1Curve) ScalarMult(x1, y1 *big.Int, k []byte) (*big.Int, *big.Int)
- type PrivateKey
- type PublicKey
- type Sm2CipherTextType
- type Sm2Signature
Constants ¶
View Source
const ( BitSize = 256 KeyBytes = (BitSize + 7) / 8 UnCompress = 0x04 )
View Source
const (
// DefaultUID The default user id as specified in GM/T 0009-2012
DefaultUID = "1234567812345678"
)
Variables ¶
View Source
var RInverse, _ = new(big.Int).SetString("7ffffffd80000002fffffffe000000017ffffffe800000037ffffffc80000002", 16)
Functions ¶
func Decrypt ¶
func Decrypt(priv *PrivateKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func Encrypt ¶
func Encrypt(pub *PublicKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func GenerateKey ¶
func GenerateKey(rand io.Reader) (*PrivateKey, *PublicKey, error)
func MarshalCipher ¶
func MarshalCipher(in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func ResponderConfirm ¶
func Sign ¶
gm sign with privatekey, r and s covert to byte array ,According to byte array length to implementation method.
func ToECDSAPublickey ¶
gm publickey covert to ecdsa publickey.
func ToEcdsaPrivate ¶
func ToEcdsaPrivate(key *PrivateKey) *ecdsa.PrivateKey
gm privatekey covert to ecdsa privatekey.
func UnmarshalCipher ¶
func UnmarshalCipher(in []byte, cipherTextType Sm2CipherTextType) (out []byte, err error)
func ValidateSignatureValues ¶
Validate sign value about v,r and s.
Types ¶
type ExchangeResult ¶
func CalculateKeyWithConfirmation ¶
func CalculateKeyWithConfirmation(initiator bool, keyBits int, confirmationTag []byte, selfStaticPriv *PrivateKey, selfEphemeralPriv *PrivateKey, selfId []byte, otherStaticPub *PublicKey, otherEphemeralPub *PublicKey, otherId []byte) (*ExchangeResult, error)
type P256V1Curve ¶
type P256V1Curve struct { *elliptic.CurveParams A *big.Int }
func GetSm2P256V1 ¶
func GetSm2P256V1() P256V1Curve
func (P256V1Curve) IsOnCurve ¶
func (curve P256V1Curve) IsOnCurve(X, Y *big.Int) bool
y^2 = x^3 + ax + b
func (P256V1Curve) Params ¶
func (curve P256V1Curve) Params() *elliptic.CurveParams
func (P256V1Curve) QPlus1Div4 ¶
func (curve P256V1Curve) QPlus1Div4() *big.Int
func (P256V1Curve) ScalarBaseMult ¶
func (P256V1Curve) ScalarMult ¶
type PrivateKey ¶
type PrivateKey struct { D *big.Int Curve P256V1Curve PublicKey }
func ToSm2privatekey ¶
func ToSm2privatekey(key *ecdsa.PrivateKey) *PrivateKey
ecdsa privatekey covert to gm privatekey.
func (*PrivateKey) GenerateShared ¶
func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error)
func (*PrivateKey) GetRawBytes ¶
func (pri *PrivateKey) GetRawBytes() []byte
type PublicKey ¶
type PublicKey struct {
X, Y *big.Int
Curve P256V1Curve
}
func Decompress ¶
Decompress transform 33 bytes publickey to publickey point struct.
func RecoverCompactSM2 ¶
func RecoverCompactSM2(curve P256V1Curve, signature, hash, userId []byte, ee *big.Int) (*PublicKey, bool, error)
RecoverCompact verifies the compact signature "signature" of "hash" for the Koblitz curve in "curve". If the signature matches then the recovered public key will be returned as well as a boolen if the original key was compressed or not, else an error will be returned.
func ToSm2Publickey ¶
ecdsa publickey covert to gm publickey.
func (*PublicKey) GetRawBytes ¶
func (*PublicKey) GetUnCompressBytes ¶
type Sm2CipherTextType ¶
type Sm2CipherTextType int32
const ( C1C2C3 Sm2CipherTextType = 1 C1C3C2 Sm2CipherTextType = 2 )
Click to show internal directories.
Click to hide internal directories.