The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Ghirai on November 20, 2006, 12:23:01 PM

Title: Whirlpool masm implementation (need some help)
Post by: Ghirai on November 20, 2006, 12:23:01 PM
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)?
Title: Re: Whirlpool masm implementation (need some help)
Post by: zooba on November 20, 2006, 12:28:43 PM
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
Title: Re: Whirlpool masm implementation (need some help)
Post by: Ghirai on November 20, 2006, 12:36:13 PM
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
Title: Re: Whirlpool masm implementation (need some help)
Post by: drizz on November 20, 2006, 03:18:28 PM
Hi Ghirai

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

http://drizz.t35.com/files/cryptohash.rar
Title: Re: Whirlpool masm implementation (need some help)
Post by: dsouza123 on November 20, 2006, 04:26:42 PM
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.
Title: Re: Whirlpool masm implementation (need some help)
Post by: zooba on November 20, 2006, 07:59:48 PM
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
Title: Re: Whirlpool masm implementation (need some help)
Post by: Ghirai on November 21, 2006, 09:54:19 AM
Thanks both of you, you've been very helpful :U