MCPcopy Create free account
hub / github.com/chain/txvm / leftEncode

Function leftEncode

crypto/sha3/cshake.go:109–127  ·  view source on GitHub ↗

leftEncode encodes integer in a variable-length encoding unambiguously parseable from the beginning of a string. Used to encode strings for all cSHAKE functions.

(d *state, value uint64)

Source from the content-addressed store, hash-verified

107// unambiguously parseable from the beginning of a string.
108// Used to encode strings for all cSHAKE functions.
109func leftEncode(d *state, value uint64) int {
110 input := d.varintbuf[:]
111 copy(input, zero[:])
112 var offset uint
113 if value == 0 {
114 offset = 8
115 } else {
116 binary.BigEndian.PutUint64(input[1:], value)
117 for offset = 0; offset < 9; offset++ {
118 if input[offset] != 0 {
119 break
120 }
121 }
122 }
123 input[offset-1] = byte(9 - offset)
124 b := input[offset-1:]
125 d.Write(b)
126 return len(b)
127}

Callers 5

newKMACFunction · 0.85
BenchmarkLeftEncodeFunction · 0.85
WriteItemPrefixMethod · 0.85
initCShakeMethod · 0.85
encodeStringFunction · 0.85

Calls 1

WriteMethod · 0.45

Tested by 1

BenchmarkLeftEncodeFunction · 0.68