News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

AES 128 bits Encrypt

Started by cpu2, May 14, 2014, 09:25:17 PM

Previous topic - Next topic

Gunther

Hi cpu2,

is the AT&T syntax the output from gcc?

Gunther
You have to know the facts before you can distort them.

cpu2

No, the code is written in vi my favorite editor. Sorry again for the syntax, when everything is in intel and fastcall.

Regards.

peter_asm

vi and at&t syntax....is someone whipping you while you write the code too?  :biggrin:
Joking dude, just seems like you're being hard on yourself when it comes to coding.

I use notepad++ on windows but unfortunately doesn't exist on *nix.
Geany on the other hand is pretty good, so long as you have GUI components installed.

cpu2

I have not installed any GUI system, my system is OpenBSD, and work and I work in an old resolution for VT100 (80x25), but I feel good, of course they used another system to communicate with you, merely for convenience.

Band leaving it all, that you think the code snippet?

Regards.

Gunther

Quote from: peter_asm on May 31, 2014, 03:06:58 AM
I use notepad++ on windows but unfortunately doesn't exist on *nix.

TEA exists on both platforms. I would recommend it.

Gunther
You have to know the facts before you can distort them.

cpu2

I'm on it no and left it hanging. I been talking to this person, will soon translated and the encrypt part fastcall.

I'll leave so they can study better, while just the decrypt.

Regards.

cpu2

#36
The user said and translated the code.


.data

sbx_:
    dq 0c56f6bf27b777c63h,076abd7fe2b670130h
    dq 0f04759fa7dc982cah,0c072a49cafa2d4adh
    dq 0ccf73f362693fdb7h,01531d871f1e5a534h
    dq 09a059618c323c704h,075b227ebe2801207h
    dq 0a05a6e1b1a2c8309h,0842fe329b3d63b52h
    dq 05bb1fc20ed00d153h,0cf584c4a39becb6ah
    dq 085334d43fbaaefd0h,0a89f3c507f02f945h
    dq 0f5389d928f40a351h,0d2f3ff1021dab6bch
    dq 01744975fec130ccdh,073195d643d7ea7c4h
    dq 088902a22dc4f8160h,0db0b5ede14b8ee46h
    dq 05c2406490a3a32e0h,079e4959162acd3c2h
    dq 0a94ed58d6d37c8e7h,008ae7a65eaf4566ch
    dq 0c6b4a61c2e2578bah,08a8bbd4b1f74dde8h
    dq 00ef6034866b53e70h,09e1dc186b9573561h
    dq 0948ed9691198f8e1h,0df2855cee9871e9bh
    dq 06842e6bf0d89a18ch,016bb54b00f2d9941h
sq0_:
    dq 0000000ff000000ffh,0000000ff000000ffh
sq1_:
    dq 00000ff000000ff00h,00000ff000000ff00h
sq2_:
    dq 000ff000000ff0000h,000ff000000ff0000h
sq3_:
    dq 0ff000000ff000000h,0ff000000ff000000h
bts_:
    dq 08080808080808080h,08080808080808080h
dlb_:
    dq 07f7f7f7f7f7f7f7fh,07f7f7f7f7f7f7f7fh
xrb_:
    dq 01b1b1b1b1b1b1b1bh,01b1b1b1b1b1b1b1bh
rcn_:
    dq 01b1b1b1b1b1b1b1bh,01b1b1b1b1b1b1b1bh
    dq 00000002000000010h,00000008000000040h
    dq 0000000360000001bh
ptr_:   
    dq 00706050403020100h,00f0e0d0c0b0a0908h
    dq 07766554433221100h,0ffeeddccbbaa9988h
   

.code
_start:
    lea r11,ptr_
    prefetch sbx_
    prefetch [sbx_+40h]
    prefetch [sbx_+80h]
    prefetch [sbx_+0c0h]
    prefetch [sq0_]
    prefetch [sq0_+40h]
    prefetch [sq0_+80h]
    mov r13,0ffffffffffffff60h
    movdqu xmm0,xmmword [r11]
    movdqu xmmword[rsp+r13-10h],xmm0
    mov r11d,dword [r11+0ch]
    movnti dword [rsp+r13],r11d
    lea r12,rcn_
    lea r11,ptr_

_exk:   
    ror dword [rsp+r13],08h
    movzx r14,byte [rsp+r13]
    movzx r15,byte [rsp+r13+1]
    movzx r8,byte [rsp+r13+2]
    movzx r9,byte [rsp+r13+3]
    movzx r14,byte [r14+sbx_]
    movzx r15,byte [r15+sbx_]
    movzx r8,byte [r8+sbx_]
    movzx r9,byte [r9+sbx_]
    movnti dword [rsp+r13],r14d
    movnti dword [rsp+r13+01h],r15d
    movnti dword [rsp+r13+02h],r8d
    movnti dword [rsp+r13+03h],r9d
    mov eax,[rsp+r13]
    xor eax,[r12]
    add r12,04h
    xor eax,[rsp+r13-10h]
    movnti dword [rsp+r13],eax
    xor eax,[rsp+r13-0ch]
    movnti dword [rsp+r13+04h],eax
    xor eax,[rsp+r13-08h]
    movnti dword [rsp+r13+08h],eax
    xor eax,[rsp+r13-04h]
    movnti dword [rsp+r13+0ch],eax
    movnti dword [rsp+r13+10h],eax
    add r13,10h
    jnz _exk
   
_ak1:   
    movdqu xmm0,dqword [r11+10h]
    pxor xmm0,dqword [rsp-0b0h]
    mov r11,0ffffffffffffff60h
    mov rbx,09h
   
