mirror of
https://github.com/codex-storage/nim-poseidon2.git
synced 2025-02-23 08:18:05 +00:00
Add Sponge.digest() call that takes bytes
This commit is contained in:
parent
d8a176930d
commit
70c03b834f
@ -65,3 +65,9 @@ func digest*(_: type Sponge, elements: openArray[F], rate: static int): F =
|
|||||||
for element in elements:
|
for element in elements:
|
||||||
sponge.update(element)
|
sponge.update(element)
|
||||||
return sponge.finish()
|
return sponge.finish()
|
||||||
|
|
||||||
|
func digest*(_: type Sponge, bytes: openArray[byte], rate: static int): F =
|
||||||
|
var sponge = Sponge.init(rate)
|
||||||
|
for element in bytes.elements(F):
|
||||||
|
sponge.update(element)
|
||||||
|
return sponge.finish()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import std/unittest
|
import std/unittest
|
||||||
|
import std/sequtils
|
||||||
|
|
||||||
import constantine/math/io/io_fields
|
import constantine/math/io/io_fields
|
||||||
|
import constantine/math/arithmetic
|
||||||
|
|
||||||
import poseidon2/types
|
import poseidon2/types
|
||||||
import poseidon2
|
import poseidon2
|
||||||
@ -48,3 +50,9 @@ suite "sponge":
|
|||||||
xs.add( toF(i) )
|
xs.add( toF(i) )
|
||||||
let h = Sponge.digest(xs, rate = 2)
|
let h = Sponge.digest(xs, rate = 2)
|
||||||
check toDecimal(h) == expectedSpongeResultsRate2[n]
|
check toDecimal(h) == expectedSpongeResultsRate2[n]
|
||||||
|
|
||||||
|
test "sponge with byte array as input":
|
||||||
|
let bytes = toSeq 1'u8..80'u8
|
||||||
|
let elements = toSeq bytes.elements(F)
|
||||||
|
let expected = Sponge.digest(elements, rate = 2)
|
||||||
|
check bool(Sponge.digest(bytes, rate = 2) == expected)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user