Open notgiven688 opened 5 years ago
Compare [1] https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L116 and [2] https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L127
with the reference implementation here [3]: https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L138
Looks to me as [3] does not yield the same result as [1] and [2] since the offsets (0x10,0x20,0x30) are not interchanged correctly.
In my opinion the correct reference implementation (for reverse=true) should read:
#define VARIANT2_PORTABLE_SHUFFLE_ADD(base_ptr, offset, reverse) \ do if (variant >= 2) \ { \ uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x30)); \ uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \ uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x10)); \ \ const uint64_t chunk1_old[2] = { chunk1[0], chunk1[1] }; \ \ uint64_t b1[2]; \ memcpy(b1, b + 16, 16); \ chunk3[0] = chunk3[0] + b1[0]; \ chunk3[1] = chunk3[1] + b1[1]; \ \ uint64_t a0[2]; \ memcpy(a0, a, 16); \ chunk1[0] = chunk2[0] + a0[0]; \ chunk1[1] = chunk2[1] + a0[1]; \ \ uint64_t b0[2]; \ memcpy(b0, b, 16); \ chunk2[0] = chunk1_old[0] + b0[0]; \ chunk2[1] = chunk1_old[1] + b0[1]; \ } while (0)
Compare [1] https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L116 and [2] https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L127
with the reference implementation here [3]: https://github.com/graft-project/GraftNetwork/blob/dfd9b6d18a6694b537aa71e43294ad2c19e82be3/src/crypto/slow-hash.c#L138
Looks to me as [3] does not yield the same result as [1] and [2] since the offsets (0x10,0x20,0x30) are not interchanged correctly.
In my opinion the correct reference implementation (for reverse=true) should read: