mirror of
https://github.com/logos-storage/nim-goldilocks-hash.git
synced 2026-01-02 13:43:09 +00:00
yet another attempt to make it work as nimble dependency (this time it seem successful)
This commit is contained in:
parent
0d12b14293
commit
2d201ea8bb
@ -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"]
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user