arnaucube
arnaucube/go-iden3-cryptoPublic Self-hosted repository
Poseidon & MiMC7 HashBytes remove return of err
arnaucube root@arnaucube.com
Fri, 22 May 2020 00:42:14 +0200
commit

3a9171000b95f0fc534690f3461a81698b348ad4

parent

b1468fc0760ff436978b37ab4639c87378befac1

4 files changed, 14 insertions(+), 8 deletions(-)

jump to
M mimc7/mimc7.go → mimc7/mimc7.go

@@ -137,7 +137,7 @@ }

// HashBytes hashes a msg byte slice by blocks of 31 bytes encoded as // little-endian -func HashBytes(b []byte) (*big.Int, error) { +func HashBytes(b []byte) *big.Int { n := 31 bElems := make([]*big.Int, 0, len(b)/n+1) for i := 0; i < len(b)/n; i++ {

@@ -150,5 +150,9 @@ v := new(big.Int)

utils.SetBigIntFromLEBytes(v, b[(len(b)/n)*n:]) bElems = append(bElems, v) } - return Hash(bElems, nil) + h, err := Hash(bElems, nil) + if err != nil { + panic(err) + } + return h }
M mimc7/mimc7_test.go → mimc7/mimc7_test.go

@@ -74,8 +74,7 @@ // same hash value than the iden3js and circomlib tests:

assert.Equal(t, "0x"+hex.EncodeToString((*big.Int)(h4).Bytes()), "0x284bc1f34f335933a23a433b6ff3ee179d682cd5e5e2fcdd2d964afa85104beb") msg := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") - hmsg, err := HashBytes(msg) - assert.Nil(t, err) + hmsg := HashBytes(msg) assert.Equal(t, "16855787120419064316734350414336285711017110414939748784029922801367685456065", hmsg.String()) }
M poseidon/poseidon.go → poseidon/poseidon.go

@@ -179,7 +179,7 @@ }

// HashBytes hashes a msg byte slice by blocks of 31 bytes encoded as // little-endian -func HashBytes(b []byte) (*big.Int, error) { +func HashBytes(b []byte) *big.Int { n := 31 bElems := make([]*big.Int, 0, len(b)/n+1) for i := 0; i < len(b)/n; i++ {

@@ -193,5 +193,9 @@ v := big.NewInt(int64(0))

utils.SetBigIntFromLEBytes(v, b[(len(b)/n)*n:]) bElems = append(bElems, v) } - return Hash(bElems) + h, err := Hash(bElems) + if err != nil { + panic(err) + } + return h }
M poseidon/poseidon_test.go → poseidon/poseidon_test.go

@@ -73,8 +73,7 @@ hmsg2, err := Hash(msg2Elems)

assert.Nil(t, err) assert.Equal(t, "2978613163687734485261639854325792381691890647104372645321246092227111432722", hmsg2.String()) - hmsg2, err = HashBytes(msg2) - assert.Nil(t, err) + hmsg2 = HashBytes(msg2) assert.Equal(t, "2978613163687734485261639854325792381691890647104372645321246092227111432722", hmsg2.String()) }