-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Mimc on bls12-377 (#132)
Signed-off-by: AlexandreBelling <alexandrebelling8@gmail.com>
- Loading branch information
1 parent
eb6f9dd
commit a674a55
Showing
3 changed files
with
66 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
package main | ||
|
||
|
||
|
||
import "C" | ||
import "unsafe" | ||
import ( | ||
"github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" | ||
"unsafe" | ||
|
||
mimcBls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377/fr/mimc" | ||
mimcBn254 "github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" | ||
) | ||
|
||
func MiMCHash(b []byte) []byte { | ||
hasher := mimc.NewMiMC() | ||
hasher.Write(b) | ||
return hasher.Sum(nil) | ||
func MiMCBls12377Hash(b []byte) []byte { | ||
hasher := mimcBls12377.NewMiMC() | ||
hasher.Write(b) | ||
return hasher.Sum(nil) | ||
} | ||
|
||
func MiMCBn254Hash(b []byte) []byte { | ||
hasher := mimcBn254.NewMiMC() | ||
hasher.Write(b) | ||
return hasher.Sum(nil) | ||
} | ||
|
||
//export computeMimc | ||
func computeMimc(input *C.char, inputLength C.int, output *C.char) C.int { | ||
inputSlice := C.GoBytes(unsafe.Pointer(input), inputLength) | ||
outputSlice := (*[32]byte)(unsafe.Pointer(output))[:] | ||
hash := MiMCHash(inputSlice) | ||
copy(outputSlice, hash) | ||
return C.int(len(hash)) | ||
//export computeMimcBn254 | ||
func computeMimcBn254(input *C.char, inputLength C.int, output *C.char) C.int { | ||
inputSlice := C.GoBytes(unsafe.Pointer(input), inputLength) | ||
outputSlice := (*[32]byte)(unsafe.Pointer(output))[:] | ||
hash := MiMCBn254Hash(inputSlice) | ||
copy(outputSlice, hash) | ||
return C.int(len(hash)) | ||
} | ||
|
||
//export computeMimcBls12377 | ||
func computeMimcBls12377(input *C.char, inputLength C.int, output *C.char) C.int { | ||
inputSlice := C.GoBytes(unsafe.Pointer(input), inputLength) | ||
outputSlice := (*[32]byte)(unsafe.Pointer(output))[:] | ||
hash := MiMCBls12377Hash(inputSlice) | ||
copy(outputSlice, hash) | ||
return C.int(len(hash)) | ||
} | ||
|
||
func main() {} | ||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters