chainhash

package
v0.0.0-...-619de72 Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: ISC Imports: 3 Imported by: 0

README

chainhash

chainhash is a wrapper around the hash function used for decred. It is designed to isolate the code that needs to differ between btcd and dcrd.

Installation and updating

$ go get -u github.com/decred/dcrd/chaincfg/chainhash

Documentation

Overview

Package chainhash defines the hash functions used.

This package provides a wrapper around the hash function used. This is designed to isolate the code that needs to be changed to support coins with different hash functions (i.e, bitcoin vs decred).

Index

Constants

View Source
const HashBlockSize = blake256.BlockSize

HashBlockSize is the block size of the hash algorithm in bytes.

View Source
const HashSize = 32

HashSize of array used to store hashes. See Hash.

View Source
const MaxHashStringSize = HashSize * 2

MaxHashStringSize is the maximum length of a Hash hash string.

Variables

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

Functions

func HashFunc

func HashFunc(data []byte) [blake256.Size]byte

HashFunc calculates the hash of the supplied bytes. TODO(jcv) Should modify blake256 so it has the same interface as blake2 and fastsha256 so these function can look more like btcsuite. Then should try to get it to the upstream blake256 repo

func HashFuncB

func HashFuncB(b []byte) []byte

HashFuncB calculates hash(b) and returns the resulting bytes.

Types

type Hash

type Hash [HashSize]byte

Hash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.

func HashFuncH

func HashFuncH(b []byte) Hash

HashFuncH calculates hash(b) and returns the resulting bytes as a Hash.

func NewHash

func NewHash(newHash []byte) (*Hash, error)

NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func NewHashFromStr

func NewHashFromStr(hash string) (*Hash, error)

NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (*Hash) Bytes

func (hash *Hash) Bytes() []byte

Bytes returns the bytes which represent the hash as a byte slice.

NOTE: This makes a copy of the bytes and should have probably been named CloneBytes. It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.

func (*Hash) IsEqual

func (hash *Hash) IsEqual(target *Hash) bool

IsEqual returns true if target is the same as hash.

func (*Hash) SetBytes

func (hash *Hash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (Hash) String

func (hash Hash) String() string

String returns the Hash as the hexadecimal string of the byte-reversed hash.

Jump to

Keyboard shortcuts

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