Documentation ¶
Overview ¶
Package sm9 implements ShangMi(SM) sm9 digital signature, encryption and key exchange algorithms.
Index ¶
- Constants
- Variables
- 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
- type CFBEncrypterOpts
- type ECBEncrypterOpts
- type EncryptMasterPrivateKey
- 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
- 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
- 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
- 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
- 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
- type SignMasterPrivateKey
- type SignMasterPublicKey
- 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
- 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
Constants ¶
View Source
const ( H1 hashMode = 1 + iota H2 )
View Source
const ( EncTypeXor encryptType = 0 EncTypeEcb encryptType = 1 EncTypeCbc encryptType = 2 EncTypeOfb encryptType = 4 EncTypeCfb encryptType = 8 )
Variables ¶
View Source
var DefaultEncrypterOpts = new(XOREncrypterOpts)
View Source
var ErrDecryption = errors.New("sm9: decryption error")
View Source
var ErrEmptyPlaintext = errors.New("sm9: empty plaintext")
View Source
var SM4CBCEncrypterOpts = NewCBCEncrypterOpts(padding.NewPKCS7Padding(sm4.BlockSize), sm4.NewCipher, sm4.BlockSize)
View Source
var SM4CFBEncrypterOpts = NewCFBEncrypterOpts(sm4.NewCipher, sm4.BlockSize)
View Source
var SM4ECBEncrypterOpts = NewECBEncrypterOpts(padding.NewPKCS7Padding(sm4.BlockSize), sm4.NewCipher, sm4.BlockSize)
View Source
var SM4OFBEncrypterOpts = NewOFBEncrypterOpts(sm4.NewCipher, sm4.BlockSize)
Functions ¶
func Decrypt ¶
func Decrypt(priv *EncryptPrivateKey, uid, ciphertext []byte, opts EncrypterOpts) ([]byte, error)
func DecryptASN1 ¶
func DecryptASN1(priv *EncryptPrivateKey, uid, ciphertext []byte) ([]byte, error)
func Encrypt ¶
func Encrypt(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte, plaintext []byte, opts EncrypterOpts) ([]byte, error)
func EncryptASN1 ¶
func EncryptASN1(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte, plaintext []byte, opts EncrypterOpts) ([]byte, error)
func VerifyASN1 ¶
func VerifyASN1(pub *SignMasterPublicKey, uid []byte, hid byte, hash, sig []byte) bool
Types ¶
type CBCEncrypterOpts ¶
type CBCEncrypterOpts struct {
// contains filtered or unexported fields
}
func (*CBCEncrypterOpts) Decrypt ¶
func (opts *CBCEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error)
func (*CBCEncrypterOpts) GetEncryptType ¶
func (opts *CBCEncrypterOpts) GetEncryptType() encryptType
func (*CBCEncrypterOpts) GetKeySize ¶
type CFBEncrypterOpts ¶
type CFBEncrypterOpts struct {
// contains filtered or unexported fields
}
func (*CFBEncrypterOpts) Decrypt ¶
func (opts *CFBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error)
func (*CFBEncrypterOpts) GetEncryptType ¶
func (opts *CFBEncrypterOpts) GetEncryptType() encryptType
func (*CFBEncrypterOpts) GetKeySize ¶
type ECBEncrypterOpts ¶
type ECBEncrypterOpts struct {
// contains filtered or unexported fields
}
func (*ECBEncrypterOpts) Decrypt ¶
func (opts *ECBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error)
func (*ECBEncrypterOpts) GetEncryptType ¶
func (opts *ECBEncrypterOpts) GetEncryptType() encryptType
func (*ECBEncrypterOpts) GetKeySize ¶
type EncryptMasterPrivateKey ¶
type EncryptMasterPrivateKey struct { EncryptMasterPublicKey D *big.Int }
func GenerateEncryptMasterKey ¶
func GenerateEncryptMasterKey(rand io.Reader) (*EncryptMasterPrivateKey, error)
func (*EncryptMasterPrivateKey) GenerateUserKey ¶
func (master *EncryptMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*EncryptPrivateKey, error)
func (*EncryptMasterPrivateKey) MarshalASN1 ¶
func (master *EncryptMasterPrivateKey) MarshalASN1() ([]byte, error)
func (*EncryptMasterPrivateKey) Public ¶
func (master *EncryptMasterPrivateKey) Public() *EncryptMasterPublicKey
func (*EncryptMasterPrivateKey) UnmarshalASN1 ¶
func (master *EncryptMasterPrivateKey) UnmarshalASN1(der []byte) error
type EncryptMasterPublicKey ¶
type EncryptMasterPublicKey struct { MasterPublicKey *bn256.G1 // contains filtered or unexported fields }
func (*EncryptMasterPublicKey) Encrypt ¶
func (pub *EncryptMasterPublicKey) Encrypt(rand io.Reader, uid []byte, hid byte, plaintext []byte, opts EncrypterOpts) ([]byte, error)
func (*EncryptMasterPublicKey) GenerateUserPublicKey ¶
func (pub *EncryptMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *bn256.G1
func (*EncryptMasterPublicKey) MarshalASN1 ¶
func (pub *EncryptMasterPublicKey) MarshalASN1() ([]byte, error)
func (*EncryptMasterPublicKey) MarshalCompressedASN1 ¶
func (pub *EncryptMasterPublicKey) MarshalCompressedASN1() ([]byte, error)
func (*EncryptMasterPublicKey) ParseFromPEM ¶
func (pub *EncryptMasterPublicKey) ParseFromPEM(data []byte) error
func (*EncryptMasterPublicKey) ScalarBaseMult ¶
func (pub *EncryptMasterPublicKey) ScalarBaseMult(scalar []byte) (*bn256.GT, error)
func (*EncryptMasterPublicKey) UnmarshalASN1 ¶
func (pub *EncryptMasterPublicKey) UnmarshalASN1(der []byte) error
func (*EncryptMasterPublicKey) UnmarshalRaw ¶
func (pub *EncryptMasterPublicKey) UnmarshalRaw(bytes []byte) error
func (*EncryptMasterPublicKey) WrapKeyASN1 ¶
type EncryptPrivateKey ¶
type EncryptPrivateKey struct { PrivateKey *bn256.G2 EncryptMasterPublicKey }
func (*EncryptPrivateKey) Decrypt ¶
func (priv *EncryptPrivateKey) Decrypt(uid, ciphertext []byte, opts EncrypterOpts) ([]byte, error)
func (*EncryptPrivateKey) DecryptASN1 ¶
func (priv *EncryptPrivateKey) DecryptASN1(uid, ciphertext []byte) ([]byte, error)
func (*EncryptPrivateKey) MarshalASN1 ¶
func (priv *EncryptPrivateKey) MarshalASN1() ([]byte, error)
func (*EncryptPrivateKey) MarshalCompressedASN1 ¶
func (priv *EncryptPrivateKey) MarshalCompressedASN1() ([]byte, error)
func (*EncryptPrivateKey) MasterPublic ¶
func (priv *EncryptPrivateKey) MasterPublic() *EncryptMasterPublicKey
func (*EncryptPrivateKey) SetMasterPublicKey ¶
func (priv *EncryptPrivateKey) SetMasterPublicKey(pub *EncryptMasterPublicKey)
func (*EncryptPrivateKey) UnmarshalASN1 ¶
func (priv *EncryptPrivateKey) UnmarshalASN1(der []byte) error
func (*EncryptPrivateKey) UnmarshalRaw ¶
func (priv *EncryptPrivateKey) UnmarshalRaw(bytes []byte) error
type EncrypterOpts ¶
type EncrypterOpts interface { GetEncryptType() encryptType GetKeySize(plaintext []byte) int Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, error) Decrypt(key, ciphertext []byte) ([]byte, error) }
func NewCBCEncrypterOpts ¶
func NewCBCEncrypterOpts(padding padding.Padding, newCipher newCipher, keySize int) EncrypterOpts
func NewCFBEncrypterOpts ¶
func NewCFBEncrypterOpts(newCipher newCipher, keySize int) EncrypterOpts
func NewECBEncrypterOpts ¶
func NewECBEncrypterOpts(padding padding.Padding, newCipher newCipher, keySize int) EncrypterOpts
func NewOFBEncrypterOpts ¶
func NewOFBEncrypterOpts(newCipher newCipher, keySize int) EncrypterOpts
type KeyExchange ¶
type KeyExchange struct {
// contains filtered or unexported fields
}
func NewKeyExchange ¶
func NewKeyExchange(priv *EncryptPrivateKey, uid, peerUID []byte, keyLen int, genSignature bool) *KeyExchange
func (*KeyExchange) ConfirmInitiator ¶
func (ke *KeyExchange) ConfirmInitiator(s1 []byte) ([]byte, error)
func (*KeyExchange) ConfirmResponder ¶
func (*KeyExchange) Destroy ¶
func (ke *KeyExchange) Destroy()
type OFBEncrypterOpts ¶
type OFBEncrypterOpts struct {
// contains filtered or unexported fields
}
func (*OFBEncrypterOpts) Decrypt ¶
func (opts *OFBEncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error)
func (*OFBEncrypterOpts) GetEncryptType ¶
func (opts *OFBEncrypterOpts) GetEncryptType() encryptType
func (*OFBEncrypterOpts) GetKeySize ¶
type SignMasterPrivateKey ¶
type SignMasterPrivateKey struct { SignMasterPublicKey D *big.Int }
func GenerateSignMasterKey ¶
func GenerateSignMasterKey(rand io.Reader) (*SignMasterPrivateKey, error)
func (*SignMasterPrivateKey) GenerateUserKey ¶
func (master *SignMasterPrivateKey) GenerateUserKey(uid []byte, hid byte) (*SignPrivateKey, error)
func (*SignMasterPrivateKey) MarshalASN1 ¶
func (master *SignMasterPrivateKey) MarshalASN1() ([]byte, error)
func (*SignMasterPrivateKey) Public ¶
func (master *SignMasterPrivateKey) Public() *SignMasterPublicKey
func (*SignMasterPrivateKey) UnmarshalASN1 ¶
func (master *SignMasterPrivateKey) UnmarshalASN1(der []byte) error
type SignMasterPublicKey ¶
type SignMasterPublicKey struct { MasterPublicKey *bn256.G2 // contains filtered or unexported fields }
func (*SignMasterPublicKey) GenerateUserPublicKey ¶
func (pub *SignMasterPublicKey) GenerateUserPublicKey(uid []byte, hid byte) *bn256.G2
func (*SignMasterPublicKey) MarshalASN1 ¶
func (pub *SignMasterPublicKey) MarshalASN1() ([]byte, error)
func (*SignMasterPublicKey) MarshalCompressedASN1 ¶
func (pub *SignMasterPublicKey) MarshalCompressedASN1() ([]byte, error)
func (*SignMasterPublicKey) ParseFromPEM ¶
func (pub *SignMasterPublicKey) ParseFromPEM(data []byte) error
func (*SignMasterPublicKey) ScalarBaseMult ¶
func (pub *SignMasterPublicKey) ScalarBaseMult(scalar []byte) (*bn256.GT, error)
func (*SignMasterPublicKey) UnmarshalASN1 ¶
func (pub *SignMasterPublicKey) UnmarshalASN1(der []byte) error
func (*SignMasterPublicKey) UnmarshalRaw ¶
func (pub *SignMasterPublicKey) UnmarshalRaw(bytes []byte) error
type SignPrivateKey ¶
type SignPrivateKey struct { PrivateKey *bn256.G1 SignMasterPublicKey }
func (*SignPrivateKey) MarshalASN1 ¶
func (priv *SignPrivateKey) MarshalASN1() ([]byte, error)
func (*SignPrivateKey) MarshalCompressedASN1 ¶
func (priv *SignPrivateKey) MarshalCompressedASN1() ([]byte, error)
func (*SignPrivateKey) MasterPublic ¶
func (priv *SignPrivateKey) MasterPublic() *SignMasterPublicKey
func (*SignPrivateKey) SetMasterPublicKey ¶
func (priv *SignPrivateKey) SetMasterPublicKey(pub *SignMasterPublicKey)
func (*SignPrivateKey) Sign ¶
func (priv *SignPrivateKey) Sign(rand io.Reader, hash []byte, opts crypto.SignerOpts) ([]byte, error)
func (*SignPrivateKey) UnmarshalASN1 ¶
func (priv *SignPrivateKey) UnmarshalASN1(der []byte) error
func (*SignPrivateKey) UnmarshalRaw ¶
func (priv *SignPrivateKey) UnmarshalRaw(bytes []byte) error
type XOREncrypterOpts ¶
type XOREncrypterOpts struct{}
func (*XOREncrypterOpts) Decrypt ¶
func (opts *XOREncrypterOpts) Decrypt(key, ciphertext []byte) ([]byte, error)
func (*XOREncrypterOpts) GetEncryptType ¶
func (opts *XOREncrypterOpts) GetEncryptType() encryptType
func (*XOREncrypterOpts) GetKeySize ¶
func (opts *XOREncrypterOpts) GetKeySize(plaintext []byte) int
Click to show internal directories.
Click to hide internal directories.