hashutil

package
v1.0.0-alpha.6.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package hashutil includes all hash-function related helpers for Prysm.

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 CustomSHA256Hasher added in v0.3.2

func CustomSHA256Hasher() func([]byte) [32]byte

CustomSHA256Hasher returns a hash function that uses an enclosed hasher. This is not safe for concurrent use as the same hasher is being called throughout.

Note: that this method is only more performant over hashutil.Hash if the callback is used more than 5 times.

func FastSum256 added in v0.3.0

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

FastSum256 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 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/v0.9.3/specs/core/0_beacon-chain.md#hash

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