mirror of
https://github.com/logos-storage/nim-goldilocks-hash.git
synced 2026-01-06 23:53:11 +00:00
add some convenience functions converting digests to field element sequences
This commit is contained in:
parent
2d201ea8bb
commit
bd5b805b80
@ -6,6 +6,7 @@ import ./types
|
|||||||
# build system hack
|
# build system hack
|
||||||
|
|
||||||
const
|
const
|
||||||
|
# REMARK: currentSourcePath = ~/.nimble/pkgs/goldilocks_hash-0.0.1/goldilocks_hash/goldilocks.nim
|
||||||
root = currentSourcePath.parentDir.parentDir
|
root = currentSourcePath.parentDir.parentDir
|
||||||
|
|
||||||
{. passc: "-I" & root & "/cbits" .}
|
{. passc: "-I" & root & "/cbits" .}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import std/sequtils
|
||||||
import std/strformat
|
import std/strformat
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
@ -55,6 +56,15 @@ proc `$`*(x: Digest): string = return $(fromDigest(x))
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func digestToFeltSeq*( d: Digest ): seq[F] =
|
||||||
|
var output: seq[F] = newSeq[F]( 4 )
|
||||||
|
let f4 = fromDigest( d )
|
||||||
|
output[0] = f4[0]
|
||||||
|
output[1] = f4[1]
|
||||||
|
output[2] = f4[2]
|
||||||
|
output[3] = f4[3]
|
||||||
|
return output
|
||||||
|
|
||||||
func digestSeqToFeltSeq*( ds: seq[Digest] ): seq[F] =
|
func digestSeqToFeltSeq*( ds: seq[Digest] ): seq[F] =
|
||||||
let n = ds.len
|
let n = ds.len
|
||||||
var output: seq[F] = newSeq[F]( 4*n )
|
var output: seq[F] = newSeq[F]( 4*n )
|
||||||
@ -67,6 +77,9 @@ func digestSeqToFeltSeq*( ds: seq[Digest] ): seq[F] =
|
|||||||
output[j+3] = f4[3]
|
output[j+3] = f4[3]
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
func digestSeqToFeltSeqSeq*( ds: seq[Digest] ): seq[seq[F]]
|
||||||
|
= ds.map(digestToFeltSeq)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
func numberOfBits*(T: type): int {.compileTime.} =
|
func numberOfBits*(T: type): int {.compileTime.} =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user