arnaucube
arnaucube/go-iden3-cryptoPublic Self-hosted repository
Merge pull request #11 from iden3/fix/issue-9

Fix/issue #9
Eduard S eduard@iden3.io
Wed, 18 Dec 2019 11:03:37 +0100
commit

8d5a7a7ccbcd335e132b6270530e40ea21c1dbd5

parent

7c6170453eb83c017725d79a7c0a12ae68570e34

2 files changed, 11 insertions(+), 10 deletions(-)

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

@@ -101,7 +101,7 @@ }

// ark computes Add-Round Key, from the paper https://eprint.iacr.org/2019/458.pdf func ark(state []*big.Int, c *big.Int) []*big.Int { - for i := 0; i < len(state); i++ { + for i := 0; i < T; i++ { state[i] = constants.fqR.Add(state[i], c) } return state

@@ -167,16 +167,17 @@ return nil, errors.New("inputs values not inside Finite Field")

} r := constants.fqR.Zero() - for i := 0; i < len(arr); i = i + 5 { - var fiveElems [5]*big.Int - for j := 0; j < 5; j++ { + for i := 0; i < len(arr); i = i + T - 1 { + var toHash [T]*big.Int + for j := 0; j < T-1; 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[T-1] = 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) {