Extrarius
March 30th, 2006, 23:23
I'm new to reverse engineering, but I'm somewhat familiar with the relevant assembly language (x86) so I've been doing pretty well so far, but I've come across what is almost certainly a round function (meaning one step in some kind of encryption/decription and/or hash function) that I haven't been able to identify. If it had some kind of magic numbers that I could research or the like, it'd be easy (as was identifying a function that calculates the md5 of a string), but the only constants are 1 (the amount everything is shifted by) and 30 (the number of times the same code occurs in sequence and the reason I'm fairly certain it's a round function).
The program was coded in C/C++ and compiled with MSVC 2002 or 2003 with unknown settings (likely standard 'release' settings - I've found at least one instance of a function both inlined and not)
If you have any idea what algorithm the following represents, I'd greatly appreciate your thoughts:
Besides this code segment appearing 30 times in a sequence, there is a somewhat similar (in instructions used, anyways) setup sequence and exit sequence that likely act as the 1st and 32nd round, respectively. The start and sequences use all 3 arguments (arg_0, arg_4, arg_8), while the intermediate rounds only use 2 (as can be easily seen).
The function is not called in a loop, and it doesn't contain a loop itself, so it seems as if it's not an encryption or hash function, but I'm not sure what else would have 32 rounds. Also, arg_0 and arg_4 seem to be based on some function of delta-time in clock cycles(measured based on a stored reading of rdtsc and a current reading), while arg_8 is always an unknown global value that is to be initialized only at program startup, based on some calculation on the result of rdtsc.
Is it perhaps some kind of random number generator? It seems odd that one would require 30 rounds of the same few instructions (and that it would be unrolled when there seems to be little overall inlining or unrolling), but since it's not looped I can't really think of much else that would use such a sequence of operations on nearly-random input.
The program was coded in C/C++ and compiled with MSVC 2002 or 2003 with unknown settings (likely standard 'release' settings - I've found at least one instance of a function both inlined and not)
If you have any idea what algorithm the following represents, I'd greatly appreciate your thoughts:
Code:
mov edi, [ebp+arg_0]
shrd edi, esi, 1
mov ebx, edi
mov [ebp+arg_8], edi
shr esi, 1
shl eax, 1
mov edi, edx
mov [ebp+arg_0], ebx
sub edi, ebx
mov ebx, ecx
sbb ebx, esi
js short L_Two
jg short L_One
test edi, edi
jb short L_Two
L_One:
mov edx, edi
mov ecx, ebx
inc eax
L_Two:
The function is not called in a loop, and it doesn't contain a loop itself, so it seems as if it's not an encryption or hash function, but I'm not sure what else would have 32 rounds. Also, arg_0 and arg_4 seem to be based on some function of delta-time in clock cycles(measured based on a stored reading of rdtsc and a current reading), while arg_8 is always an unknown global value that is to be initialized only at program startup, based on some calculation on the result of rdtsc.
Is it perhaps some kind of random number generator? It seems odd that one would require 30 rounds of the same few instructions (and that it would be unrolled when there seems to be little overall inlining or unrolling), but since it's not looped I can't really think of much else that would use such a sequence of operations on nearly-random input.