Documentation
¶
Overview ¶
Package crypto 加解密、签名接口定义
Index ¶
- Constants
- Variables
- func BasicValidation(c Crypto, msg, pub, sig []byte) error
- func CRandBytes(numBytes int) []byte
- func CRandHex(numDigits int) string
- func CReader() io.Reader
- func GenDriverTypeID(name string) int32
- func GetCryptoList() ([]string, []int32)
- func GetName(ty int) string
- func GetType(name string) int
- func Init(cfg *Config, subCfg map[string][]byte)
- func MixEntropy(seedBytes []byte)
- func Register(name string, crypto Crypto, options ...RegOption)
- func Ripemd160(bytes []byte) []byte
- func Sha256(bytes []byte) []byte
- func Sm3Hash(msg []byte) []byte
- type AggregateCrypto
- type CertSignature
- type Config
- type Crypto
- type Driver
- type DriverInitFunc
- type LoadOption
- type PrivKey
- type PubKey
- type RegOption
- type Signature
Constants ¶
const (
// MaxManualTypeID 手动指定ID最大值 4095
MaxManualTypeID = 1<<12 - 1
)
Variables ¶
var ( //ErrNotSupportAggr 不支持聚合签名 ErrNotSupportAggr = errors.New("AggregateCrypto not support") //ErrSign 签名错误 ErrSign = errors.New("error signature") //ErrUnknownDriver 未注册加密插件 ErrUnknownDriver = errors.New("ErrUnknownDriver") //ErrDriverNotEnable 加密插件未开启 ErrDriverNotEnable = errors.New("ErrUnknownDriver") )
Functions ¶
func BasicValidation ¶ added in v1.65.1
BasicValidation 公私钥数据签名验证基础实现
func GenDriverTypeID ¶ added in v1.65.1
GenDriverTypeID 根据名称生成driver type id
func GetCryptoList ¶ added in v1.65.3
GetCryptoList 获取加密插件列表,名称和对应的类型值
func MixEntropy ¶
func MixEntropy(seedBytes []byte)
MixEntropy Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.
Types ¶
type AggregateCrypto ¶ added in v1.65.0
type AggregateCrypto interface { Aggregate(sigs []Signature) (Signature, error) AggregatePublic(pubs []PubKey) (PubKey, error) VerifyAggregatedOne(pubs []PubKey, m []byte, sig Signature) error VerifyAggregatedN(pubs []PubKey, ms [][]byte, sig Signature) error }
AggregateCrypto 聚合签名
func ToAggregate ¶ added in v1.65.0
func ToAggregate(c Crypto) (AggregateCrypto, error)
ToAggregate 判断签名是否可以支持聚合签名,并且返回聚合签名的接口
type Config ¶ added in v1.65.1
type Config struct { //支持只指定若干加密类型,不配置默认启用所有的加密插件, 如 types=["secp256k1", "sm2"] EnableTypes []string `json:"enableTypes,omitempty"` //支持对EnableTypes的每个加密插件分别设置启用高度, 不配置采用内置的启用高度 // [crypto.enableHeight] // secp256k1=0 EnableHeight map[string]int64 `json:"enableHeight,omitempty"` }
Config crypto模块配置
type Crypto ¶
type Crypto interface { GenKey() (PrivKey, error) SignatureFromBytes([]byte) (Signature, error) PrivKeyFromBytes([]byte) (PrivKey, error) PubKeyFromBytes([]byte) (PubKey, error) Validate(msg, pub, sig []byte) error }
Crypto 加密
type Driver ¶ added in v1.65.1
type Driver struct {
// contains filtered or unexported fields
}
Driver 加密插件及相关信息
type DriverInitFunc ¶ added in v1.65.1
type DriverInitFunc func(jsonCfg []byte)
DriverInitFunc 插件初始化接口,参数是序列化的json数据,需要unmarshal为自定义的结构
type LoadOption ¶ added in v1.66.1
LoadOption load crypto可选参数
func WithLoadOptionEnableCheck ¶ added in v1.66.1
func WithLoadOptionEnableCheck(blockHeight int64) LoadOption
WithLoadOptionEnableCheck 在New阶段根据当前区块高度进行插件使能检测
type PrivKey ¶
type PrivKey interface { Bytes() []byte Sign(msg []byte) Signature PubKey() PubKey Equals(PrivKey) bool }
PrivKey 私钥
type PubKey ¶
type PubKey interface { Bytes() []byte KeyString() string VerifyBytes(msg []byte, sig Signature) bool Equals(PubKey) bool }
PubKey 公钥
type RegOption ¶ added in v1.65.3
RegOption Register Driver可选参数,设置相关参数默认值
func WithRegOptionCGO ¶ added in v1.65.3
func WithRegOptionCGO() RegOption
WithRegOptionCGO 设置为CGO版本
func WithRegOptionDefaultDisable ¶ added in v1.65.3
func WithRegOptionDefaultDisable() RegOption
WithRegOptionDefaultDisable 设置默认不启用
func WithRegOptionInitFunc ¶ added in v1.65.3
func WithRegOptionInitFunc(fn DriverInitFunc) RegOption
WithRegOptionInitFunc 设置插件初始化接口
func WithRegOptionTypeID ¶ added in v1.65.3
WithRegOptionTypeID 手动指定typeID, 不指定情况,系统将根据name自动生成typeID
Directories
¶
Path | Synopsis |
---|---|
Package client 实现系统消息队列事件处理,新增client包避免循环引用
|
Package client 实现系统消息队列事件处理,新增client包避免循环引用 |
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
|
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202. |