crypto

package
v0.0.0-...-de85661 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Unlicense Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DigestLength = 32

DigestLength设置签名摘要的精确长度

View Source
const RecoveryIDOffset = 64

RecoveryIDOffset points to the byte offset within the signature that contains the recovery id.

View Source
const SignatureLength = 64 + 1 // 64字节ECDSA签名+1字节恢复id

SignatureLength表示携带具有恢复id的签名所需的字节长度。

Variables

This section is empty.

Functions

func CompressPubkey

func CompressPubkey(pubkey *ecdsa.PublicKey) []byte

CompressPubkey encodes a public key to the 33-byte compressed format.

func CreateAddress

func CreateAddress(b entity.Address, nonce uint64) entity.Address

CreateAddress在给定字节和nonce的情况下创建以太坊地址

func CreateAddress2

func CreateAddress2(b entity.Address, salt [32]byte, inithash []byte) entity.Address

CreateAddress2在给定地址字节、初始合同代码哈希和salt的情况下创建以太坊地址。

func DecompressPubkey

func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)

DecompressPubkey parses a public key in the 33-byte compressed format.

func Ecrecover

func Ecrecover(hash, sig []byte) ([]byte, error)

Ecrecover返回创建给定签名的未压缩公钥。

func FromECDSA

func FromECDSA(priv *ecdsa.PrivateKey) []byte

从ECDSA将私钥导出到二进制转储。

func FromECDSAPub

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey生成新的私钥。

func HexToECDSA

func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)

HexToECDSA解析secp256k1私钥。

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256计算并返回输入数据的Keccak256哈希。

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h entity.Hash)

Keccak256哈希计算并返回输入数据的Keccak256哈希,将其转换为内部哈希数据结构。

func Keccak512

func Keccak512(data ...[]byte) []byte

Keccak512计算并返回输入数据的Keccak512哈希。

func LoadECDSA

func LoadECDSA(file string) (*ecdsa.PrivateKey, error)

LoadECDSA从给定文件加载secp256k1私钥。

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) entity.Address

func S256

func S256() elliptic.Curve

S256返回secp256k1曲线的实例。

func SaveECDSA

func SaveECDSA(file string, key *ecdsa.PrivateKey) error

SaveECDSA将secp256k1私钥保存到具有限制权限的给定文件。密钥数据以十六进制编码保存。

func SigToPub

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub returns the public key that created the given signature.

func Sign

func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)

Sign calculates an ECDSA signature.

This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given digest cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.

The produced signature is in the [R || S || V] format where V is 0 or 1.

func SignECDSA

func SignECDSA(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)

Sign计算ECDSA签名。 此函数容易受到选定的明文攻击,这些攻击可能会泄漏有关用于签名的私钥的信息。 呼叫者必须意识到对手无法选择给定摘要。常见的解决方案是在计算签名之前对任何输入进行散列。 生成的签名采用[R | | S | V]格式,其中V为0或1。

func ToECDSA

func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)

ToECDSA创建具有给定D值的私钥。

func ToECDSAUnsafe

func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey

ToecdsanSafe盲目地将二进制blob转换为私钥。除非您确信输入有效,并且希望避免由于错误的原点编码(0个前缀被截断)而导致的错误,否则几乎不应该使用它。

func UnmarshalPubkey

func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)

UnmarshalPubkey converts bytes to a secp256k1 public key.

func ValidateSignatureValues

func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool

ValidateSignatureValues验证签名值对于给定的链规则是否有效。假设v值为0或1。

func VerifySignature

func VerifySignature(pubkey, digestHash, signature []byte) bool

VerifySignature checks that the given public key created signature over digest. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.

Types

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

KeccakState包裹sha3。状态除了通常的散列方法外,它还支持读取以从散列状态获取可变数量的数据。Read比Sum快,因为它不复制内部状态,但也修改内部状态。

func NewKeccakState

func NewKeccakState() KeccakState

NewKeccakState创建新的KeccakState

Directories

Path Synopsis
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.

Jump to

Keyboard shortcuts

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