Versions in this module Expand all Collapse all v1 v1.12.0 Dec 19, 2023 v1.11.0 Dec 19, 2023 v1.10.0 Nov 20, 2023 v1.9.0 Jun 1, 2023 v1.8.0 May 31, 2023 Changes in this version + const EncTypeCbc + const EncTypeCfb + const EncTypeEcb + const EncTypeOfb + const EncTypeXor + const H1 + const H2 + var DefaultEncrypterOpts = new(XOREncrypterOpts) + var ErrDecryption = errors.New("sm9: decryption error") + var ErrEmptyPlaintext = errors.New("sm9: empty plaintext") + var SM4CBCEncrypterOpts = NewCBCEncrypterOpts(padding.NewPKCS7Padding(sm4.BlockSize), sm4.NewCipher, sm4.BlockSize) + var SM4CFBEncrypterOpts = NewCFBEncrypterOpts(sm4.NewCipher, sm4.BlockSize) + var SM4ECBEncrypterOpts = NewECBEncrypterOpts(padding.NewPKCS7Padding(sm4.BlockSize), sm4.NewCipher, sm4.BlockSize) + var SM4OFBEncrypterOpts = NewOFBEncrypterOpts(sm4.NewCipher, sm4.BlockSize) + func Decrypt(priv *EncryptPrivateKey, uid, ciphertext []byte, opts EncrypterOpts) ([]byte, error) + func DecryptASN1(priv *EncryptPrivateKey, uid, ciphertext []byte) ([]byte, error) + func Encrypt(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte, ...) ([]byte, error) + func EncryptASN1(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte, ...) ([]byte, error) + func Sign(rand io.Reader, priv *SignPrivateKey, hash []byte) (h *big.Int, s *bn256.G1, err error) + func SignASN1(rand io.Reader, priv *SignPrivateKey, hash []byte) ([]byte, error) + func UnmarshalSM9KeyPackage(der []byte) ([]byte, *bn256.G1, error) + func UnwrapKey(priv *EncryptPrivateKey, uid []byte, cipher *bn256.G1, kLen int) ([]byte, error) + func Verify(pub *SignMasterPublicKey, uid []byte, hid byte, hash []byte, h *big.Int, ...) bool + func VerifyASN1(pub *SignMasterPublicKey, uid []byte, hid byte, hash, sig []byte) bool + func WrapKey(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte, kLen int) (key []byte, cipher *bn256.G1, err error) + type CBCEncrypterOpts struct + func (opts *CBCEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error) + func (opts *CBCEncrypterOpts) Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) + func (opts *CBCEncrypterOpts) GetEncryptType() encryptType + func (opts *CBCEncrypterOpts) GetKeySize(plaintext []byte) int + type CFBEncrypterOpts struct + func (opts *CFBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error) + func (opts *CFBEncrypterOpts) Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) + func (opts *CFBEncrypterOpts) GetEncryptType() encryptType + func (opts *CFBEncrypterOpts) GetKeySize(plaintext []byte) int + type ECBEncrypterOpts struct + func (opts *ECBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error) + func (opts *ECBEncrypterOpts) Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) + func (opts *ECBEncrypterOpts) GetEncryptType() encryptType + func (opts *ECBEncrypterOpts) GetKeySize(plaintext []byte) int + type EncryptMasterPrivateKey struct + D *big.Int + func GenerateEncryptMasterKey(rand io.Reader) (*EncryptMasterPrivateKey, error) + func (master *EncryptMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*EncryptPrivateKey, error) + func (master *EncryptMasterPrivateKey) MarshalASN1() ([]byte, error) + func (master *EncryptMasterPrivateKey) Public() *EncryptMasterPublicKey + func (master *EncryptMasterPrivateKey) UnmarshalASN1(der []byte) error + type EncryptMasterPublicKey struct + MasterPublicKey *bn256.G1 + func (pub *EncryptMasterPublicKey) Encrypt(rand io.Reader, uid []byte, hid byte, plaintext []byte, opts EncrypterOpts) ([]byte, error) + func (pub *EncryptMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *bn256.G1 + func (pub *EncryptMasterPublicKey) MarshalASN1() ([]byte, error) + func (pub *EncryptMasterPublicKey) MarshalCompressedASN1() ([]byte, error) + func (pub *EncryptMasterPublicKey) ParseFromPEM(data []byte) error + func (pub *EncryptMasterPublicKey) ScalarBaseMult(scalar []byte) (*bn256.GT, error) + func (pub *EncryptMasterPublicKey) UnmarshalASN1(der []byte) error + func (pub *EncryptMasterPublicKey) UnmarshalRaw(bytes []byte) error + func (pub *EncryptMasterPublicKey) WrapKey(rand io.Reader, uid []byte, hid byte, kLen int) ([]byte, []byte, error) + func (pub *EncryptMasterPublicKey) WrapKeyASN1(rand io.Reader, uid []byte, hid byte, kLen int) ([]byte, error) + type EncryptPrivateKey struct + PrivateKey *bn256.G2 + func (priv *EncryptPrivateKey) Decrypt(uid, ciphertext []byte, opts EncrypterOpts) ([]byte, error) + func (priv *EncryptPrivateKey) DecryptASN1(uid, ciphertext []byte) ([]byte, error) + func (priv *EncryptPrivateKey) MarshalASN1() ([]byte, error) + func (priv *EncryptPrivateKey) MarshalCompressedASN1() ([]byte, error) + func (priv *EncryptPrivateKey) MasterPublic() *EncryptMasterPublicKey + func (priv *EncryptPrivateKey) SetMasterPublicKey(pub *EncryptMasterPublicKey) + func (priv *EncryptPrivateKey) UnmarshalASN1(der []byte) error + func (priv *EncryptPrivateKey) UnmarshalRaw(bytes []byte) error + func (priv *EncryptPrivateKey) UnwrapKey(uid, cipherDer []byte, kLen int) ([]byte, error) + type EncrypterOpts interface + Decrypt func(key, ciphertext []byte) ([]byte, error) + Encrypt func(rand io.Reader, key, plaintext []byte) ([]byte, error) + GetEncryptType func() encryptType + GetKeySize func(plaintext []byte) int + func NewCBCEncrypterOpts(padding padding.Padding, newCipher newCipher, keySize int) EncrypterOpts + func NewCFBEncrypterOpts(newCipher newCipher, keySize int) EncrypterOpts + func NewECBEncrypterOpts(padding padding.Padding, newCipher newCipher, keySize int) EncrypterOpts + func NewOFBEncrypterOpts(newCipher newCipher, keySize int) EncrypterOpts + type KeyExchange struct + func NewKeyExchange(priv *EncryptPrivateKey, uid, peerUID []byte, keyLen int, genSignature bool) *KeyExchange + func (ke *KeyExchange) ConfirmInitiator(s1 []byte) ([]byte, error) + func (ke *KeyExchange) ConfirmResponder(rB *bn256.G1, sB []byte) ([]byte, []byte, error) + func (ke *KeyExchange) Destroy() + func (ke *KeyExchange) Init(rand io.Reader, hid byte) (*bn256.G1, error) + func (ke *KeyExchange) Respond(rand io.Reader, hid byte, rA *bn256.G1) (*bn256.G1, []byte, error) + type OFBEncrypterOpts struct + func (opts *OFBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error) + func (opts *OFBEncrypterOpts) Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) + func (opts *OFBEncrypterOpts) GetEncryptType() encryptType + func (opts *OFBEncrypterOpts) GetKeySize(plaintext []byte) int + type SignMasterPrivateKey struct + D *big.Int + func GenerateSignMasterKey(rand io.Reader) (*SignMasterPrivateKey, error) + func (master *SignMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*SignPrivateKey, error) + func (master *SignMasterPrivateKey) MarshalASN1() ([]byte, error) + func (master *SignMasterPrivateKey) Public() *SignMasterPublicKey + func (master *SignMasterPrivateKey) UnmarshalASN1(der []byte) error + type SignMasterPublicKey struct + MasterPublicKey *bn256.G2 + func (pub *SignMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *bn256.G2 + func (pub *SignMasterPublicKey) MarshalASN1() ([]byte, error) + func (pub *SignMasterPublicKey) MarshalCompressedASN1() ([]byte, error) + func (pub *SignMasterPublicKey) ParseFromPEM(data []byte) error + func (pub *SignMasterPublicKey) ScalarBaseMult(scalar []byte) (*bn256.GT, error) + func (pub *SignMasterPublicKey) UnmarshalASN1(der []byte) error + func (pub *SignMasterPublicKey) UnmarshalRaw(bytes []byte) error + func (pub *SignMasterPublicKey) Verify(uid []byte, hid byte, hash, sig []byte) bool + type SignPrivateKey struct + PrivateKey *bn256.G1 + func (priv *SignPrivateKey) MarshalASN1() ([]byte, error) + func (priv *SignPrivateKey) MarshalCompressedASN1() ([]byte, error) + func (priv *SignPrivateKey) MasterPublic() *SignMasterPublicKey + func (priv *SignPrivateKey) SetMasterPublicKey(pub *SignMasterPublicKey) + func (priv *SignPrivateKey) Sign(rand io.Reader, hash []byte, opts crypto.SignerOpts) ([]byte, error) + func (priv *SignPrivateKey) UnmarshalASN1(der []byte) error + func (priv *SignPrivateKey) UnmarshalRaw(bytes []byte) error + type XOREncrypterOpts struct + func (opts *XOREncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error) + func (opts *XOREncrypterOpts) Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) + func (opts *XOREncrypterOpts) GetEncryptType() encryptType + func (opts *XOREncrypterOpts) GetKeySize(plaintext []byte) int