yet another attempt to make it work as nimble dependency (this time it seem successful)

This commit is contained in:
Balazs Komuves 2024-10-22 11:47:26 +02:00
parent 0d12b14293
commit 2d201ea8bb
No known key found for this signature in database
GPG Key ID: F63B7AEF18435562
13 changed files with 30 additions and 18 deletions

View File

@ -1,5 +1,6 @@
version = "0.0.1"
author = "Balazs Komuves"
version = "0.0.1"
author = "Balazs Komuves"
description = "Airthmetic hash functions (Poseidon2, Monolith) over the Goldilocks field"
license = "MIT"
license = "MIT"
installDirs = @["cbits"]

View File

@ -1,11 +1,22 @@
{. compile: "../goldilocks_hash/cbits/goldilocks.c" .}
import os
import ./types
func neg* (x: F ): F {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_neg", cdecl .}
func `+`* (x, y: F): F {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_add", cdecl .}
func `-`* (x, y: F): F {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_sub", cdecl .}
func `*`* (x, y: F): F {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_mul", cdecl .}
#-------------------------------------------------------------------------------
# build system hack
const
root = currentSourcePath.parentDir.parentDir
{. passc: "-I" & root & "/cbits" .}
{. compile: root & "/cbits/goldilocks.c" .}
#-------------------------------------------------------------------------------
func neg* (x: F ): F {. header: "goldilocks.h", importc: "goldilocks_neg", cdecl .}
func `+`* (x, y: F): F {. header: "goldilocks.h", importc: "goldilocks_add", cdecl .}
func `-`* (x, y: F): F {. header: "goldilocks.h", importc: "goldilocks_sub", cdecl .}
func `*`* (x, y: F): F {. header: "goldilocks.h", importc: "goldilocks_mul", cdecl .}
proc `+=`* (x: var F, y: F) = x = x + y
proc `-=`* (x: var F, y: F) = x = x - y

View File

@ -1,7 +1,7 @@
import ../types
proc c_compress(a, b: var Digest, key: uint64, output: var Digest) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_keyed_compress", cdecl .}
proc c_compress(a, b: var Digest, key: uint64, output: var Digest) {. header: "goldilocks.h", importc: "goldilocks_monolith_keyed_compress", cdecl .}
# keyed compression function
func compress*(a, b: Digest, key: uint64 = 0) : Digest =

View File

@ -2,8 +2,8 @@
import ../types
# the Monolith permutation (mutable, in-place version)
proc permInPlace* (state: var State) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_permutation", cdecl .}
proc permInPlaceF12*(state: var F12 ) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_permutation", cdecl .}
proc permInPlace* (state: var State) {. header: "goldilocks.h", importc: "goldilocks_monolith_permutation", cdecl .}
proc permInPlaceF12*(state: var F12 ) {. header: "goldilocks.h", importc: "goldilocks_monolith_permutation", cdecl .}
# the Monolith permutation (pure version)
func perm*(state: State): State =

View File

@ -79,8 +79,8 @@ func digestNim*(rate: static int = 8, elements: openArray[F]): Digest =
#---------------------------------------
proc digestFeltsRawC(rate: int, len: int, input: ptr F , hash: var F4) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_felts_digest", cdecl .}
proc digestBytesRawC(rate: int, len: int, input: ptr byte, hash: var F4) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_bytes_digest", cdecl .}
proc digestFeltsRawC(rate: int, len: int, input: ptr F , hash: var F4) {. header: "goldilocks.h", importc: "goldilocks_monolith_felts_digest", cdecl .}
proc digestBytesRawC(rate: int, len: int, input: ptr byte, hash: var F4) {. header: "goldilocks.h", importc: "goldilocks_monolith_bytes_digest", cdecl .}
func digestFeltsC*(rate: static int = 8, felts: openArray[F]): Digest =
var digest : F4

View File

@ -1,7 +1,7 @@
import ../types
proc c_compress(a, b: var Digest, key: uint64, output: var Digest) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_keyed_compress", cdecl .}
proc c_compress(a, b: var Digest, key: uint64, output: var Digest) {. header: "goldilocks.h", importc: "goldilocks_poseidon2_keyed_compress", cdecl .}
# keyed compression function
func compress*(a, b: Digest, key: uint64 = 0) : Digest =

View File

@ -2,8 +2,8 @@
import ../types
# the Poseidon2 permutation (mutable, in-place version)
proc permInPlace* (state: var State) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .}
proc permInPlaceF12*(state: var F12 ) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .}
proc permInPlace* (state: var State) {. header: "goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .}
proc permInPlaceF12*(state: var F12 ) {. header: "goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .}
# the Poseidon2 permutation (pure version)
func perm*(state: State): State =

View File

@ -79,8 +79,8 @@ func digestNim*(rate: static int = 8, elements: openArray[F]): Digest =
#---------------------------------------
proc digestFeltsRawC(rate: int, len: int, input: ptr F , hash: var F4) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_felts_digest", cdecl .}
proc digestBytesRawC(rate: int, len: int, input: ptr byte, hash: var F4) {. header: "../goldilocks_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_bytes_digest", cdecl .}
proc digestFeltsRawC(rate: int, len: int, input: ptr F , hash: var F4) {. header: "goldilocks.h", importc: "goldilocks_poseidon2_felts_digest", cdecl .}
proc digestBytesRawC(rate: int, len: int, input: ptr byte, hash: var F4) {. header: "goldilocks.h", importc: "goldilocks_poseidon2_bytes_digest", cdecl .}
func digestFeltsC*(rate: static int = 8, felts: openArray[F]): Digest =
var digest : F4