cncc

package
v0.0.0-...-a160350 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2020 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SessionCacheSize  = 10
	BJ_NetSignConfig  []*NetSignConfig
	SH_NetSignConfig  []*NetSignConfig
	BAK_NetSignConfig []*NetSignConfig
)

Functions

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte

func FindPKCS11Lib

func FindPKCS11Lib(opts CNCC_GMOpts)

* 环境变量格式: CORE_PEER_BCCSP_CNCC_GM_IP=111.63.61.21,111.63.61.22;17.63.61.21,17.63.61.22 CORE_PEER_BCCSP_CNCC_GM_PORT=50060,50061;50060,50061 CORE_PEER_BCCSP_CNCC_GM_password=123456,123456;123456,123456 理论上用 “;” 来区分 北京和上海的签名服务器配置

func GetPublicKeyExample

func GetPublicKeyExample() *sm2.PublicKey

func GetRandomBytes

func GetRandomBytes(len int) ([]byte, error)

GetRandomBytes returns len random looking bytes

func IsLowS

func IsLowS(k *ecdsa.PublicKey, s *big.Int) (bool, error)

IsLow checks that s is a low-S

func MarshalSM2Signature

func MarshalSM2Signature(r, s *big.Int) ([]byte, error)

func New

func New(opts CNCC_GMOpts, keyStore bccsp.KeyStore) (bccsp.BCCSP, error)

func NewDummyKeyStore

func NewDummyKeyStore() bccsp.KeyStore

模拟实现

func NewFileBasedKeyStore

func NewFileBasedKeyStore(pwd []byte, path string, readOnly bool) (bccsp.KeyStore, error)

NewFileBasedKeyStore instantiated a file-based key store at a given position. The key store can be encrypted if a non-empty password is specifiec. It can be also be set as read only. In this case, any store operation will be forbidden

func OpenNetSign

func OpenNetSign(ip, password string, port int) (socketFd int, ns *netsign.NetSign)

func RandStringInt

func RandStringInt() string

产生随机数

func SM4Decrypt

func SM4Decrypt(key, src []byte) ([]byte, error)

AESCBCPKCS7Decrypt combines CBC decryption and PKCS7 unpadding

func SM4Encrypt

func SM4Encrypt(key, src []byte) ([]byte, error)

AESCBCPKCS7Encrypt combines CBC encryption and PKCS7 padding

func SaveSKI

func SaveSKI(path, ski string) error

func ToLowS

func ToLowS(k *ecdsa.PublicKey, s *big.Int) (*big.Int, bool, error)

func UnmarshalSM2Signature

func UnmarshalSM2Signature(raw []byte) (*big.Int, *big.Int, error)

Types

type CNCC_GMOpts

type CNCC_GMOpts struct {
	// Default algorithms when not specified (Deprecated?)
	SecLevel   int    `mapstructure:"security" json:"security" yaml:"Security"`
	HashFamily string `mapstructure:"hash" json:"hash" yaml:"Hash"`

	// Keystore options
	Ephemeral     bool               `mapstructure:"tempkeys,omitempty" json:"tempkeys,omitempty" yaml:"Ephemeral"`
	FileKeystore  *FileKeystoreOpts  `mapstructure:"filekeystore,omitempty" json:"filekeystore,omitempty", yaml:"FileKeyStore"`
	DummyKeystore *DummyKeystoreOpts `mapstructure:"dummykeystore,omitempty" json:"dummykeystore,omitempty"`

	// PKCS11 options
	Library    string `mapstructure:"library" json:"library" yaml:"Library"`
	Ip         string `mapstructure:"ip" json:"ip" yaml:"Ip"`
	Port       string `mapstructure:"port" json:"port" yaml:"Port"`
	Password   string `mapstructure:"password" json:"password" yaml:"Password"`
	Sensitive  bool   `mapstructure:"sensitivekeys,omitempty" json:"sensitivekeys,omitempty" yaml:"Sensitive"`
	SoftVerify bool   `mapstructure:"softwareverify,omitempty" json:"softwareverify,omitempty" yaml:"SoftVerify"`
}

CNCC_GMpts contains options for the CNCC_GMFactory

type DummyKeystoreOpts

type DummyKeystoreOpts struct{}

type FileKeystoreOpts

type FileKeystoreOpts struct {
	KeyStorePath string `mapstructure:"keystore" json:"keystore" yaml:"KeyStore"`
}

type Impl

type Impl struct {
	bccsp.BCCSP // 内嵌BCCSP接口

	Sessions chan *NetSignSesssion // 会话标识符通道,默认10(sessionCacheSize = 10)
	// contains filtered or unexported fields
}

func (*Impl) Decrypt

func (csp *Impl) Decrypt(k bccsp.Key, ciphertext []byte, opts bccsp.DecrypterOpts) (plaintext []byte, err error)

根据解密者选项opts,使用k对ciphertext进行解密

func (*Impl) Encrypt

func (csp *Impl) Encrypt(k bccsp.Key, plaintext []byte, opts bccsp.EncrypterOpts) (ciphertext []byte, err error)

根据加密者选项opts,使用k加密plaintext

func (*Impl) GetHash

func (csp *Impl) GetHash(opts bccsp.HashOpts) (h hash.Hash, err error)

GetHash returns and instance of hash.Hash using options opts. If opts is nil then the default hash function is returned.

func (*Impl) GetKey

func (csp *Impl) GetKey(ski []byte) (k bccsp.Key, err error)

根据SKI返回与该接口实例有联系的key

func (*Impl) Hash

func (csp *Impl) Hash(msg []byte, opts bccsp.HashOpts) (digest []byte, err error)

根据哈希选项opts哈希一个消息msg,如果opts为空,则使用默认选项

func (*Impl) KeyDeriv

func (csp *Impl) KeyDeriv(k bccsp.Key, opts bccsp.KeyDerivOpts) (dk bccsp.Key, err error)

根据解密者选项opts,使用k对ciphertext进行解密

func (*Impl) KeyGen

func (csp *Impl) KeyGen(opts bccsp.KeyGenOpts) (k bccsp.Key, err error)

根据key生成选项opts生成一个key

func (*Impl) KeyImport

func (csp *Impl) KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (k bccsp.Key, err error)

根据key导入选项opts从一个key原始的数据中导入一个key

func (*Impl) Sign

func (csp *Impl) Sign(k bccsp.Key, digest []byte, opts bccsp.SignerOpts) (signature []byte, err error)

根据签名者选项opts,使用k对digest进行签名,注意如果需要对一个特别大的消息的hash值 进行签名,调用者则负责对该特别大的消息进行hash后将其作为digest传入

func (*Impl) Uploadcert

func (csp *Impl) Uploadcert(ski []byte, certBytes []byte) error

上传证书

func (*Impl) Verify

func (csp *Impl) Verify(k bccsp.Key, signature, digest []byte, opts bccsp.SignerOpts) (valid bool, err error)

根据鉴定者选项opts,通过对比k和digest,鉴定签名

type InmemKeystoreOpts

type InmemKeystoreOpts struct{}

InmemKeystoreOpts - empty, as there is no config for the in-memory keystore

type NetSignConfig

type NetSignConfig struct {
	Ip     string
	Port   string
	Passwd string
}

type NetSignSesssion

type NetSignSesssion struct {
	NSC       *NetSignConfig
	NS_sesion int
}

type SM2Signature

type SM2Signature struct {
	R, S *big.Int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL