Hi everyone!

I am writing a program that demonstrates the xtea encryption algorithm in CTR block cipher mode.  I need to encrypt 64 bit blocks of the message.  How do I get only 64 bit blocks of the message into a buffer?  So far I have

mov gettextlength.flags,GTL_NUMBYTES
mov gettextlength.codepage,CP_ACP
invoke SendDlgItemMessage,hWin,d0_rte_message,EM_GETTEXTLENGTHEX,addr gettextlength,0
mov txtlength,eax
invoke GlobalAlloc,GPTR,txtlength
mov hMemory,eax
invoke GetDlgItemText,hWin,d0_rte_message,hMemory,txtlength
; confusion???
invoke GlobalFree,hMemory

So that the message is in hMemory.  How would I get the consecutive 64 bits out of hMemory?

Posted on 2006-03-28 21:56:13 by silverflow2120
It would seem to me that all that you need to do is take eight bytes (8bits * 8==64)that you want to encode, at the offset that you want from hMemory, and do your processing on it.
Posted on 2006-03-29 08:35:55 by rags
I know but how?  :shock:  I have a lot to learn about assembly still...
Posted on 2006-03-29 08:56:05 by silverflow2120
1) By working on 32-but pieces one by one
2) By using MMX/SSE to work on 64/128-bit pieces
Posted on 2006-03-29 10:15:42 by ti_mo_n
Without writing the code for you here's an outline.
Let's say that the 64-bits (8bytes) that you want to encode start at the 8th byte of the buffer.
Get the base address that hMemory holds, add 7 to it(because zero is first byte of buffer), and
read your 8 bytes starting from that address you calculated, then do your processing on that data.
Remember that hMemory holds a "pointer" to the start address in memory, where the buffer you allocated
with GlobalAlloc resides.
Also, do your processing on the data, BEFORE you free the memory that it is in.
Just a thought, maybe you should brush up on the basics such as pointers,indexing and memory offsets, before tackling a cypher project.
Posted on 2006-03-29 13:12:40 by rags
Thanks rags.  I have noticed that adding to hMemory subtracts the number of bits available from that address.  After studying a few more tutorials, I still can't figure out how to read only 8 bytes from hMemory.  :mad:  I've tried moving the contents of hMemory into a register in hopes of truncating the data to 4 bytes, but this doens't seem to work.  I figure I am only moving the pointer to hMemory around.  How do you move the actual data at the address hMemory?  Or would this work at all?
Posted on 2006-03-30 00:01:27 by silverflow2120
hMemory only holds the starting address of the block of memory that you allocated using Global Alloc, not the whole buffer.
The masm32 package has a help file called "ASM intro help".
In it is a section called "addressing and pointers". Read it. It will give you an understanding of how pointers work.

Posted on 2006-03-30 00:36:36 by rags
push hMemory
mov eax, hMemory
mov eax,
mov blockdword,eax
mov eax,hMemory
mov eax,
mov ,eax
pop hMemory
add hMemory,8

invoke SetDlgItemText,hWin,d0_rte_message,addr blockword

Works perfectly!  :D  We really should advertise that help file a little more!  It was very helpful and I didn't even know it existed!
Posted on 2006-03-30 15:50:35 by silverflow2120