mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-08 03:56:42 +01:00
Better keccac256 (#41)
* Switch to keccac256 implementation from golang.org/x/crypto instead of go-ethereum
This commit is contained in:
committed by
GitHub
parent
9c2ca9ca7c
commit
64e757cc4a
@@ -4,9 +4,9 @@ import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
_constants "github.com/iden3/go-iden3-crypto/constants"
|
||||
"github.com/iden3/go-iden3-crypto/ff"
|
||||
"github.com/iden3/go-iden3-crypto/keccak256"
|
||||
"github.com/iden3/go-iden3-crypto/utils"
|
||||
)
|
||||
|
||||
@@ -25,8 +25,8 @@ type constantsData struct {
|
||||
func generateConstantsData() constantsData {
|
||||
var constants constantsData
|
||||
|
||||
constants.seedHash = new(big.Int).SetBytes(crypto.Keccak256([]byte(SEED)))
|
||||
c := new(big.Int).SetBytes(crypto.Keccak256([]byte(SEED + "_iv")))
|
||||
constants.seedHash = new(big.Int).SetBytes(keccak256.Hash([]byte(SEED)))
|
||||
c := new(big.Int).SetBytes(keccak256.Hash([]byte(SEED + "_iv")))
|
||||
constants.iv = new(big.Int).Mod(c, _constants.Q)
|
||||
|
||||
constants.nRounds = 91
|
||||
@@ -38,9 +38,9 @@ func generateConstantsData() constantsData {
|
||||
func getConstants(seed string, nRounds int) []*ff.Element {
|
||||
cts := make([]*ff.Element, nRounds)
|
||||
cts[0] = ff.NewElement()
|
||||
c := new(big.Int).SetBytes(crypto.Keccak256([]byte(SEED)))
|
||||
c := new(big.Int).SetBytes(keccak256.Hash([]byte(SEED)))
|
||||
for i := 1; i < nRounds; i++ {
|
||||
c = new(big.Int).SetBytes(crypto.Keccak256(c.Bytes()))
|
||||
c = new(big.Int).SetBytes(keccak256.Hash(c.Bytes()))
|
||||
|
||||
n := new(big.Int).Mod(c, _constants.Q)
|
||||
cts[i] = ff.NewElement().SetBigInt(n)
|
||||
|
||||
@@ -5,16 +5,16 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/iden3/go-iden3-crypto/keccak256"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestKeccak256(t *testing.T) {
|
||||
res := crypto.Keccak256([]byte(SEED))
|
||||
res := keccak256.Hash([]byte(SEED))
|
||||
assert.Equal(t,
|
||||
"b6e489e6b37224a50bebfddbe7d89fa8fdcaa84304a70bd13f79b5d9f7951e9e",
|
||||
hex.EncodeToString(res))
|
||||
c := new(big.Int).SetBytes(crypto.Keccak256([]byte(SEED)))
|
||||
c := new(big.Int).SetBytes(keccak256.Hash([]byte(SEED)))
|
||||
assert.Equal(t,
|
||||
"82724731331859054037315113496710413141112897654334566532528783843265082629790",
|
||||
c.String())
|
||||
|
||||
Reference in New Issue
Block a user