diff --git a/programs/develop/libraries/libcrash/trunk/crashtest.asm b/programs/develop/libraries/libcrash/trunk/crashtest.asm index 299a684661..dd97c2dc6c 100644 --- a/programs/develop/libraries/libcrash/trunk/crashtest.asm +++ b/programs/develop/libraries/libcrash/trunk/crashtest.asm @@ -7,9 +7,9 @@ include '../../../../proc32.inc' include '../../../../macros.inc' include '../../../../dll.inc' ;include '../../../../debug.inc' -include '../../../../develop/libraries/libs-dev/libio/libio.inc' include 'libcrash.inc' -BUFFER_SIZE = 8192 + +BUFFER_SIZE = 4096 start: @@ -19,38 +19,6 @@ start: or eax, eax jnz quit - invoke file.open, this_file_name, O_READ - or eax, eax - jz quit - mov [fh], eax - - invoke file.size, this_file_name - mov [file_len], ebx - - stdcall mem.Alloc, ebx - or eax, eax - jz quit - mov [file_data], eax - - invoke file.read, [fh], eax, [file_len] - cmp eax, -1 - je quit - cmp eax, [file_len] - jne quit - - invoke file.close, [fh] - inc eax - jz quit - - stdcall mem.Free, [file_data] - test eax, eax - jz quit - - - invoke crash.hash, LIBCRASH_SHA512, hash, data_buffer, 0, update_data_buffer, msglen - invoke crash.bin2hex, hash, hex, LIBCRASH_SHA512 - - still: mcall 10 dec eax @@ -67,9 +35,33 @@ button: redraw: mcall 12, 1 - mcall 0, <0,800>, <0,100>, 0x34000000, 0x80000000, window_title + mcall 0, <0,900>, <0,150>, 0x34000000, 0x80000000, window_title - mcall 4, 0, 0x40ffffff, hex, 128, 0 + + mcall 4, < 0, 0>, 0xc0ffffff, message, , 0 + + mov [hid], 0 + mov [text_pos_y], 10 + mov [hash_name], hash_strings + .next_hash: + mov dword[f70_buf + 4], 0 + mov dword[msglen], 0 + mov edi, hex + xor eax, eax + mov ecx, 1024/4 + rep stosd + invoke crash.hash, [hid], hash, data_buffer, 0, update_data_buffer, msglen + invoke crash.bin2hex, hash, hex, [hid] + mov ebx, [text_pos_y] + mcall 4, , 0xc0ffffff, [hash_name], , 0 + mov ebx, [text_pos_y] + add ebx, 66 SHL 16 + mcall 4, , 0x40ffffff, hex, 128, 0 + add [text_pos_y], 10 + add [hash_name], 12 ; lenght of hash_strings item + inc [hid] + cmp [hid], LIBCRASH_SHA3_512 + jng .next_hash mcall 12, 2 jmp still @@ -83,23 +75,40 @@ quit: mcall -1 -proc update_data_buffer +proc update_data_buffer _left + mov eax, data_buffer + add eax, [_left] + mov dword[f70_buf + 16], eax + mov eax, BUFFER_SIZE + sub eax, [_left] + mov dword[f70_buf + 12], eax mcall 70, f70_buf mov eax, ebx cmp eax, -1 jne @f inc eax @@: - add dword[f70_buf + 4], BUFFER_SIZE + add dword[f70_buf + 4], eax ret endp -szZ window_title ,'libcrash example' +szZ window_title ,'libcrash example' -sz msg_few_args , '2 arguments required',0x0a -sz msg_bad_hash_type , 'invalid hash type',0x0a -sz msg_file_not_found , 'file not found: ' +szZ message , 'hash sums of this file' + +hash_strings: +md4 db 'md4 : ',0 +md5 db 'md5 : ',0 +sha1 db 'sha1 : ',0 +sha224 db 'sha224 : ',0 +sha256 db 'sha256 : ',0 +sha384 db 'sha384 : ',0 +sha512 db 'sha512 : ',0 +sha3_224 db 'sha3-224 : ',0 +sha3_256 db 'sha3-256 : ',0 +sha3_384 db 'sha3-384 : ',0 +sha3_512 db 'sha3-512 : ',0 f70_buf: funcnum dd 0 @@ -110,37 +119,27 @@ f70_buf: res2 db 0 fname dd this_file_name + align 4 @IMPORT: library \ - libio , 'libio.obj' , \ libcrash, 'libcrash.obj' -import libio , \ - libio.init , 'lib_init' , \ - file.size , 'file_size' , \ - file.open , 'file_open' , \ - file.read , 'file_read' , \ - file.close , 'file_close' - import libcrash , \ libcrash.init , 'lib_init' , \ crash.hash , 'crash_hash' , \ crash.bin2hex , 'crash_bin2hex' i_end: -hash rd 16 +hash_name rd 1 +text_pos_y rd 1 +hash rd 50 +hid rd 1 ; hash id msglen rd 1 -fd rd 1 -fh rd 1 -data_length rd 1 hex rb 1024 data_buffer rb BUFFER_SIZE -file_data rd 1 -file_len rd 1 - this_file_name rb 4096 -rb 0x400 ;stack +rb 0x800 ;stack e_end: diff --git a/programs/develop/libraries/libcrash/trunk/libcrash.asm b/programs/develop/libraries/libcrash/trunk/libcrash.asm index 316427b458..85d17a5951 100644 --- a/programs/develop/libraries/libcrash/trunk/libcrash.asm +++ b/programs/develop/libraries/libcrash/trunk/libcrash.asm @@ -35,6 +35,7 @@ include 'md5.asm' include 'sha1.asm' include 'sha224_256.asm' include 'sha384_512.asm' +include 'sha3.asm' proc lib_init @@ -85,22 +86,28 @@ endl je .quit .callback: - call [_callback] - test eax, eax - jz @f - mov [_len], eax - jmp .first - @@: - mov edi, [_data] mov ecx, [_len] rep movsb + push esi edi + stdcall [_callback], [_len] + pop edi esi + test eax, eax + jz @f + mov edx, [_msglen] + mov ecx, [_len] + sub [edx], ecx + add [_len], eax + jmp .first + @@: + mov eax, [_msglen] mov eax, [eax] - mov edx, [hi] - mov edx, [edx + crash_item.len_blk] - sub edx, 1 - and eax, edx + xor edx, edx + mov ecx, [hi] + mov ecx, [ecx + crash_item.len_blk] + div ecx + mov eax, edx mov edx, [hi] mov ecx, [edx + crash_item.len_blk] sub ecx, [edx + crash_item.len_size] @@ -109,36 +116,13 @@ endl add ecx, [edx + crash_item.len_blk] @@: add [_len], ecx - mov eax, [hi] - mov byte[edi], 0x80 - add edi, 1 - sub ecx, 1 - mov al, 0 - rep stosb - push ecx - xor eax, eax - mov ecx, [hi] - mov ecx, [ecx + crash_item.len_size] - sub ecx, 8 ; FIXME for > 2^64 input length - shr ecx, 2 - rep stosd - pop ecx - mov eax, [_msglen] - mov eax, [eax] - mov edx, 8 - mul edx - mov ecx, [hi] - cmp [ecx + crash_item.endianness], LIBCRASH_ENDIAN_BIG - jne @f - bswap eax - bswap edx - xchg eax, edx - @@: - mov dword[edi], eax - mov dword[edi + 4], edx - mov ecx, [hi] - mov eax, [ecx + crash_item.len_size] + + mov eax, [edx + crash_item.len_size] add [_len], eax + + mov eax, [hi] + stdcall [eax + crash_item.finalproc], [hi], [_msglen] + mov [final], 1 jmp .first .quit: @@ -148,12 +132,116 @@ endl endp -proc crash._.md4_md5_postprocess _len_out, _hash +crash._.md4_finalproc: +proc crash._.md5_finalproc _hi, _msglen + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + push ecx + xor eax, eax + mov ecx, [_hi] + mov ecx, [ecx + crash_item.len_size] + sub ecx, 8 ; FIXME for > 2^64 input length + shr ecx, 2 + rep stosd + pop ecx + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + mov ecx, [_hi] + mov dword[edi], eax + mov dword[edi + 4], edx ret endp -proc crash._.sha1_224_256_postprocess _len_out, _hash +crash._.sha1_finalproc: +crash._.sha224_finalproc: +proc crash._.sha256_finalproc _hi, _msglen + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + push ecx + xor eax, eax + mov ecx, [_hi] + mov ecx, [ecx + crash_item.len_size] + sub ecx, 8 ; FIXME for > 2^64 input length + shr ecx, 2 + rep stosd + pop ecx + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + mov ecx, [_hi] + bswap eax + bswap edx + xchg eax, edx + mov dword[edi], eax + mov dword[edi + 4], edx + + ret +endp + + +crash._.sha384_finalproc: +proc crash._.sha512_finalproc _hi, _msglen + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + push ecx + xor eax, eax + mov ecx, [_hi] + mov ecx, [ecx + crash_item.len_size] + sub ecx, 8 ; FIXME for > 2^64 input length + shr ecx, 2 + rep stosd + pop ecx + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + mov ecx, [_hi] + bswap eax + bswap edx + xchg eax, edx + mov dword[edi], eax + mov dword[edi + 4], edx + + ret +endp + + +crash._.sha3_224_finalproc: +crash._.sha3_256_finalproc: +crash._.sha3_384_finalproc: +proc crash._.sha3_512_finalproc _hi, _msglen + mov byte[edi], 0x01 + add edi, 1 + sub ecx, 1 + mov eax, 0 + rep stosb + or byte[edi - 1], 0x80 + ret +endp + + +crash._.md4_postprocess: +proc crash._.md5_postprocess _len_out, _hash + ret +endp + + +crash._.sha1_postprocess: +crash._.sha224_postprocess: +proc crash._.sha256_postprocess _len_out, _hash mov ecx, [_len_out] mov esi, [_hash] mov edi, esi @@ -167,7 +255,8 @@ proc crash._.sha1_224_256_postprocess _len_out, _hash endp -proc crash._.sha384_512_postprocess _len_out, _hash +crash._.sha384_postprocess: +proc crash._.sha512_postprocess _len_out, _hash mov ecx, [_len_out] mov esi, [_hash] mov edi, esi @@ -187,6 +276,15 @@ proc crash._.sha384_512_postprocess _len_out, _hash endp +crash._.sha3_224_postprocess: +crash._.sha3_256_postprocess: +crash._.sha3_384_postprocess: +proc crash._.sha3_512_postprocess _len_out, _hash + emms + ret +endp + + proc crash.bin2hex _bin, _hex, _hid ; FIXME _hid param? mov eax, [_hid] imul eax, sizeof.crash_item @@ -215,15 +313,17 @@ endp crash._.bin2hex_table db '0123456789abcdef' ; see crash_item struct for details -crash._.table dd crash.md4, crash._.md4_init, crash._.md4_md5_postprocess, 4, 4, 64, 8, 0 - dd crash.md5, crash._.md5_init, crash._.md4_md5_postprocess, 4, 4, 64, 8, 0 - dd crash.sha1, crash._.sha1_init, crash._.sha1_224_256_postprocess, 5, 5, 64, 8, 1 - dd crash.sha256, crash._.sha224_init, crash._.sha1_224_256_postprocess, 8, 7, 64, 8, 1 - dd crash.sha256, crash._.sha256_init, crash._.sha1_224_256_postprocess, 8, 8, 64, 8, 1 - dd crash.sha512, crash._.sha384_init, crash._.sha384_512_postprocess, 16, 12, 128, 16, 1 - dd crash.sha512, crash._.sha512_init, crash._.sha384_512_postprocess, 16, 16, 128, 16, 1 - -crash._.crc_init dd 0xffffffff +crash._.table dd crash.md4, crash._.md4_init, crash._.md4_finalproc, crash._.md4_postprocess, 4, 4, 64, 8 + dd crash.md5, crash._.md5_init, crash._.md5_finalproc, crash._.md5_postprocess, 4, 4, 64, 8 + dd crash.sha1, crash._.sha1_init, crash._.sha1_finalproc, crash._.sha1_postprocess, 5, 5, 64, 8 + dd crash.sha256, crash._.sha224_init, crash._.sha224_finalproc, crash._.sha224_postprocess, 8, 7, 64, 8 + dd crash.sha256, crash._.sha256_init, crash._.sha256_finalproc, crash._.sha256_postprocess, 8, 8, 64, 8 + dd crash.sha512, crash._.sha384_init, crash._.sha384_finalproc, crash._.sha384_postprocess, 16, 12, 128, 16 + dd crash.sha512, crash._.sha512_init, crash._.sha512_finalproc, crash._.sha512_postprocess, 16, 16, 128, 16 + dd crash.sha3_224, crash._.sha3_224_init, crash._.sha3_224_finalproc, crash._.sha3_224_postprocess, 50, 7, 144, 0 + dd crash.sha3_256, crash._.sha3_256_init, crash._.sha3_256_finalproc, crash._.sha3_256_postprocess, 50, 8, 136, 0 + dd crash.sha3_384, crash._.sha3_384_init, crash._.sha3_384_finalproc, crash._.sha3_384_postprocess, 50, 12, 104, 0 + dd crash.sha3_512, crash._.sha3_512_init, crash._.sha3_512_finalproc, crash._.sha3_512_postprocess, 50, 16, 72, 0 crash._.md4_init: crash._.md5_init: @@ -239,6 +339,11 @@ crash._.sha384_init dq 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd1 crash._.sha512_init dq 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\ 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179 +crash._.sha3_512_init: +crash._.sha3_384_init: +crash._.sha3_256_init: +crash._.sha3_224_init dq 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + crash._.sha256_table dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\ @@ -269,6 +374,13 @@ crash._.sha512_table dq 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\ 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 +crash._.sha3_round dq 0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000,\ + 0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,\ + 0x000000000000008A, 0x0000000000000088, 0x0000000080008009, 0x000000008000000A,\ + 0x000000008000808B, 0x800000000000008B, 0x8000000000008089, 0x8000000000008003,\ + 0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,\ + 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 + align 4 @EXPORT: @@ -278,5 +390,3 @@ export \ crash.hash , 'crash_hash' , \ crash.bin2hex , 'crash_bin2hex' -section '.data' data readable writable align 16 -crash._.crc32_table rd 256 diff --git a/programs/develop/libraries/libcrash/trunk/libcrash.inc b/programs/develop/libraries/libcrash/trunk/libcrash.inc index 333e640c18..5a05fbfce1 100644 --- a/programs/develop/libraries/libcrash/trunk/libcrash.inc +++ b/programs/develop/libraries/libcrash/trunk/libcrash.inc @@ -15,24 +15,25 @@ ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . -LIBCRASH_ENDIAN_LITTLE = 0 -LIBCRASH_ENDIAN_BIG = 1 - -LIBCRASH_MD4 = 0 -LIBCRASH_MD5 = 1 -LIBCRASH_SHA1 = 2 -LIBCRASH_SHA224 = 3 -LIBCRASH_SHA256 = 4 -LIBCRASH_SHA384 = 5 -LIBCRASH_SHA512 = 6 +LIBCRASH_MD4 = 0 +LIBCRASH_MD5 = 1 +LIBCRASH_SHA1 = 2 +LIBCRASH_SHA224 = 3 +LIBCRASH_SHA256 = 4 +LIBCRASH_SHA384 = 5 +LIBCRASH_SHA512 = 6 +LIBCRASH_SHA3_224 = 7 +LIBCRASH_SHA3_256 = 8 +LIBCRASH_SHA3_384 = 9 +LIBCRASH_SHA3_512 = 10 struct crash_item function dd ? init_val dd ? + finalproc dd ? postproc dd ? len_in dd ? len_out dd ? len_blk dd ? len_size dd ? - endianness dd ? ends diff --git a/programs/develop/libraries/libcrash/trunk/sha3.asm b/programs/develop/libraries/libcrash/trunk/sha3.asm new file mode 100644 index 0000000000..69bb8024e9 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/sha3.asm @@ -0,0 +1,291 @@ +; libcrash -- cryptographic hash functions +; +; Copyright (C) 2013 Ivan Baravy (dunkaist) +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + +macro keccak_rol_xor nd, ncl, ncr +{ + movq mm0, [C + 8*(ncl)] + movq mm1, mm0 + psllq mm0, 1 + psrlq mm1, 63 + por mm0, mm1 + pxor mm0, [C + 8*(ncr)] + movq [D + 8*(nd)], mm0 +} + +proc keccak_theta +locals + C rq 5 + D rq 5 +endl + +repeat 5 + movq mm0, [edi + 8*(%-1 + 0)] + pxor mm0, [edi + 8*(%-1 + 5)] + pxor mm0, [edi + 8*(%-1 + 10)] + pxor mm0, [edi + 8*(%-1 + 15)] + pxor mm0, [edi + 8*(%-1 + 20)] + movq [C + 8*(%-1)], mm0 +end repeat + + keccak_rol_xor 0, 1, 4 + keccak_rol_xor 1, 2, 0 + keccak_rol_xor 2, 3, 1 + keccak_rol_xor 3, 4, 2 + keccak_rol_xor 4, 0, 3 + +repeat 5 + movq mm1, [D + 8*(%-1)] + movq mm0, mm1 + pxor mm0, [edi + 8*(%-1 + 0)] + movq [edi + 8*(%-1 + 0)], mm0 + movq mm0, mm1 + pxor mm0, [edi + 8*(%-1 + 5)] + movq [edi + 8*(%-1 + 5)], mm0 + movq mm0, mm1 + pxor mm0, [edi + 8*(%-1 + 10)] + movq [edi + 8*(%-1 + 10)], mm0 + movq mm0, mm1 + pxor mm0, [edi + 8*(%-1 + 15)] + movq [edi + 8*(%-1 + 15)], mm0 + movq mm0, mm1 + pxor mm0, [edi + 8*(%-1 + 20)] + movq [edi + 8*(%-1 + 20)], mm0 +end repeat + + ret +endp + + +proc keccak_pi + movq mm1, [edi + 8*1] + movq mm0, [edi + 8*6] + movq [edi + 8*1], mm0 + movq mm0, [edi + 8*9] + movq [edi + 8*6], mm0 + movq mm0, [edi + 8*22] + movq [edi + 8*9], mm0 + movq mm0, [edi + 8*14] + movq [edi + 8*22], mm0 + movq mm0, [edi + 8*20] + movq [edi + 8*14], mm0 + movq mm0, [edi + 8*2] + movq [edi + 8*20], mm0 + movq mm0, [edi + 8*12] + movq [edi + 8*2], mm0 + movq mm0, [edi + 8*13] + movq [edi + 8*12], mm0 + movq mm0, [edi + 8*19] + movq [edi + 8*13], mm0 + movq mm0, [edi + 8*23] + movq [edi + 8*19], mm0 + movq mm0, [edi + 8*15] + movq [edi + 8*23], mm0 + movq mm0, [edi + 8*4] + movq [edi + 8*15], mm0 + movq mm0, [edi + 8*24] + movq [edi + 8*4], mm0 + movq mm0, [edi + 8*21] + movq [edi + 8*24], mm0 + movq mm0, [edi + 8*8] + movq [edi + 8*21], mm0 + movq mm0, [edi + 8*16] + movq [edi + 8*8], mm0 + movq mm0, [edi + 8*5] + movq [edi + 8*16], mm0 + movq mm0, [edi + 8*3] + movq [edi + 8*5], mm0 + movq mm0, [edi + 8*18] + movq [edi + 8*3], mm0 + movq mm0, [edi + 8*17] + movq [edi + 8*18], mm0 + movq mm0, [edi + 8*11] + movq [edi + 8*17], mm0 + movq mm0, [edi + 8*7] + movq [edi + 8*11], mm0 + movq mm0, [edi + 8*10] + movq [edi + 8*7], mm0 + movq [edi + 8*10], mm1 + + ret +endp + + +proc keccak_chi + + mov eax, 0xffffffff + movd mm0, eax + movq mm2, mm0 + punpckldq mm2, mm0 + +repeat 5 + movq mm6, [edi + 8*(0 + 5*(%-1))] + movq mm7, [edi + 8*(1 + 5*(%-1))] + + movq mm0, [edi + 8*(0 + 5*(%-1))] + movq mm1, mm7 + pandn mm1, mm2 + pand mm1, [edi + 8*(2 + 5*(%-1))] + pxor mm0, mm1 + movq [edi + 8*(0 + 5*(%-1))], mm0 + + movq mm0, [edi + 8*(1 + 5*(%-1))] + movq mm1, [edi + 8*(2 + 5*(%-1))] + pandn mm1, mm2 + pand mm1, [edi + 8*(3 + 5*(%-1))] + pxor mm0, mm1 + movq [edi + 8*(1 + 5*(%-1))], mm0 + + movq mm0, [edi + 8*(2 + 5*(%-1))] + movq mm1, [edi + 8*(3 + 5*(%-1))] + pandn mm1, mm2 + pand mm1, [edi + 8*(4 + 5*(%-1))] + pxor mm0, mm1 + movq [edi + 8*(2 + 5*(%-1))], mm0 + + movq mm0, [edi + 8*(3 + 5*(%-1))] + movq mm1, [edi + 8*(4 + 5*(%-1))] + pandn mm1, mm2 + pand mm1, mm6 + pxor mm0, mm1 + movq [edi + 8*(3 + 5*(%-1))], mm0 + + movq mm0, [edi + 8*(4 + 5*(%-1))] + movq mm1, mm6 + pandn mm1, mm2 + pand mm1, mm7 + pxor mm0, mm1 + movq [edi + 8*(4 + 5*(%-1))], mm0 +end repeat + ret +endp + + +macro keccak_rol_mov n, c +{ + movq mm0, [edi + 8*(n)] + movq mm1, mm0 + psllq mm0, (c) + psrlq mm1, (64-(c)) + por mm0, mm1 + movq [edi + 8*(n)], mm0 +} + +proc keccak_permutation + +repeat 24 + stdcall keccak_theta + + keccak_rol_mov 1, 1 + keccak_rol_mov 2, 62 + keccak_rol_mov 3, 28 + keccak_rol_mov 4, 27 + keccak_rol_mov 5, 36 + keccak_rol_mov 6, 44 + keccak_rol_mov 7, 6 + keccak_rol_mov 8, 55 + keccak_rol_mov 9, 20 + keccak_rol_mov 10, 3 + keccak_rol_mov 11, 10 + keccak_rol_mov 12, 43 + keccak_rol_mov 13, 25 + keccak_rol_mov 14, 39 + keccak_rol_mov 15, 41 + keccak_rol_mov 16, 45 + keccak_rol_mov 17, 15 + keccak_rol_mov 18, 21 + keccak_rol_mov 19, 8 + keccak_rol_mov 20, 18 + keccak_rol_mov 21, 2 + keccak_rol_mov 22, 61 + keccak_rol_mov 23, 56 + keccak_rol_mov 24, 14 + + stdcall keccak_pi + stdcall keccak_chi + + movq mm0, [edi + 8*(0)] + pxor mm0, [crash._.sha3_round + 8*(%-1)] + movq [edi + 8*(0)], mm0 +end repeat + + ret +endp + + +proc crash.sha3_224 _hash, _data + mov edi, [_hash] + +repeat 18 + movq mm0, [esi + 8*(%-1)] + pxor mm0, [edi + 8*(%-1)] + movq [edi + 8*(%-1)], mm0 +end repeat + + stdcall keccak_permutation + + add esi, 144 + ret +endp + + +proc crash.sha3_256 _hash, _data + mov edi, [_hash] + +repeat 17 + movq mm0, [esi + 8*(%-1)] + pxor mm0, [edi + 8*(%-1)] + movq [edi + 8*(%-1)], mm0 +end repeat + + stdcall keccak_permutation + + add esi, 136 + ret +endp + + +proc crash.sha3_384 _hash, _data + mov edi, [_hash] + +repeat 13 + movq mm0, [esi + 8*(%-1)] + pxor mm0, [edi + 8*(%-1)] + movq [edi + 8*(%-1)], mm0 +end repeat + + stdcall keccak_permutation + + add esi, 104 + ret +endp + + +proc crash.sha3_512 _hash, _data + mov edi, [_hash] + +repeat 9 + movq mm0, [esi + 8*(%-1)] + pxor mm0, [edi + 8*(%-1)] + movq [edi + 8*(%-1)], mm0 +end repeat + + stdcall keccak_permutation + + add esi, 72 + ret +endp +