hashutil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilProto = errors.New("cannot hash a nil protobuf message")

ErrNilProto can occur when attempting to hash a protobuf message that is nil or has nil objects within lists.

Functions

func FastSum64

func FastSum64(data []byte) uint64

FastSum64 returns a hash sum of the input data using highwayhash. This method is not secure, but may be used as a quick identifier for objects where collisions are acceptable.

func Hash

func Hash(data []byte) [32]byte

Hash defines a function that returns the sha256 checksum of the data passed in. https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#appendix

func HashKeccak256

func HashKeccak256(data []byte) [32]byte

HashKeccak256 defines a function which returns the Keccak-256/SHA3 hash of the data passed in.

func HashProto

func HashProto(msg proto.Message) (result [32]byte, err error)

HashProto hashes a protocol buffer message using sha256.

func MerkleRoot

func MerkleRoot(values [][]byte) []byte

MerkleRoot derives the merkle root from a 2d byte array with each element in the outer array signifying the data that is to be represented in the merkle tree. Note: This function is only used to merklize a list of block root hashes. As such, we assume the input comes pre-hashed and do NOT hash the leaves. Spec:

def merkle_root(values):
	o = [0] * len(values) + values
	for i in range(len(values)-1, 0, -1):
		o[i] = hash(o[i*2] + o[i*2+1])
	return o[1]

func RepeatHash

func RepeatHash(data [32]byte, numTimes uint64) [32]byte

RepeatHash applies the sha256 hash function repeatedly numTimes on a [32]byte array.

Types

This section is empty.

Jump to

Keyboard shortcuts

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