Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;################# Created by Bearchik http://crazyasm.blogspot.com ###############################
- ;#################SHA-2-256.inc
- include windows.inc
- include kernel32.inc
- include user32.inc
- include Comctl32.inc
- include shell32.inc
- includelib kernel32.lib
- includelib user32.lib
- includelib Comctl32.lib
- includelib shell32.lib
- sha256main PROTO :DWORD
- .const
- ;#########################################################################
- .data
- H0 dd 6A09E667h
- H1 dd 0BB67AE85h
- H2 dd 3C6EF372h
- H3 dd 0A54FF53Ah
- H4 dd 510E527Fh
- H5 dd 9B05688Ch
- H6 dd 1F83D9ABh
- H7 dd 5BE0CD19h
- K dd 428A2F98h
- dd 71374491h
- dd 0B5C0FBCFh
- dd 0E9B5DBA5h
- dd 3956C25Bh
- dd 59F111F1h
- dd 923F82A4h
- dd 0AB1C5ED5h
- dd 0D807AA98h
- dd 12835B01h
- dd 243185BEh
- dd 550C7DC3h
- dd 72BE5D74h
- dd 80DEB1FEh
- dd 9BDC06A7h
- dd 0C19BF174h
- dd 0E49B69C1h
- dd 0EFBE4786h
- dd 0FC19DC6h
- dd 240CA1CCh
- dd 2DE92C6Fh
- dd 4A7484AAh
- dd 5CB0A9DCh
- dd 76F988DAh
- dd 983E5152h
- dd 0A831C66Dh
- dd 0B00327C8h
- dd 0BF597FC7h
- dd 0C6E00BF3h
- dd 0D5A79147h
- dd 06CA6351h
- dd 14292967h
- dd 27B70A85h
- dd 2E1B2138h
- dd 4D2C6DFCh
- dd 53380D13h
- dd 650A7354h
- dd 766A0ABBh
- dd 81C2C92Eh
- dd 92722C85h
- dd 0A2BFE8A1h
- dd 0A81A664Bh
- dd 0C24B8B70h
- dd 0C76C51A3h
- dd 0D192E819h
- dd 0D6990624h
- dd 0F40E3585h
- dd 106AA070h
- dd 19A4C116h
- dd 1E376C08h
- dd 2748774Ch
- dd 34B0BCB5h
- dd 391C0CB3h
- dd 4ED8AA4Ah
- dd 5B9CCA4Fh
- dd 682E6FF3h
- dd 748F82EEh
- dd 78A5636Fh
- dd 84C87814h
- dd 8CC70208h
- dd 90BEFFFAh
- dd 0A4506CEBh
- dd 0BEF9A3F7h
- dd 0C67178F2h
- codestring db "Bearchik",0
- ;#########################################################################
- .data?
- mkey db 256 dup (?)
- lengh db ?
- aav dd ?
- bbv dd ?
- ccv dd ?
- ddv dd ?
- eev dd ?
- ffv dd ?
- ggv dd ?
- hhv dd ?
- t2 dd ?
- H0out dd ?
- H1out dd ?
- H2out dd ?
- H3out dd ?
- H4out dd ?
- H5out dd ?
- H6out dd ?
- H7out dd ?
- ;#########################################################################
- ;#################SHA-2-256.asm
- .486
- .model flat, stdcall ;32 bit memory model
- option casemap :none ;case sensitive
- include SHA-2-256.inc
- .code
- start:
- invoke sha256main, addr codestring
- invoke ExitProcess,0
- sha256main proc pinstring:DWORD
- mov eax, pinstring
- xor ecx, ecx
- @@:
- cmp BYTE PTR [eax+ecx], 0
- jz @f
- inc ecx
- jmp @b
- @@:
- mov lengh, cl
- lea edi, mkey
- mov esi, pinstring
- rep movsb
- mov BYTE PTR [edi], 80h
- lea eax, mkey
- add eax, 3Eh
- xor ebx, ebx
- mov bl, lengh
- shl ebx, 3h
- xchg bl, bh
- mov WORD PTR [eax], bx
- lea edi, mkey
- mov ecx, 10h
- @@:
- mov eax,DWORD PTR [edi]
- bswap eax
- mov DWORD PTR [edi], eax
- add edi, 4h
- loop @b
- lea eax, mkey
- mov ebx, edi
- sub ebx, eax
- shr ebx, 2h
- mov eax, 40h
- sub eax, ebx
- @@:
- ;s0 := (w[i-15] rightrotate 7) xor (w[i-15] rightrotate 18) xor (w[i-15] rightshift 3)
- push eax
- mov ebx, DWORD PTR [edi-15*4h]
- ror ebx, 7
- mov edx, DWORD PTR [edi-15*4h]
- ror edx, 18
- xor ebx, edx
- mov edx, DWORD PTR [edi-15*4h]
- shr edx, 3
- xor ebx, edx
- ;s1 := (w[i-2] rightrotate 17) xor (w[i-2] rightrotate 19) xor (w[i-2] rightshift 10)
- mov eax, DWORD PTR [edi-2*4h]
- ror eax, 17
- mov edx, DWORD PTR [edi-2*4h]
- ror edx, 19
- xor eax, edx
- mov edx, DWORD PTR [edi-2*4h]
- shr edx, 10
- xor eax, edx
- ;w[i] := w[i-16] + s0 + w[i-7] + s1
- mov edx, DWORD PTR [edi-16*4h]
- add edx, ebx
- add edx, DWORD PTR [edi-7*4h]
- add edx, eax
- mov DWORD PTR [edi], edx
- add edi, 4
- inc ecx
- pop eax
- .if ecx < eax
- jmp @b
- .endif
- xor ecx, ecx
- lea edi, aav
- lea esi, H0
- mov ecx, 20h
- rep movsb
- xor ecx, ecx
- lea edi, mkey
- mainloop:
- ;S0 := (a rightrotate 2) xor (a rightrotate 13) xor (a rightrotate 22)
- mov eax, aav
- ror eax, 2
- mov edx, aav
- ror edx, 13
- xor eax, edx
- mov edx, aav
- ror edx, 22
- xor eax, edx
- ;maj := (a and b) xor (a and c) xor (b and c)
- mov ebx, aav
- and ebx, bbv
- mov edx, aav
- and edx, ccv
- xor ebx, edx
- mov edx, bbv
- and edx, ccv
- xor ebx, edx
- ;t2 := S0 + maj
- add eax, ebx
- mov t2, eax
- ;S1 := (e rightrotate 6) xor (e rightrotate 11) xor (e rightrotate 25)
- mov eax, eev
- ror eax, 6
- mov edx, eev
- ror edx, 11
- xor eax, edx
- mov edx, eev
- ror edx, 25
- xor eax, edx
- ;ch := (e and f) xor ((not e) and g)
- mov ebx, eev
- and ebx, ffv
- mov edx, eev
- not edx
- and edx, ggv
- xor ebx, edx
- ;t1 := h + S1 + ch + k[i] + w[i]
- add eax, hhv
- add eax, ebx
- add eax, DWORD PTR [K+ecx*4h]
- add eax, DWORD PTR [mkey+ecx*4h]
- ;h := g
- mov ebx, ggv
- mov hhv, ebx
- ;g := f
- mov ebx, ffv
- mov ggv, ebx
- ;f := e
- mov ebx, eev
- mov ffv, ebx
- ;e := d + t1
- mov ebx, ddv
- add ebx, eax
- mov eev, ebx
- ;d := c
- mov ebx, ccv
- mov ddv, ebx
- ;c := b
- mov ebx, bbv
- mov ccv, ebx
- ;b := a
- mov ebx, aav
- mov bbv, ebx
- ;a := t1 + t2
- add eax, t2
- mov aav, eax
- inc ecx
- .if ecx < 40h
- jmp mainloop
- .endif
- mov eax, H0
- add eax, aav
- mov H0out, eax
- mov eax, H1
- add eax, bbv
- mov H1out, eax
- mov eax, H2
- add eax, ccv
- mov H2out, eax
- mov eax, H3
- add eax, ddv
- mov H3out, eax
- mov eax, H4
- add eax, eev
- mov H4out, eax
- mov eax, H5
- add eax, ffv
- mov H5out, eax
- mov eax, H6
- add eax, ggv
- mov H6out, eax
- mov eax, H7
- add eax, hhv
- mov H7out, eax
- ret
- sha256main endp
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement