mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-07 11:36:41 +01:00
Poseidon Sponge Hash with different frame sizes (#52)
* Poseidon Sponge Hash with different frame sizes * Update deps. Bump go version * Update & fix linter. * Refactor a bit. * Reduce gc pressure
This commit is contained in:
committed by
GitHub
parent
edc36bfa52
commit
e5cf066b8b
@@ -3,10 +3,14 @@ package poseidon
|
||||
import "github.com/iden3/go-iden3-crypto/ffg"
|
||||
|
||||
const (
|
||||
NROUNDSF = 8 //nolint:golint
|
||||
NROUNDSP = 22 //nolint:golint
|
||||
CAPLEN = 4 //nolint:golint
|
||||
mLen = 12
|
||||
// NROUNDSF const from original paper
|
||||
NROUNDSF = 8
|
||||
// NROUNDSP const from original paper
|
||||
NROUNDSP = 22
|
||||
// CAPLEN const
|
||||
CAPLEN = 4
|
||||
// mLen const
|
||||
mLen = 12
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -10,9 +10,11 @@ func zero() *ffg.Element {
|
||||
return ffg.NewElement()
|
||||
}
|
||||
|
||||
var big7 = big.NewInt(7)
|
||||
|
||||
// exp7 performs x^7 mod p
|
||||
func exp7(a *ffg.Element) {
|
||||
a.Exp(*a, big.NewInt(7)) //nolint:gomnd
|
||||
a.Exp(*a, big7)
|
||||
}
|
||||
|
||||
// exp7state perform exp7 for whole state
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package poseidon
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -99,32 +97,11 @@ func TestPoseidonHashCompare(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
func BenchmarkPoseidonHash12Inputs(b *testing.B) {
|
||||
bigArray12 := []*big.Int{
|
||||
big.NewInt(1),
|
||||
big.NewInt(2),
|
||||
big.NewInt(3),
|
||||
big.NewInt(4),
|
||||
big.NewInt(5),
|
||||
big.NewInt(6),
|
||||
big.NewInt(7),
|
||||
big.NewInt(8),
|
||||
big.NewInt(9),
|
||||
big.NewInt(10),
|
||||
big.NewInt(11),
|
||||
big.NewInt(12),
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
poseidon.Hash(bigArray12) //nolint:errcheck,gosec
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNeptuneHash(b *testing.B) {
|
||||
inp := [NROUNDSF]uint64{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
cap := [CAPLEN]uint64{10, 11, 12, 13}
|
||||
_cap := [CAPLEN]uint64{10, 11, 12, 13}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
Hash(inp, cap) //nolint:errcheck,gosec
|
||||
_, _ = Hash(inp, _cap)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user