_x0:   
    mov r13,0fffffffffffffff0h
    movdqu dqword [rsp-0d0h],xmm0
   
_sxm:   
    movzx r14,byte [rsp+r13-0c0h]
    movzx r15,byte [rsp+r13-0bfh]
    movzx r8,byte [rsp+r13-0beh]
    movzx r9,byte [rsp+r13-0bdh]
    movzx r14,byte [r14+sbx_]
    movzx r15,byte [r15+sbx_]
    movzx r8,byte [r8+sbx_]
    movzx r9,byte [r9+sbx_]
    movnti dword [rsp+r13-0e0h],r14d
    movnti dword [rsp+r13-0dfh],r15d
    movnti dword [rsp+r13-0deh],r8d
    movnti dword [rsp+r13-0ddh],r9d
    add r13,04h
    jnz _sxm
_shw:   
    movdqu xmm0,dqword [rsp-0f0h]
    pshufd xmm1,dqword [rsp-0f0h],39h
    pshufd xmm2,dqword [rsp-0f0h],4eh
    pshufd xmm3,dqword [rsp-0f0h],93h
    pand xmm1,dqword [sq1_]
    pand xmm2,dqword [sq2_]
    pand xmm3,dqword [sq3_]
    pand xmm0,dqword [sq0_]
    pxor xmm0,xmm1
    pxor xmm0,xmm2
    pxor xmm0,xmm3
_mxm:   
    movdqa xmm1,xmm0
    movdqa xmm2,xmm1
    movdqa xmm3,xmm2
    movdqa xmm4,xmm3
    pand xmm0,dqword [bts_]
    pcmpeqb xmm0,dqword [bts_]
    movdqa xmm5,xmm0
    pand xmm1,xmm0
    pandn xmm0,xmm2
    pand xmm1,dqword [dlb_]
    pslld xmm0,01h
    pslld xmm1,01h
    pxor xmm1, dqword [xrb_]
    pand xmm1,xmm5
    pxor xmm0,xmm1
    pxor xmm2,xmm0
    movdqa xmm6,xmm2
    psrld xmm2,08h
    pxor xmm0,xmm2
    pslld xmm3,08h
    pxor xmm0,xmm3
    pslld xmm3,08h
    pxor xmm0,xmm3
    psrld xmm4,10h
    pxor xmm0,xmm4
    psrld xmm4,08h
    pxor xmm0,xmm4
    pslld xmm6,18h
    pxor xmm0,xmm6
    pxor xmm0,dqword [rsp+r11]
   
_ark:   
    add r11,10h
    dec rbx
    jnz _x0
    movdqu dqword [rsp-0d0h],xmm0
    mov r13,0fffffffffffffff0h
   
_ltn:   
    movzx r14,byte [rsp+r13-0c0h]
    movzx r15,byte [rsp+r13-0bfh]
    movzx r8,byte [rsp+r13-0beh]
    movzx r9,byte [rsp+r13-0bdh]
    movzx r14,byte [r14+sbx_]
    movzx r15,byte [r15+sbx_]
    movzx r8,byte [r8+sbx_]
    movzx r9,byte [r9+sbx_]
    movnti dword [rsp+r13-0e0h],r14d
    movnti dword [rsp+r13-0dfh],r15d
    movnti dword [rsp+r13-0deh],r8d
    movnti dword [rsp+r13-0ddh],r9d
    add r13,04h
    jnz _ltn
    movdqu xmm0,dqword [rsp-0f0h]
    pshufd xmm1,dqword [rsp-0f0h],39h
    pshufd xmm2,dqword [rsp-0f0h],4eh
    pshufd xmm3,dqword [rsp-0f0h],93h
    pand xmm1,dqword [sq1_]
    pand xmm2,dqword [sq2_]
    pand xmm3,dqword [sq3_]
    pand xmm0,dqword [sq0_]
    pxor xmm0,xmm1
    pxor xmm0,xmm2
    pxor xmm0,xmm3
    pxor xmm0,dqword [rsp+r11]
    movdqu dqword [rsp-0f0h],xmm0


_ptr is taken as a pointer to key and plaintext, is only for a test and no calls or anything like that, the result is

0x69c4e0d86a7b0430d8cdb78070b4c55a

And is stored in [rsp-0f0h]

Regards.

cpu2

I have not answered here, just come to say that we finished everything, even decrypt.

Encrypt = 66 OPS for 1 round

Decrypt = 171 OPS for 1 round, InvMixcolumns 130 OPS SSE2  :icon_mrgreen:

KeyExpand = 220 OPS.

As seen, sorry the delay.

Thanks

Gunther

Are you satisfied with the results?

Gunther
You have to know the facts before you can distort them.

cpu2

Yes, I did what I was told, leave the independent functions and are called a call, the code no longer linked as before.

On cycles I think it's okay. I can not share the code as it is personal, if you have questions about the code, say it.

Thanks.

Gunther

Hi cpu2,

Quote from: cpu2 on October 13, 2014, 03:50:08 AM
On cycles I think it's okay. I can not share the code as it is personal, if you have questions about the code, say it.

only one basic question: do you use AT&T syntax or have you converted the sources?

Gunther
You have to know the facts before you can distort them.

cpu2

No, my personal sources is written in AT&T syntax, I like this syntax.

If you have more questions codes, say it.

Thanks.

Gunther

Hi cpu2,

Quote from: cpu2 on October 13, 2014, 02:59:11 PM
No, my personal sources is written in AT&T syntax, I like this syntax.

why not, I'm familiar with AT&T syntax. It has advantages but drawbacks, too. If you would like to write assembly language programs for the PowerPC, AT&T syntax gives an easy entry.

Gunther
You have to know the facts before you can distort them.