arnaucube
arnaucube/go-iden3-cryptoPublic Self-hosted repository
fix #9
arnaucube root@arnaucube.com
Tue, 17 Dec 2019 18:04:49 +0100
commit

fcb586591ab6b1d50a9eff5b7a3e93655e62fef8

parent

7c6170453eb83c017725d79a7c0a12ae68570e34

2 files changed, 8 insertions(+), 7 deletions(-)

jump to
M poseidon/poseidon.go → poseidon/poseidon.go

@@ -168,15 +168,16 @@ }

r := constants.fqR.Zero() for i := 0; i < len(arr); i = i + 5 { - var fiveElems [5]*big.Int + var toHash [6]*big.Int for j := 0; j < 5; j++ { if i+j < len(arr) { - fiveElems[j] = arr[i+j] + toHash[j] = arr[i+j] } else { - fiveElems[j] = _constants.Zero + toHash[j] = _constants.Zero } } - ph, err := PoseidonHash(fiveElems[:]) + toHash[5] = r + ph, err := PoseidonHash(toHash[:]) if err != nil { return nil, err }
M poseidon/poseidon_test.go → poseidon/poseidon_test.go

@@ -43,7 +43,7 @@ msgElems = append(msgElems, v)

} hmsg, err := Hash(msgElems) assert.Nil(t, err) - assert.Equal(t, "11821124228916291136371255062457365369197326845706357273715164664419275913793", hmsg.String()) + assert.Equal(t, "19204466598658860237115179437116112945222240370078952939676636700594938553268", hmsg.String()) msg2 := []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. Lorem ipsum dolor sit amet.") msg2Elems := make([]*big.Int, 0, len(msg2)/n+1)

@@ -59,11 +59,11 @@ msg2Elems = append(msg2Elems, v)

} hmsg2, err := Hash(msg2Elems) assert.Nil(t, err) - assert.Equal(t, "10747013384255785702102976082726575658403084163954725275481577373644732938016", hmsg2.String()) + assert.Equal(t, "11846976426841208067103690249139614816718727366915557488657094868020932500524", hmsg2.String()) hmsg2, err = HashBytes(msg2) assert.Nil(t, err) - assert.Equal(t, "10747013384255785702102976082726575658403084163954725275481577373644732938016", hmsg2.String()) + assert.Equal(t, "11846976426841208067103690249139614816718727366915557488657094868020932500524", hmsg2.String()) } func TestPoseidonBrokenChunks(t *testing.T) {