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)
| 107 | // unambiguously parseable from the beginning of a string. |
| 108 | // Used to encode strings for all cSHAKE functions. |
| 109 | func 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 | } |