Hey everyone, i'm writing a masm implementation of the whirlpool hashing algo.
I'm using C source from truecrypt for reference, and i've got stuck atm.
digest[0] = (u8)(structpointer->hash[i] >> 56);
digest[0] is a byte, and structpointer->hash is a qword.
Basically this does digest[0]=(byte typecast)(shr qword,56).
Any idea how would i translate this to masm (32bit)?
Just read 7 bytes further on:
mov esi, structpointer
mov ecx, i
mov al, [esi].STRUCT.hash[ecx+7]
Shifting a QWORD 56 bits to the right and trimming to an 8 bit number is the same as grabbing the byte 7 bytes along, as hopefully I've shown here.
Cheers,
Zooba :U
Thanks for the quick reply :)
I also need to do the same, but shifting 8, 16, 24, 32, etc till 56.
for (i = 0; i < DIGESTBYTES/8; i++) {
digest[0] = (u8)(structpointer->hash[i] >> 56);
digest[1] = (u8)(structpointer->hash[i] >> 48);
digest[2] = (u8)(structpointer->hash[i] >> 40);
digest[3] = (u8)(structpointer->hash[i] >> 32);
digest[4] = (u8)(structpointer->hash[i] >> 24);
digest[5] = (u8)(structpointer->hash[i] >> 16);
digest[6] = (u8)(structpointer->hash[i] >> 8);
digest[7] = (u8)(structpointer->hash[i] );
digest += 8;
}
I'll post the code when it's done and working :P
And yes, i suck at C bigtime :P
Hi Ghirai
you can take a peek on how i did it. :wink
http://drizz.t35.com/files/cryptohash.rar
Something like this.
mov ebx, DIGESTBYTES
shr ebx, 3
mov edi, 0
mov ecx, structpointer
mov esi, i
@@:
mov eax, dword ptr [ecx].STRUCT.hash[esi*8+0]
mov edx, dword ptr [ecx].STRUCT.hash[esi*8+4]
bswap eax
bswap edx
mov dword ptr [digest+edi*8+0], edx
mov dword ptr [digest+edi*8+4], eax
inc esi
inc edi
cmp esi, ebx
jnz @B
Added the dword ptr (syntax issue) to make it plain that four bytes are handled in parallel.
Each of those lines is simply reading the individual byte values from the QWORD. C doesn't provide an obvious facility for this, while in ASM it's extremely simple. Just use the code I showed you above and substitute '7' for the number of the byte you want (the shift value divided by 8)
Cheers,
Zooba :U
Thanks both of you, you've been very helpful :U