Notes from a crackme I solve for practice, one of the beginner ones made to be solved. My cat walked across the keyboard twice. The second time it found a bug in my notes, so I count her as a reviewer.
The check function, after I tidied the decompiler output:
int check(const char *s) {
unsigned int h = 5381;
while (*s) {
h = h * 33 + (unsigned char)*s;
s++;
}
return h == 0x0002b5e3;
}
Two constants give it away: 5381 as the starting value and 33 as the multiplier. That is the djb2 string hash (h = h * 33 + c). Recognising common constants is half of reverse engineering: they tell you what an algorithm is without reading every instruction. Others I look for are 0x67452301 (MD5/SHA-1 init), 0x9e3779b9 (a golden-ratio constant used in TEA and hash mixing), and the CRC32 polynomial 0xedb88320.
The lesson for the crackme: the program does not store the password, only a 32-bit hash of it. A hash this small has many inputs that give the same value, so "the" password is not unique. That is a weakness of this design, and a nice reminder for real code: never use a 32-bit non-cryptographic hash to check a secret.
I solved it on my own machine, offline, with the challenge's own binary. Cat approves.