Documentation ¶
Index ¶
- Constants
- Variables
- func NormalizePoCBytes(vb []byte, bitLength int) []byte
- func PoCValue2Bytes(v PoCValue, bitLength int) []byte
- func RecordSize(bitLength int) int
- type Hash
- type PoCValue
- func Bytes2PoCValue(vb []byte, bl int) PoCValue
- func CutBigInt(bi *big.Int, bl int) PoCValue
- func CutHash(hash Hash, bl int) PoCValue
- func F(x, xp PoCValue, bl int, pubKeyHash Hash) PoCValue
- func FB(x, xp []byte, bl int, pubKeyHash Hash) PoCValue
- func FlipValue(v PoCValue, bl int) PoCValue
- func P(x PoCValue, bl int, pubKeyHash Hash) PoCValue
- func PB(x []byte, bl int, pubKeyHash Hash) PoCValue
Constants ¶
const (
// PoCPrefixLen represents the byte length of PoCPrefix.
PoCPrefixLen = 4
)
Variables ¶
var ErrInvalidHashLength = errors.New("invalid length for hash")
ErrInvalidHashLength indicates the length of hash is invalid.
var ( // PoCPrefix is the prefix for PoC Calculation. PoCPrefix = []byte("MASS") )
Functions ¶
func NormalizePoCBytes ¶
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 ¶
PoCValue2Bytes encodes a PoCValue to bytes, size depending on its bitLength.
func RecordSize ¶
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 ¶
DecodeStringToHash decodes a string value to Hash, the length of string value must be 64.
func DoubleSHA256 ¶
DoubleSHA256 represents the standard double sha256.
func PubKeyHash ¶
PubKeyHash returns the hash of pubKey.
func SktDoubleSHA256 ¶
SktDoubleSHA256 represents the unique Skt double sha256.
type PoCValue ¶
type PoCValue uint64
PoCValue represents the value type of PoC Record.
func Bytes2PoCValue ¶
Bytes2PoCValue decodes a PoCValue from bytes, size depending on its bitLength.
func CutHash ¶
CutHash cuts the least significant 8 bytes of Hash, decoding it as little endian uint64, and masking result to bitLength value.
func F ¶
F calculates SktSHA256(PoCPrefix || PubKeyHash || X || XP).CutByBitLength(bitLength), it takes in (x, xp) as PoCValue.
func FB ¶
FB calculates SktSHA256(PoCPrefix || PubKeyHash || X || XP).CutByBitLength(bitLength), it takes in (x, xp) 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. |