import "github.com/ethereum/go-ethereum/crypto"
const DigestLength = 32
DigestLength sets the signature digest exact length
const RecoveryIDOffset = 64
RecoveryIDOffset points to the byte offset within the signature that contains the recovery id.
const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id
SignatureLength indicates the byte length required to carry a signature with recovery id.
CompressPubkey encodes a public key to the 33-byte compressed format.
CreateAddress creates an ethereum address given the bytes and the nonce
CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.
DecompressPubkey parses a public key in the 33-byte compressed format.
Ecrecover returns the uncompressed public key that created the given signature.
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func GenerateKey() (*ecdsa.PrivateKey, error)
GenerateKey generates a new private key.
func HashData(kh KeccakState, data []byte) (h common.Hash)
HashData hashes the provided data using the KeccakState and returns a 32 byte hash
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
Keccak256 calculates and returns the Keccak256 hash of the input data.
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
Keccak512 calculates and returns the Keccak512 hash of the input data.
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
S256 returns an instance of the secp256k1 curve.
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
SigToPub returns the public key that created the given signature.
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 ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
UnmarshalPubkey converts bytes to a secp256k1 public key.
ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.
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.
KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.
func NewKeccakState() KeccakState
NewKeccakState creates a new KeccakState
Path | Synopsis |
---|---|
blake2b | Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb. |
bls12381 | |
bn256 | Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
bn256/cloudflare | Package bn256 implements a particular bilinear group at the 128-bit security level. |
bn256/google | Package bn256 implements a particular bilinear group. |
ecies | |
secp256k1 | Package secp256k1 wraps the bitcoin secp256k1 C library. |
signify |
Package crypto imports 17 packages (graph) and is imported by 6104 packages. Updated 2021-01-21. Refresh now. Tools for package owners.