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 GetName(ty int) string
- func GetType(name string) int
- func Init(cfg *Config, subCfg map[string][]byte)
- func IsEnable(name string, height int64) bool
- func MixEntropy(seedBytes []byte)
- func Register(name string, crypto Crypto, options ...Option)
- 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 Option
- type PrivKey
- type PubKey
- type Signature
Constants ¶
View Source
const MaxManualTypeID = math.MaxUint16 - 1
MaxManualTypeID 手动指定ID最大值 65534
Variables ¶
View Source
var ( //ErrNotSupportAggr 不支持聚合签名 ErrNotSupportAggr = errors.New("AggregateCrypto not support") //ErrSign 签名错误 ErrSign = errors.New("error signature") )
Functions ¶
func BasicValidation ¶
BasicValidation 公私钥数据签名验证基础实现
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 ¶
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 ¶
func ToAggregate(c Crypto) (AggregateCrypto, error)
ToAggregate 判断签名是否可以支持聚合签名,并且返回聚合签名的接口
type Config ¶
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 DriverInitFunc ¶
type DriverInitFunc func(jsonCfg []byte)
DriverInitFunc 插件初始化接口,参数是序列化的json数据,需要unmarshal为自定义的结构
type Option ¶
Option 注册Driver时可选参数,设置相关参数默认值
func WithOptionDefaultDisable ¶
func WithOptionDefaultDisable() Option
WithOptionDefaultDisable 设置默认不启用
func WithOptionInitFunc ¶
func WithOptionInitFunc(fn DriverInitFunc) Option
WithOptionInitFunc 设置插件初始化接口
func WithOptionTypeID ¶
WithOptionTypeID 手动指定typeID, 不指定情况,系统将根据name自动生成typeID
type PrivKey ¶
type PrivKey interface {
Bytes() []byte
Sign(msg []byte) Signature
PubKey() PubKey
Equals(PrivKey) bool
}
PrivKey 私钥
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |
Click to show internal directories.
Click to hide internal directories.