crypto

package
v1.0.2-dev Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: GPL-3.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

View Source
const PrivkeyLength = 144
View Source
const PubkeyLength = 56
View Source
const SignatureLength = 112 + 56

Variables

This section is empty.

Functions

func CompressPubkey

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

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

func ComputeSecret

func ComputeSecret(privkey *eddsa.PrivateKey, pubkey *eddsa.PublicKey) []byte

func CreateAddress

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

CreateAddress creates an core address given the bytes and the nonce

func CreateAddress2

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

CreateAddress2 creates an core address given the address bytes, initial contract code hash and a salt.

func DecompressPubkey

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

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

func Ecrecover

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

Ecrecover returns the uncompressed public key that created the given signature.

func FromEDDSA

func FromEDDSA(priv *eddsa.PrivateKey) []byte

FromEDDSA exports a private key into a binary dump.

func FromEDDSAPub

func FromEDDSAPub(pub *eddsa.PublicKey) []byte

func GenerateKey

func GenerateKey(read io.Reader) (*eddsa.PrivateKey, error)

func HexToEDDSA

func HexToEDDSA(hexkey string) (*eddsa.PrivateKey, error)

HexToEDDSA parses a secp256k1 private key.

func Keccak256

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

Keccak256 calculates and returns the Keccak256 hash of the input data. //Substituted in CoreCoin by NIPS SHA3-256

func Keccak256Hash

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

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func Keccak512

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

Keccak512 calculates and returns the Keccak512 hash of the input data.

func LoadEDDSA

func LoadEDDSA(file string) (*eddsa.PrivateKey, error)

LoadEDDSA loads a secp256k1 private key from the given file.

func PubkeyToAddress

func PubkeyToAddress(p eddsa.PublicKey) common.Address

func SHA3 added in v1.0.48

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

NIPS implementation of SHA3-256

func SHA3Hash added in v1.0.48

func SHA3Hash(data ...[]byte) (h common.Hash)

SHA3Hash calculates and returns the NIPS SHA3-256 hash of the input data, converting it to an internal Hash data structure.

func SHA3_512 added in v1.0.48

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

NIPS implementation of SHA3-512

func SaveEDDSA

func SaveEDDSA(file string, key *eddsa.PrivateKey) error

SaveEDDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.

func SigToPub

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

SigToPub returns the public key that created the given signature.

func Sign

func Sign(hash []byte, prv *eddsa.PrivateKey) (sig []byte, err error)

Sign calculates an EDDSA 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 ToEDDSA

func ToEDDSA(d []byte) (*eddsa.PrivateKey, error)

ToEDDSA creates a private key with the given D value.

func ToEDDSAUnsafe

func ToEDDSAUnsafe(d []byte) *eddsa.PrivateKey

ToEDDSAUnsafe 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).

func UnmarshalPubkey

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

UnmarshalPubkey converts bytes to a secp256k1 public key.

func ValidateSignatureValues

func ValidateSignatureValues(v byte) bool

ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.

func VerifySignature

func VerifySignature(pub, hash, signature []byte) bool

VerifySignature checks that the given public key created signature over hash.

Types

This section is empty.

Directories

Path Synopsis
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb.
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
google
Package bn256 implements a particular bilinear group.
Package bn256 implements a particular bilinear group.

Jump to

Keyboard shortcuts

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