Generating collisions #54
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#54
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For e. g. testing purposes I need to generate different sequences, whose XXH64 hash codes collide.
I've found this thread and applied (rather blindly) the same algorithm to XXH64, so I got
0xBA79078168D4BAFto the 64-bit value at positionP(in the little-endian order)0x9C90005B80000000to the value atP + 32.But it doesn't work (the hash codes are different).
Hi Roman
The thread you found explain how to create a collision with xxh32.
For xxh64, similar reasoning may apply, but it nonetheless needs to be studied thoroughly. There could be a single minor difference, but it will make the solution different.
Yes I see that it is for xxh32, so I applied the same reasoning with xxh64's constants (P1, P2) and multiplied offsets by 2 (16 -> 32).
I see you adapted the constants to xxh64.
But since it doesn't work, it could be either :
I don't see where the difference could be, since both xxh32 & xxh64 internal loops are very similar,
so maybe a calculation error ?
Note that I'm currently finding the same constants as you, so constants error looks less likely.
Next in the list are the test conditions.
I guess you already checked them, but just in case :
No, I did not obey additional conditions you listed, but now with them, it works. Thank you!
BTW it would be useful to document these collision generation procedures in the repo.
I also need short byte sequences that collide with XXH64 for testing purpose. Could we have two or three samples ? My use case of to use xxHash for a map (index). Unfortunately, @leventov did not provide his results. The algorithm he used is unclear.
@chmike here is the specific collision-generating code: https://github.com/OpenHFT/Zero-Allocation-Hashing/blob/master/src/test/java/net/openhft/hashing/XxHashCollisionTest.java
I found out by testing. Here is the explanation with the missing information.
To generate two shortest byte sequence yielding the same XXH64 code here is the algorithm:
The XXH64 hash of s1 and s2 will have the same value.
Here is an example to check your algorithm:
When s1 is a sequence of 64 zero bytes, and after executing the 7 steps above, the 8 first byte of s2 must have the value
0xAF, 0x4B, 0x8D, 0x16, 0x78, 0x90, 0xA7, 0x0B, and the 8 bytes at offset 32 must have the value0x00, 0x00, 0x00, 0x80, 0x5B, 0x00, 0x90, 0x9C. The hash of s1 and s2 will be 2700762989836380697.This was tested with
github.com/cespare/xxhash, a Go version of XXH64.Thank you very much @leventov . Your code was helpfull. With it I discovered that one can multiply the magical constants by an integer to get other collisions. Thank you very much for your impressive initial work and the code.
Pythonic, easier to digest version of what @chmike said: