pocutil

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PoCPrefixLen represents the byte length of PoCPrefix.
	PoCPrefixLen = 4
)

Variables

View Source
var ErrInvalidHashLength = errors.New("invalid length for hash")

ErrInvalidHashLength indicates the length of hash is invalid.

View Source
var (
	// PoCPrefix is the prefix for PoC Calculation.
	PoCPrefix = []byte("MASS")
)

Functions

func NormalizePoCBytes

func NormalizePoCBytes(vb []byte, bl int) []byte

NormalizePoCBytes sets vb and returns vb according to its bitLength, upper bits would be set to zero.

func PoCValue2Bytes

func PoCValue2Bytes(v PoCValue, bl int) []byte

PoCValue2Bytes encodes a PoCValue to bytes, size depending on its bitLength.

func RecordSize

func RecordSize(bl int) int

RecordSize returns the size of a bitLength record, in byte unit.

Types

type Hash

type Hash [32]byte

Hash represents a 32-byte hash value.

func DecodeStringToHash

func DecodeStringToHash(str string) (Hash, error)

DecodeStringToHash decodes a string value to Hash, the length of string value must be 64.

func DoubleSHA256

func DoubleSHA256(raw []byte) Hash

DoubleSHA256 represents the standard double sha256.

func MASSDoubleSHA256

func MASSDoubleSHA256(raw []byte) Hash

MASSDoubleSHA256 represents the unique MASS double sha256.

func MASSSHA256

func MASSSHA256(raw []byte) Hash

MASSSHA256 represents the unique MASS sha256.

func PubKeyHash

func PubKeyHash(pubKey *pocec.PublicKey) Hash

PubKeyHash returns the hash of pubKey.

func PubKeyItfHash

func PubKeyItfHash(pubKey interfaces.PublicKey) Hash

func SHA256

func SHA256(raw []byte) Hash

SHA256 represents the standard sha256.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes converts Hash to Byte Slice.

func (Hash) String

func (h Hash) String() string

String converts Hash to String.

type PoCValue

type PoCValue uint64

PoCValue represents the value type of PoC Record.

func Bytes2PoCValue

func Bytes2PoCValue(vb []byte, bl int) PoCValue

Bytes2PoCValue decodes a PoCValue from bytes, size depending on its bitLength.

func CutBigInt

func CutBigInt(bi *big.Int, bl int) PoCValue

CutBigInt cuts big.Int to uint64, masking result to bitLength value.

func CutHash

func CutHash(hash Hash, bl int) PoCValue

CutHash cuts the least significant 8 bytes of Hash, decoding it as little endian uint64, and masking result to bitLength value.

func F

func F(x, xp PoCValue, bl int, pubKeyHash Hash) PoCValue

F calculates MASSSHA256(PoCPrefix || PubKeyHash || X || XP).CutByBitLength(bitLength), it takes in (x, xp) as PoCValue.

func FB

func FB(x, xp []byte, bl int, pubKeyHash Hash) PoCValue

FB calculates MASSSHA256(PoCPrefix || PubKeyHash || X || XP).CutByBitLength(bitLength), it takes in (x, xp) as Byte Slice.

func FlipValue

func FlipValue(v PoCValue, bl int) PoCValue

FlipValue flips(bit-flip) the bitLength bits of a PoCValue.

func P

func P(x PoCValue, bl int, pubKeyHash Hash) PoCValue

P calculates MASSSHA256(PoCPrefix || PubKeyHash || X).CutByBitLength(bitLength), it takes in x as PoCValue.

func PB

func PB(x []byte, bl int, pubKeyHash Hash) PoCValue

PB calculates MASSSHA256(PoCPrefix || PubKeyHash || X).CutByBitLength(bitLength), it takes in x as Byte Slice.

Directories

Path Synopsis
Package crypto collects common cryptographic constants.
Package crypto collects common cryptographic constants.
hash
Package hash provides interfaces for hash functions.
Package hash provides interfaces for hash functions.
sha256
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-4.

Jump to

Keyboard shortcuts

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