News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Whirlpool masm implementation (need some help)

Started by Ghirai, November 20, 2006, 12:23:01 PM

Previous topic - Next topic

Ghirai

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)?
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

zooba

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

Ghirai

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
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

drizz

Hi Ghirai

you can take a peek on how i did it.  :wink

http://drizz.t35.com/files/cryptohash.rar
The truth cannot be learned ... it can only be recognized.

dsouza123

#4
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.

zooba

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

Ghirai

Thanks both of you, you've been very helpful :U
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html