mirror of
https://github.com/logos-storage/nim-poseidon2.git
synced 2026-01-17 04:53:14 +00:00
Document conversion of bytes into field elements
This commit is contained in:
parent
0344d9ab45
commit
eb56d5bba2
@ -3,6 +3,10 @@ import constantine/math/arithmetic
|
||||
import constantine/math/io/io_bigints
|
||||
|
||||
func unmarshal*(_: type F, bytes: openArray[byte]): F =
|
||||
## Converts bytes into a field element. The byte array is interpreted as a
|
||||
## canonical little-endian big integer. The array should be of length 31 bytes
|
||||
## or less to ensure that it fits in a field of 254 bits. The remaining
|
||||
## 6 most-significant bits are set to 0.
|
||||
assert bytes.len <= 31
|
||||
var padded: array[32, byte]
|
||||
copyMem(addr padded[0], unsafeAddr bytes[0], bytes.len)
|
||||
@ -10,6 +14,8 @@ func unmarshal*(_: type F, bytes: openArray[byte]): F =
|
||||
return F.fromBig(bigint)
|
||||
|
||||
func unmarshal*(_: type seq[F], bytes: openArray[byte]): seq[F] =
|
||||
## Converts bytes into field elements. The byte array is converted 31 bytes at
|
||||
## a time with the `F.unmarshal()` function.
|
||||
const chunkLen = 31
|
||||
var elements: seq[F]
|
||||
var chunkStart = 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user