Browse Source

Merge pull request #11 from iden3/fix/issue-9

Fix/issue #9
feature/update-bbjj-sig
Eduard S 4 years ago
committed by GitHub
parent
commit
8d5a7a7ccb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions
  1. +8
    -7
      poseidon/poseidon.go
  2. +3
    -3
      poseidon/poseidon_test.go

+ 8
- 7
poseidon/poseidon.go

@ -101,7 +101,7 @@ func checkAllDifferent(v []*big.Int) bool {
// 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 @@ func Hash(arr []*big.Int) (*big.Int, error) {
}
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
}

+ 3
- 3
poseidon/poseidon_test.go

@ -43,7 +43,7 @@ func TestPoseidon(t *testing.T) {
}
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 @@ func TestPoseidon(t *testing.T) {
}
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) {

Loading…
Cancel
Save