mirror of
https://github.com/logos-storage/nim-goldilocks-hash.git
synced 2026-01-05 23:23:07 +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"
|
version = "0.0.1"
|
||||||
author = "Balazs Komuves"
|
author = "Balazs Komuves"
|
||||||
description = "Airthmetic hash functions (Poseidon2, Monolith) over the Goldilocks field"
|
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
|
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 .}
|
# build system hack
|
||||||
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 .}
|
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
|
||||||
proc `-=`* (x: var F, y: F) = x = x - y
|
proc `-=`* (x: var F, y: F) = x = x - y
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import ../types
|
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
|
# keyed compression function
|
||||||
func compress*(a, b: Digest, key: uint64 = 0) : Digest =
|
func compress*(a, b: Digest, key: uint64 = 0) : Digest =
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
import ../types
|
import ../types
|
||||||
|
|
||||||
# the Monolith permutation (mutable, in-place version)
|
# the Monolith permutation (mutable, in-place version)
|
||||||
proc permInPlace* (state: var State) {. 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_hash/cbits/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)
|
# the Monolith permutation (pure version)
|
||||||
func perm*(state: State): State =
|
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 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_hash/cbits/goldilocks.h", importc: "goldilocks_monolith_bytes_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 =
|
func digestFeltsC*(rate: static int = 8, felts: openArray[F]): Digest =
|
||||||
var digest : F4
|
var digest : F4
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import ../types
|
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
|
# keyed compression function
|
||||||
func compress*(a, b: Digest, key: uint64 = 0) : Digest =
|
func compress*(a, b: Digest, key: uint64 = 0) : Digest =
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
import ../types
|
import ../types
|
||||||
|
|
||||||
# the Poseidon2 permutation (mutable, in-place version)
|
# the Poseidon2 permutation (mutable, in-place version)
|
||||||
proc permInPlace* (state: var State) {. 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_hash/cbits/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)
|
# the Poseidon2 permutation (pure version)
|
||||||
func perm*(state: State): State =
|
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 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_hash/cbits/goldilocks.h", importc: "goldilocks_poseidon2_bytes_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 =
|
func digestFeltsC*(rate: static int = 8, felts: openArray[F]): Digest =
|
||||||
var digest : F4
|
var digest : F4
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user