Documentation
¶
Index ¶
- func Decrypt(priv *ecdsa.PrivateKey, ciphertext []byte, order CipherOrder, window int) ([]byte, error)
- func Encrypt(random io.Reader, pub *ecdsa.PublicKey, plaintext []byte, order CipherOrder, ...) ([]byte, error)
- func MarshalPKCS8PrivateKey(pri *ecdsa.PrivateKey) ([]byte, error)
- func MarshalSPKIPublicKey(pub *ecdsa.PublicKey) ([]byte, error)
- func NewCurve() elliptic.Curve
- func ParseBitStringPrivateKey(key []byte) (*ecdsa.PrivateKey, error)
- func ParseBitStringPublicKey(key []byte) (*ecdsa.PublicKey, error)
- func ParsePKCS8PrivateKey(der []byte) (*ecdsa.PrivateKey, error)
- func ParseSPKIPublicKey(der []byte) (*ecdsa.PublicKey, error)
- func RandScalar(curve elliptic.Curve, random io.Reader) (*big.Int, error)
- func SetWindow(cv elliptic.Curve, w int)
- func Sign(random io.Reader, priv *ecdsa.PrivateKey, message []byte, uid []byte) ([]byte, error)
- func Verify(pub *ecdsa.PublicKey, message []byte, uid []byte, sig []byte) bool
- type CipherOrder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
func Decrypt(priv *ecdsa.PrivateKey, ciphertext []byte, order CipherOrder, window int) ([]byte, error)
Decrypt decrypts ciphertext using SM2 private key decryption. The ciphertext format follows GM/T 0003-2012 standard.
func Encrypt ¶
func Encrypt(random io.Reader, pub *ecdsa.PublicKey, plaintext []byte, order CipherOrder, window int) ([]byte, error)
Encrypt encrypts plaintext using SM2 public key encryption. The ciphertext format follows GM/T 0003-2012 standard.
func MarshalPKCS8PrivateKey ¶
func MarshalPKCS8PrivateKey(pri *ecdsa.PrivateKey) ([]byte, error)
MarshalPKCS8PrivateKey encodes a PKCS#8 PrivateKeyInfo for the given SM2 private key.
func MarshalSPKIPublicKey ¶
MarshalSPKIPublicKey encodes a SubjectPublicKeyInfo (SPKI) for the given SM2 public key.
func ParseBitStringPrivateKey ¶
func ParseBitStringPrivateKey(key []byte) (*ecdsa.PrivateKey, error)
ParseBitStringPrivateKey parses a BIT_STRING PrivateKeyInfo and returns an SM2 private key.
func ParseBitStringPublicKey ¶
ParseBitStringPublicKey parses a BIT_STRING PublicKeyInfo and returns an SM2 public key.
func ParsePKCS8PrivateKey ¶
func ParsePKCS8PrivateKey(der []byte) (*ecdsa.PrivateKey, error)
ParsePKCS8PrivateKey parses a PKCS#8 PrivateKeyInfo and returns an SM2 private key. Simplified: ignores optional parameters/publicKey fields inside ECPrivateKey.
func ParseSPKIPublicKey ¶
ParseSPKIPublicKey parses a SubjectPublicKeyInfo (SPKI) and returns an SM2 public key.
func RandScalar ¶
RandScalar generates random scalar in [1, N-1] using rejection sampling.
func Sign ¶
Sign generates an SM2 signature for the given message It internally calculates ZA and digest (e = SM3(ZA || M)) Returns the signature in ASN.1 DER format
Types ¶
type CipherOrder ¶
type CipherOrder string
CipherOrder represents the order of ciphertext components
const ( // C1C2C3 represents ciphertext order: C1 || C2 || C3 C1C2C3 CipherOrder = "c1c2c3" // C1C3C2 represents ciphertext order: C1 || C3 || C2 C1C3C2 CipherOrder = "c1c3c2" )
Source Files
¶
- asn1.go
- curve.go
- field.go
- pool.go
- sm2.go