pocutil

package
v0.0.0-...-163fc3c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 7 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, bitLength int) []byte

NormalizePoCBytes sets vb and returns vb according to its bitLength, upper bits would be set to zero. 0 size -1 size +----------------+--------+-------------+ | | 8 bits | 0 | +----------------+--------+-------------+

func PoCValue2Bytes

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

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

func RecordSize

func RecordSize(bitLength int) int

RecordSize returns the size of a bitLength record, in byte unit. mask 7 -> 0000 0111 + >>3

24  -> 0001 1000   -> 31  0001 1111     3 0000 0011
26  -> 0001 1010   -> 33  0010 0001     4 0000 0100
28  -> 0001 1100   -> 35  0010 0011     4 0000 0100
32  -> 0010 0000   -> 39  0010 0111     4 0000 0100
34  -> 0010 0010   -> 41  0010 1001     5 0000 0101
36  -> 0010 0100   -> 43  0010 1011     5 0000 0101
38  -> 0010 0110   -> 45  0010 1101     5 0000 0101
40  -> 0010 1000   -> 47  0010 1111     5 0000 0101

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 PubKeyHash

func PubKeyHash(pubKey *pocec.PublicKey) Hash

PubKeyHash returns the hash of pubKey.

func SHA256

func SHA256(raw []byte) Hash

SHA256 represents the standard sha256.

func SktDoubleSHA256

func SktDoubleSHA256(raw []byte) Hash

SktDoubleSHA256 represents the unique Skt double sha256.

func SktSHA256

func SktSHA256(raw []byte) Hash

SktSHA256 represents the unique Skt 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 SktSHA256(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 SktSHA256(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 SktSHA256(PoCPrefix || PubKeyHash || X).CutByBitLength(bitLength), it takes in x as PoCValue.

func PB

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

PB calculates SktSHA256(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