hash

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: ISC Imports: 13 Imported by: 5

Documentation

Overview

Copyright (c) 2020-2021 The bitcoinpay developers

Copyright (c) 2020-2021 The bitcoinpay developers

Index

Constants

View Source
const HashSize = 32
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.

View Source
var ZeroHash = Hash([32]byte{
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
})

Functions

func CalcHash

func CalcHash(buf []byte, hasher h.Hash) []byte

Calculate the hash of hasher over buf.

func Decode

func Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func DoubleHashB

func DoubleHashB(b []byte) []byte

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

func DoubleHashB_pool

func DoubleHashB_pool(b []byte) []byte

func Hash160

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(hash256(b)).

func Hash512B

func Hash512B(b []byte) []byte

Hash512B using blake2b calculates 512 bits hash and returns the resulting bytes.

func HashB

func HashB(b []byte) []byte

HashB using blake2b calculates 256 bits hash and returns the resulting bytes.

func HashB_pool

func HashB_pool(b []byte) []byte

using pool

Types

type Hash

type Hash [HashSize]byte

func DoubleHashH

func DoubleHashH(b []byte) Hash

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

func DoubleHashH_pool

func DoubleHashH_pool(b []byte) Hash

func HashBitcoinpayKeccak256

func HashBitcoinpayKeccak256(b []byte) Hash

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

func HashH

func HashH(b []byte) Hash

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

func HashH_pool

func HashH_pool(b []byte) Hash

func HashX16rv3

func HashX16rv3(b []byte) Hash

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

func HashX8r16

func HashX8r16(b []byte) Hash

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

func MustBytesToDecodeHash

func MustBytesToDecodeHash(b []byte) Hash

convert []byte to a byte-reversed hash, Must means it panics for invalid input.

func MustBytesToHash

func MustBytesToHash(b []byte) Hash

convert []byte to a hash, Must means it panics for invalid input.

func MustHexToDecodedHash

func MustHexToDecodedHash(i string) Hash

convert hex string to a byte-reversed hash, Must means it panics for invalid input.

func MustHexToHash

func MustHexToHash(i string) Hash

convert hex string to a hash. Must means it panics for invalid input.

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 (h Hash) Bytes() []byte

func (*Hash) CloneBytes

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

CloneBytes returns a copy of the bytes which represent the hash as a byte slice.

NOTE: 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.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional. TODO clean-up the byte-reverse hash

type Hash256

type Hash256 [32]byte

type Hash512

type Hash512 [64]byte

type HashType

type HashType byte
const (
	SHA256 HashType = iota
	Keccak_256
	SHA3_256
	SHA3_512
	Ripemd160
	Blake2b_256
	Blake2b_512
)

TODO refactoring hasher consider to integrated https://github.com/multiformats/go-multihash

type Hasher

type Hasher interface {
	hash.Hash
}

func GetHasher

func GetHasher(ht HashType) Hasher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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