bhash

package module
v0.0.0-...-107dfd8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 3 Imported by: 11

README

bhash

Bitcoin hashing utilities.

Documentation

Overview

Package bhash exposes commonly used utility functions for hashing data in Bitcoin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoubleSha256

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

DoubleSha256 returns the double-SHA256 hash of the given data.

func Hash160

func Hash160(data []byte) [20]byte

Hash160 returns the rmd160 hash of a SHA256 hash of the given data.

func NewTaggedHasher

func NewTaggedHasher(tag string) func(...[]byte) []byte

NewTaggedHasher returns a function which generates a hash whose preimage is prepended twice with the hash of the given tag string.

tagged_hash(tag, ...chunks) = sha256(sha256(tag) || sha256(tag) || chunks...)

func Ripemd160

func Ripemd160(data []byte) (result [20]byte)

Ripemd160 returns the rmd160 hash of the given data.

func Sha256

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

Sha256 returns the SHA256 hash of the given data.

Types

type MultiHasher

type MultiHasher struct {
	// contains filtered or unexported fields
}

MultiHasher is a chain of cryptographic hashes, one feeding into the next from first to last. Think of it as an io.MultiWriter but for hash functions.

func NewMultiHasher

func NewMultiHasher(hashes ...hash.Hash) *MultiHasher

NewMultiHasher returns a pointer to a new MultiHasher, which will use the given hashes provided to hash data.

func (*MultiHasher) BlockSize

func (mh *MultiHasher) BlockSize() int

BlockSize returns the block size of the first hash in the chain.

func (*MultiHasher) Reset

func (mh *MultiHasher) Reset()

Reset resets the MultiHasher to its initial state.

func (*MultiHasher) Size

func (mh *MultiHasher) Size() int

Size returns the output size of the last hash in the chain.

func (*MultiHasher) Sum

func (mh *MultiHasher) Sum(b []byte) []byte

Sum computes the final hash by piping output from each hash to the next in the chain, returning the result of appending the final hash to b. If b is nil, it simply returns the finalized hash.

func (*MultiHasher) Write

func (mh *MultiHasher) Write(p []byte) (int, error)

Write writes the given data to the MultiHasher.

Jump to

Keyboard shortcuts

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