diff --git a/programs/develop/libraries/libcrash/trunk/crashtest.asm b/programs/develop/libraries/libcrash/trunk/crashtest.asm new file mode 100644 index 0000000000..7b49127b6d --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/crashtest.asm @@ -0,0 +1,147 @@ +use32 + org 0x0 + db 'MENUET01' + dd 0x01,start,i_end,e_end,e_end,0,0 + +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 + + +start: + mcall 68, 11 + + stdcall dll.Load, @IMPORT + or eax, eax + jnz quit + + invoke file.open, input_file, O_READ + or eax, eax + jz quit + mov [fh], eax + + invoke file.size, input_file + 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 + jz redraw + dec eax + jz key + +button: + mcall 17 + shr eax, 8 + + cmp eax, 1 + je quit + +redraw: + mcall 12, 1 + mcall 0, <0,800>, <0,100>, 0x34000000, 0x80000000, window_title + + mcall 4, 0, 0x40ffffff, hex, 128, 0 + + mcall 12, 2 + jmp still + +key: + mcall 2 + jmp still + + +quit: + mcall -1 + + +proc update_data_buffer + mcall 70, f70_buf + mov eax, ebx + cmp eax, -1 + jne @f + inc eax + @@: + add dword[f70_buf + 4], BUFFER_SIZE + ret +endp + + +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: ' + +input_file db '/hd0/1/crashtest',0 + +f70_buf: + funcnum dd 0 + src dd 0 + res1 dd 0 + count dd BUFFER_SIZE + dst dd data_buffer + res2 db 0 + fname dd input_file + +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 +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 + +rb 0x400 ;stack +e_end: + diff --git a/programs/develop/libraries/libcrash/trunk/crc32.asm b/programs/develop/libraries/libcrash/trunk/crc32.asm new file mode 100644 index 0000000000..7681ac1d9b --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/crc32.asm @@ -0,0 +1,73 @@ +proc crash.crc32 _crc, _data, _len, _callback, _msglen + .begin: + mov ecx, [_len] + test ecx, ecx + jz .callback + mov eax, [_crc] + mov eax, [eax] + mov esi, [_data] + .head: + mov ebx, [_data] + and ebx, 3 + jz .body + @@: + dec ecx + js .done + movzx edx, al + xor dl, byte[esi] + add esi, 1 + shr eax, 8 + xor eax, [crash._.crc32_table + edx*4] + dec ebx + jnz @b + .body: + mov ebx, ecx + and ecx, 15 + shr ebx, 4 + test ebx, ebx + jz .tail + @@: +repeat 4 + mov edx, eax + mov eax, [esi] + add esi, 4 + xor eax, edx +repeat 4 + movzx edx, al + shr eax, 8 + xor eax, [crash._.crc32_table + edx*4] +end repeat +end repeat + dec ebx + jnz @b + .tail: + test ecx, ecx + jz .done + @@: + movzx edx, al + xor dl, byte[esi] + add esi, 1 + shr eax, 8 + xor eax, [crash._.crc32_table + edx*4] + dec ecx + jnz @b + .done: + mov ecx, [_crc] + mov [ecx], eax + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + mov [_len], eax + test eax, eax + jnz .begin + @@: + mov ecx, [_crc] + mov eax, [ecx] + xor eax, 0xffffffff + bswap eax + mov [ecx], eax + + ret +endp diff --git a/programs/develop/libraries/libcrash/trunk/libcrash.asm b/programs/develop/libraries/libcrash/trunk/libcrash.asm new file mode 100644 index 0000000000..b2dea57e63 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/libcrash.asm @@ -0,0 +1,158 @@ +format MS COFF + +public @EXPORT as 'EXPORTS' + +include '../../../../struct.inc' +include '../../../../proc32.inc' +include '../../../../macros.inc' +include '../../../../config.inc' +;include '../../../../debug.inc' + +purge section,mov,add,sub +section '.flat' code readable align 16 + +include 'libcrash.inc' +include 'crc32.asm' +include 'md4.asm' +include 'md5.asm' +include 'sha1.asm' +include 'sha224_256.asm' +include 'sha384_512.asm' + + +proc lib_init + ; generate crc32 table + bts [crash._.init_flags], 0 + jc .crc32_table_done + + mov edi, crash._.crc32_table + xor ecx, ecx + mov edx, 0xedb88320 + .1: + mov ebx, 8 + mov eax, ecx + .2: + shr eax, 1 + jnc @f + xor eax, edx + @@: + dec ebx + jnz .2 + stosd + inc cl + jnz .1 + + .crc32_table_done: + ret +endp + + +proc crash.hash _type, _hash, _data, _len, _callback, _msglen +locals + hash_func rd 1 +endl + mov eax, [_type] + mov ecx, eax + and eax, 0x000000ff + sub eax, 1 + mov edx, [crash._.table + eax*8] + mov esi, [crash._.table + eax*8 + 4] + mov edi, [_hash] + mov [hash_func], edx + and ecx, 0x0000ff00 + shr ecx, 8 + rep movsd + + stdcall [hash_func], [_hash], [_data], [_len], [_callback], [_msglen] + + ret +endp + + +proc crash.bin2hex _bin, _hex, _type + xor eax, eax + mov ebx, crash._.bin2hex_table + mov esi, [_bin] + mov edi, [_hex] + mov ecx, [_type] + and ecx, 0x00ff0000 + shr ecx, 16 - 2 + .byte: + lodsb + mov ah, al + shr ah, 4 + and al, 0x0f + xlatb + xchg al, ah + xlatb + stosw + dec ecx + jnz .byte + + ret +endp + + +crash._.bin2hex_table db '0123456789abcdef' +crash._.table: ; hash function, address of initial hash value + dd crash.crc32, crash._.crc_init + dd crash.md4, crash._.md4_init + dd crash.md5, crash._.md5_init + dd crash.sha1, crash._.sha1_init + dd crash.sha256, crash._.sha224_init + dd crash.sha256, crash._.sha256_init + dd crash.sha512, crash._.sha384_init + dd crash.sha512, crash._.sha512_init + +crash._.crc_init dd 0xffffffff +crash._.md4_init: +crash._.md5_init: +crash._.sha1_init dd 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 +crash._.sha224_init dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 +crash._.sha256_init dd 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 +crash._.sha384_init dq 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,\ + 0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4 +crash._.sha512_init dq 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\ + 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179 + +crash._.init_flags dd 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,\ + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\ + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\ + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\ + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\ + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + +crash._.sha512_table dq 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc,\ + 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118,\ + 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,\ + 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694,\ + 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65,\ + 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5,\ + 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4,\ + 0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70,\ + 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df,\ + 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b,\ + 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30,\ + 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8,\ + 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8,\ + 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3,\ + 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,\ + 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b,\ + 0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178,\ + 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,\ + 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\ + 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 + +align 4 +@EXPORT: + +export \ + lib_init , 'lib_init' , \ + 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 new file mode 100644 index 0000000000..c9839db41b --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/libcrash.inc @@ -0,0 +1,8 @@ +LIBCRASH_CRC32 = 0x00010101 +LIBCRASH_MD4 = 0x00040402 +LIBCRASH_MD5 = 0x00040403 +LIBCRASH_SHA1 = 0x00050504 +LIBCRASH_SHA224 = 0x00070805 +LIBCRASH_SHA256 = 0x00080806 +LIBCRASH_SHA384 = 0x000c1007 +LIBCRASH_SHA512 = 0x00101008 diff --git a/programs/develop/libraries/libcrash/trunk/md4.asm b/programs/develop/libraries/libcrash/trunk/md4.asm new file mode 100644 index 0000000000..beee908be7 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/md4.asm @@ -0,0 +1,165 @@ +macro crash.md4.f b, c, d +{ + push c + xor c, d + and b, c + xor b, d + pop c +} + +macro crash.md4.g b, c, d +{ + push c d + mov edi, b + and b, c + and c, d + and d, edi + or b, c + or b, d + pop d c +} + +macro crash.md4.h b, c, d +{ + xor b, c + xor b, d +} + +macro crash.md4.round func, a, b, c, d, index, shift, ac +{ + push b + func b, c, d + lea a, [a + b + ac] + add a, [esi + index*4] + rol a, shift + pop b +} + + +proc crash.md4 _md4, _data, _len, _callback, _msglen +locals + final rd 1 +endl + mov [final], 0 + .first: + mov eax, [_msglen] + mov ecx, [_len] + add [eax], ecx + mov esi, [_data] + test ecx, ecx + jz .callback + .begin: + sub [_len], 64 + jnc @f + add [_len], 64 + jmp .endofblock + @@: + mov edi, [_md4] + mov eax, [edi + 0x0] + mov ebx, [edi + 0x4] + mov ecx, [edi + 0x8] + mov edx, [edi + 0xc] + + crash.md4.round crash.md4.f, eax, ebx, ecx, edx, 0, 3, 0x00000000 + crash.md4.round crash.md4.f, edx, eax, ebx, ecx, 1, 7, 0x00000000 + crash.md4.round crash.md4.f, ecx, edx, eax, ebx, 2, 11, 0x00000000 + crash.md4.round crash.md4.f, ebx, ecx, edx, eax, 3, 19, 0x00000000 + crash.md4.round crash.md4.f, eax, ebx, ecx, edx, 4, 3, 0x00000000 + crash.md4.round crash.md4.f, edx, eax, ebx, ecx, 5, 7, 0x00000000 + crash.md4.round crash.md4.f, ecx, edx, eax, ebx, 6, 11, 0x00000000 + crash.md4.round crash.md4.f, ebx, ecx, edx, eax, 7, 19, 0x00000000 + crash.md4.round crash.md4.f, eax, ebx, ecx, edx, 8, 3, 0x00000000 + crash.md4.round crash.md4.f, edx, eax, ebx, ecx, 9, 7, 0x00000000 + crash.md4.round crash.md4.f, ecx, edx, eax, ebx, 10, 11, 0x00000000 + crash.md4.round crash.md4.f, ebx, ecx, edx, eax, 11, 19, 0x00000000 + crash.md4.round crash.md4.f, eax, ebx, ecx, edx, 12, 3, 0x00000000 + crash.md4.round crash.md4.f, edx, eax, ebx, ecx, 13, 7, 0x00000000 + crash.md4.round crash.md4.f, ecx, edx, eax, ebx, 14, 11, 0x00000000 + crash.md4.round crash.md4.f, ebx, ecx, edx, eax, 15, 19, 0x00000000 + + crash.md4.round crash.md4.g, eax, ebx, ecx, edx, 0, 3, 0x5a827999 + crash.md4.round crash.md4.g, edx, eax, ebx, ecx, 4, 5, 0x5a827999 + crash.md4.round crash.md4.g, ecx, edx, eax, ebx, 8, 9, 0x5a827999 + crash.md4.round crash.md4.g, ebx, ecx, edx, eax, 12, 13, 0x5a827999 + crash.md4.round crash.md4.g, eax, ebx, ecx, edx, 1, 3, 0x5a827999 + crash.md4.round crash.md4.g, edx, eax, ebx, ecx, 5, 5, 0x5a827999 + crash.md4.round crash.md4.g, ecx, edx, eax, ebx, 9, 9, 0x5a827999 + crash.md4.round crash.md4.g, ebx, ecx, edx, eax, 13, 13, 0x5a827999 + crash.md4.round crash.md4.g, eax, ebx, ecx, edx, 2, 3, 0x5a827999 + crash.md4.round crash.md4.g, edx, eax, ebx, ecx, 6, 5, 0x5a827999 + crash.md4.round crash.md4.g, ecx, edx, eax, ebx, 10, 9, 0x5a827999 + crash.md4.round crash.md4.g, ebx, ecx, edx, eax, 14, 13, 0x5a827999 + crash.md4.round crash.md4.g, eax, ebx, ecx, edx, 3, 3, 0x5a827999 + crash.md4.round crash.md4.g, edx, eax, ebx, ecx, 7, 5, 0x5a827999 + crash.md4.round crash.md4.g, ecx, edx, eax, ebx, 11, 9, 0x5a827999 + crash.md4.round crash.md4.g, ebx, ecx, edx, eax, 15, 13, 0x5a827999 + + crash.md4.round crash.md4.h, eax, ebx, ecx, edx, 0, 3, 0x6ed9eba1 + crash.md4.round crash.md4.h, edx, eax, ebx, ecx, 8, 9, 0x6ed9eba1 + crash.md4.round crash.md4.h, ecx, edx, eax, ebx, 4, 11, 0x6ed9eba1 + crash.md4.round crash.md4.h, ebx, ecx, edx, eax, 12, 15, 0x6ed9eba1 + crash.md4.round crash.md4.h, eax, ebx, ecx, edx, 2, 3, 0x6ed9eba1 + crash.md4.round crash.md4.h, edx, eax, ebx, ecx, 10, 9, 0x6ed9eba1 + crash.md4.round crash.md4.h, ecx, edx, eax, ebx, 6, 11, 0x6ed9eba1 + crash.md4.round crash.md4.h, ebx, ecx, edx, eax, 14, 15, 0x6ed9eba1 + crash.md4.round crash.md4.h, eax, ebx, ecx, edx, 1, 3, 0x6ed9eba1 + crash.md4.round crash.md4.h, edx, eax, ebx, ecx, 9, 9, 0x6ed9eba1 + crash.md4.round crash.md4.h, ecx, edx, eax, ebx, 5, 11, 0x6ed9eba1 + crash.md4.round crash.md4.h, ebx, ecx, edx, eax, 13, 15, 0x6ed9eba1 + crash.md4.round crash.md4.h, eax, ebx, ecx, edx, 3, 3, 0x6ed9eba1 + crash.md4.round crash.md4.h, edx, eax, ebx, ecx, 11, 9, 0x6ed9eba1 + crash.md4.round crash.md4.h, ecx, edx, eax, ebx, 7, 11, 0x6ed9eba1 + crash.md4.round crash.md4.h, ebx, ecx, edx, eax, 15, 15, 0x6ed9eba1 + + mov edi, [_md4] + add [edi + 0x0], eax + add [edi + 0x4], ebx + add [edi + 0x8], ecx + add [edi + 0xc], edx + add esi, 64 + jmp .begin + .endofblock: + cmp [final], 1 + je .quit + + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + test eax, eax + jz @f + mov [_len], eax + jmp .first + @@: + + mov edi, [_data] + mov ecx, [_len] + rep movsb + mov eax, [_msglen] + mov eax, [eax] + and eax, 63 + mov ecx, 56 + sub ecx, eax + ja @f + add ecx, 64 + @@: + add [_len], ecx + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + mov dword[edi], eax + mov dword[edi + 4], edx + add [_len], 8 + mov [final], 1 + jmp .first + .quit: + ret +endp + diff --git a/programs/develop/libraries/libcrash/trunk/md5.asm b/programs/develop/libraries/libcrash/trunk/md5.asm new file mode 100644 index 0000000000..f994c7260f --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/md5.asm @@ -0,0 +1,190 @@ +macro crash.md5.f b, c, d +{ + push c + xor c, d + and b, c + xor b, d + pop c +} + +macro crash.md5.g b, c, d +{ + push c d + and b, d + not d + and c, d + or b, c + pop d c +} + +macro crash.md5.h b, c, d +{ + xor b, c + xor b, d +} + +macro crash.md5.i b, c, d +{ + push d + not d + or b, d + xor b, c + pop d +} + +macro crash.md5.round func, a, b, c, d, index, shift, ac +{ + push b + func b, c, d + lea a, [a + b + ac] + add a, [esi + index*4] + rol a, shift + pop b + add a, b +} + + +proc crash.md5 _md5, _data, _len, _callback, _msglen +locals + final rd 1 +endl + mov [final], 0 + .first: + mov eax, [_msglen] + mov ecx, [_len] + add [eax], ecx + mov esi, [_data] + test ecx, ecx + jz .callback + .begin: + sub [_len], 64 + jnc @f + add [_len], 64 + jmp .endofblock + @@: + mov edi, [_md5] + mov eax, [edi + 0x0] + mov ebx, [edi + 0x4] + mov ecx, [edi + 0x8] + mov edx, [edi + 0xc] + + crash.md5.round crash.md5.f, eax, ebx, ecx, edx, 0, 7, 0xd76aa478 + crash.md5.round crash.md5.f, edx, eax, ebx, ecx, 1, 12, 0xe8c7b756 + crash.md5.round crash.md5.f, ecx, edx, eax, ebx, 2, 17, 0x242070db + crash.md5.round crash.md5.f, ebx, ecx, edx, eax, 3, 22, 0xc1bdceee + crash.md5.round crash.md5.f, eax, ebx, ecx, edx, 4, 7, 0xf57c0faf + crash.md5.round crash.md5.f, edx, eax, ebx, ecx, 5, 12, 0x4787c62a + crash.md5.round crash.md5.f, ecx, edx, eax, ebx, 6, 17, 0xa8304613 + crash.md5.round crash.md5.f, ebx, ecx, edx, eax, 7, 22, 0xfd469501 + crash.md5.round crash.md5.f, eax, ebx, ecx, edx, 8, 7, 0x698098d8 + crash.md5.round crash.md5.f, edx, eax, ebx, ecx, 9, 12, 0x8b44f7af + crash.md5.round crash.md5.f, ecx, edx, eax, ebx, 10, 17, 0xffff5bb1 + crash.md5.round crash.md5.f, ebx, ecx, edx, eax, 11, 22, 0x895cd7be + crash.md5.round crash.md5.f, eax, ebx, ecx, edx, 12, 7, 0x6b901122 + crash.md5.round crash.md5.f, edx, eax, ebx, ecx, 13, 12, 0xfd987193 + crash.md5.round crash.md5.f, ecx, edx, eax, ebx, 14, 17, 0xa679438e + crash.md5.round crash.md5.f, ebx, ecx, edx, eax, 15, 22, 0x49b40821 + + crash.md5.round crash.md5.g, eax, ebx, ecx, edx, 1, 5, 0xf61e2562 + crash.md5.round crash.md5.g, edx, eax, ebx, ecx, 6, 9, 0xc040b340 + crash.md5.round crash.md5.g, ecx, edx, eax, ebx, 11, 14, 0x265e5a51 + crash.md5.round crash.md5.g, ebx, ecx, edx, eax, 0, 20, 0xe9b6c7aa + crash.md5.round crash.md5.g, eax, ebx, ecx, edx, 5, 5, 0xd62f105d + crash.md5.round crash.md5.g, edx, eax, ebx, ecx, 10, 9, 0x02441453 + crash.md5.round crash.md5.g, ecx, edx, eax, ebx, 15, 14, 0xd8a1e681 + crash.md5.round crash.md5.g, ebx, ecx, edx, eax, 4, 20, 0xe7d3fbc8 + crash.md5.round crash.md5.g, eax, ebx, ecx, edx, 9, 5, 0x21e1cde6 + crash.md5.round crash.md5.g, edx, eax, ebx, ecx, 14, 9, 0xc33707d6 + crash.md5.round crash.md5.g, ecx, edx, eax, ebx, 3, 14, 0xf4d50d87 + crash.md5.round crash.md5.g, ebx, ecx, edx, eax, 8, 20, 0x455a14ed + crash.md5.round crash.md5.g, eax, ebx, ecx, edx, 13, 5, 0xa9e3e905 + crash.md5.round crash.md5.g, edx, eax, ebx, ecx, 2, 9, 0xfcefa3f8 + crash.md5.round crash.md5.g, ecx, edx, eax, ebx, 7, 14, 0x676f02d9 + crash.md5.round crash.md5.g, ebx, ecx, edx, eax, 12, 20, 0x8d2a4c8a + + crash.md5.round crash.md5.h, eax, ebx, ecx, edx, 5, 4, 0xfffa3942 + crash.md5.round crash.md5.h, edx, eax, ebx, ecx, 8, 11, 0x8771f681 + crash.md5.round crash.md5.h, ecx, edx, eax, ebx, 11, 16, 0x6d9d6122 + crash.md5.round crash.md5.h, ebx, ecx, edx, eax, 14, 23, 0xfde5380c + crash.md5.round crash.md5.h, eax, ebx, ecx, edx, 1, 4, 0xa4beea44 + crash.md5.round crash.md5.h, edx, eax, ebx, ecx, 4, 11, 0x4bdecfa9 + crash.md5.round crash.md5.h, ecx, edx, eax, ebx, 7, 16, 0xf6bb4b60 + crash.md5.round crash.md5.h, ebx, ecx, edx, eax, 10, 23, 0xbebfbc70 + crash.md5.round crash.md5.h, eax, ebx, ecx, edx, 13, 4, 0x289b7ec6 + crash.md5.round crash.md5.h, edx, eax, ebx, ecx, 0, 11, 0xeaa127fa + crash.md5.round crash.md5.h, ecx, edx, eax, ebx, 3, 16, 0xd4ef3085 + crash.md5.round crash.md5.h, ebx, ecx, edx, eax, 6, 23, 0x04881d05 + crash.md5.round crash.md5.h, eax, ebx, ecx, edx, 9, 4, 0xd9d4d039 + crash.md5.round crash.md5.h, edx, eax, ebx, ecx, 12, 11, 0xe6db99e5 + crash.md5.round crash.md5.h, ecx, edx, eax, ebx, 15, 16, 0x1fa27cf8 + crash.md5.round crash.md5.h, ebx, ecx, edx, eax, 2, 23, 0xc4ac5665 + + crash.md5.round crash.md5.i, eax, ebx, ecx, edx, 0, 6, 0xf4292244 + crash.md5.round crash.md5.i, edx, eax, ebx, ecx, 7, 10, 0x432aff97 + crash.md5.round crash.md5.i, ecx, edx, eax, ebx, 14, 15, 0xab9423a7 + crash.md5.round crash.md5.i, ebx, ecx, edx, eax, 5, 21, 0xfc93a039 + crash.md5.round crash.md5.i, eax, ebx, ecx, edx, 12, 6, 0x655b59c3 + crash.md5.round crash.md5.i, edx, eax, ebx, ecx, 3, 10, 0x8f0ccc92 + crash.md5.round crash.md5.i, ecx, edx, eax, ebx, 10, 15, 0xffeff47d + crash.md5.round crash.md5.i, ebx, ecx, edx, eax, 1, 21, 0x85845dd1 + crash.md5.round crash.md5.i, eax, ebx, ecx, edx, 8, 6, 0x6fa87e4f + crash.md5.round crash.md5.i, edx, eax, ebx, ecx, 15, 10, 0xfe2ce6e0 + crash.md5.round crash.md5.i, ecx, edx, eax, ebx, 6, 15, 0xa3014314 + crash.md5.round crash.md5.i, ebx, ecx, edx, eax, 13, 21, 0x4e0811a1 + crash.md5.round crash.md5.i, eax, ebx, ecx, edx, 4, 6, 0xf7537e82 + crash.md5.round crash.md5.i, edx, eax, ebx, ecx, 11, 10, 0xbd3af235 + crash.md5.round crash.md5.i, ecx, edx, eax, ebx, 2, 15, 0x2ad7d2bb + crash.md5.round crash.md5.i, ebx, ecx, edx, eax, 9, 21, 0xeb86d391 + + mov edi, [_md5] + add [edi + 0x0], eax + add [edi + 0x4], ebx + add [edi + 0x8], ecx + add [edi + 0xc], edx + add esi, 64 + jmp .begin + .endofblock: + cmp [final], 1 + je .quit + + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + test eax, eax + jz @f + mov [_len], eax + jmp .first + @@: + + mov edi, [_data] + mov ecx, [_len] + rep movsb + mov eax, [_msglen] + mov eax, [eax] + and eax, 63 + mov ecx, 56 + sub ecx, eax + ja @f + add ecx, 64 + @@: + add [_len], ecx + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + mov dword[edi], eax + mov dword[edi + 4], edx + add [_len], 8 + mov [final], 1 + jmp .first + .quit: + ret +endp + diff --git a/programs/develop/libraries/libcrash/trunk/sha1.asm b/programs/develop/libraries/libcrash/trunk/sha1.asm new file mode 100644 index 0000000000..73c61c4503 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/sha1.asm @@ -0,0 +1,258 @@ +proc crash.sha1.f + push ebx ecx edx + xor ecx, edx + and ebx, ecx + xor ebx, edx + mov esi, ebx + pop edx ecx ebx + ret +endp + +proc crash.sha1.g + push ebx ecx edx + xor ebx, ecx + xor ebx, edx + mov esi, ebx + pop edx ecx ebx + ret +endp + +proc crash.sha1.h + push ebx ecx edx + mov esi, ebx + and ebx, ecx + and ecx, edx + and esi, edx + or ebx, ecx + or esi, ebx + pop edx ecx ebx + ret +endp + + +proc crash.sha1 _sha1, _data, _len, _callback, _msglen +locals + final rd 1 + temp rd 1 + counter rd 1 + summand rd 1 + shafunc rd 1 + w rd 80 +endl + mov [final], 0 + .first: + mov eax, [_msglen] + mov ecx, [_len] + add [eax], ecx + mov esi, [_data] + test ecx, ecx + jz .callback + .begin: + sub [_len], 64 + jnc @f + add [_len], 64 + jmp .endofblock + @@: + lea edi, [w] + xor ecx, ecx + @@: + mov eax, [esi] + add esi, 4 + bswap eax + mov [edi], eax + add edi, 4 + add ecx, 1 + cmp ecx, 16 + jne @b + @@: + mov eax, [w + (ecx - 3)*4] + xor eax, [w + (ecx - 8)*4] + xor eax, [w + (ecx - 14)*4] + xor eax, [w + (ecx - 16)*4] + rol eax, 1 + mov [w + ecx*4], eax + add ecx, 1 + cmp ecx, 80 + jne @b + + mov edi, [_sha1] + mov eax, [edi + 0x00] + mov ebx, [edi + 0x04] + mov ecx, [edi + 0x08] + mov edx, [edi + 0x0c] + mov edi, [edi + 0x10] + + push esi + + mov [counter], 0 + mov [summand], 0x5a827999 + mov [shafunc], crash.sha1.f + @@: + mov esi, eax + rol esi, 5 + mov [temp], esi + call [shafunc] + + add esi, edi + add [temp], esi + mov esi, [counter] + mov esi, [w + esi*4] + add esi, [summand] + add [temp], esi + + mov edi, edx + mov edx, ecx + mov ecx, ebx + rol ecx, 30 + mov ebx, eax + mov eax, [temp] + + add [counter], 1 + cmp [counter], 20 + jne @b + + mov [summand], 0x6ed9eba1 + mov [shafunc], crash.sha1.g + @@: + mov esi, eax + rol esi, 5 + mov [temp], esi + call dword[shafunc] + + add esi, edi + add [temp], esi + mov esi, [counter] + mov esi, [w + esi*4] + add esi, [summand] + add [temp], esi + + mov edi, edx + mov edx, ecx + mov ecx, ebx + rol ecx, 30 + mov ebx, eax + mov eax, [temp] + + add [counter], 1 + cmp [counter], 40 + jne @b + + mov [summand], 0x8f1bbcdc + mov [shafunc], crash.sha1.h + @@: + mov esi, eax + rol esi, 5 + mov [temp], esi + call dword[shafunc] + + add esi, edi + add [temp], esi + mov esi, [counter] + mov esi, [w + esi*4] + add esi, [summand] + add [temp], esi + + mov edi, edx + mov edx, ecx + mov ecx, ebx + rol ecx, 30 + mov ebx, eax + mov eax, [temp] + + add [counter], 1 + cmp [counter], 60 + jne @b + + mov [summand], 0xca62c1d6 + mov [shafunc], crash.sha1.g + @@: + mov esi, eax + rol esi, 5 + mov [temp], esi + call dword[shafunc] + + add esi, edi + add [temp], esi + mov esi, [counter] + mov esi, [w + esi*4] + add esi, [summand] + add [temp], esi + + mov edi, edx + mov edx, ecx + mov ecx, ebx + rol ecx, 30 + mov ebx, eax + mov eax, [temp] + + add [counter], 1 + cmp [counter], 80 + jne @b + + pop esi + + mov [temp], edi + mov edi, [_sha1] + add [edi + 0x00], eax + add [edi + 0x04], ebx + add [edi + 0x08], ecx + add [edi + 0x0c], edx + mov eax, [temp] + add [edi + 0x10], eax + jmp .begin + .endofblock: + cmp [final], 1 + je .quit + + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + test eax, eax + jz @f + mov [_len], eax + jmp .first + @@: + + mov edi, [_data] + mov ecx, [_len] + rep movsb + mov eax, [_msglen] + mov eax, [eax] + and eax, 63 + mov ecx, 56 + sub ecx, eax + ja @f + add ecx, 64 + @@: + add [_len], ecx + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + bswap eax + bswap edx + mov dword[edi], edx + mov dword[edi + 4], eax + add [_len], 8 + mov [final], 1 + jmp .first + .quit: + mov esi, [_sha1] + mov edi, esi + mov ecx, 5 + @@: + lodsd + bswap eax + stosd + sub ecx, 1 + jnz @b + ret +endp + diff --git a/programs/develop/libraries/libcrash/trunk/sha224_256.asm b/programs/develop/libraries/libcrash/trunk/sha224_256.asm new file mode 100644 index 0000000000..fbacabbe92 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/sha224_256.asm @@ -0,0 +1,278 @@ +macro chn x, y, z +{ + mov eax, [y] + xor eax, [z] + and eax, [x] + xor eax, [z] +} + +macro maj x, y, z +{ + mov eax, [x] + xor eax, [y] + and eax, [z] + mov ecx, [x] + and ecx, [y] + xor eax, ecx +} + +macro Sigma0 x +{ + mov eax, x + mov ecx, eax + ror ecx, 2 + ror eax, 13 + xor eax, ecx + mov ecx, x + ror ecx, 22 + xor eax, ecx +} + +macro Sigma1 x +{ + mov eax, x + mov ecx, eax + ror ecx, 6 + ror eax, 11 + xor eax, ecx + mov ecx, x + ror ecx, 25 + xor eax, ecx +} + +macro sigma0 x +{ + mov eax, x + mov ecx, eax + ror ecx, 7 + ror eax, 18 + xor eax, ecx + mov ecx, x + shr ecx, 3 + xor eax, ecx +} + +macro sigma1 x +{ + mov eax, x + mov ecx, eax + ror ecx, 17 + ror eax, 19 + xor eax, ecx + mov ecx, x + shr ecx, 10 + xor eax, ecx +} + +macro recalculate_w n +{ + mov edx, [w + ((n-2) and 15)*4] + sigma1 edx + add eax, [w + ((n-7) and 15)*4] + push eax + mov edx, [w + ((n-15) and 15)*4] + sigma0 edx + pop ecx + add eax, ecx + add [w + (n)*4], eax +} + +macro crash.sha256.round a, b, c, d, e, f, g, h, k +{ + mov ebx, [h] + mov edx, [e] + Sigma1 edx + + add ebx, eax + chn e, f, g + + add ebx, eax + add ebx, [k] + add ebx, edi + + add [d], ebx + + mov edx, [a] + Sigma0 edx + add ebx, eax + maj a, b, c + add eax, ebx + mov [h], eax +} + + +macro crash.sha256.round_1_16 a, b, c, d, e, f, g, h, n +{ + + mov eax, [esi + (n)*4] + bswap eax + + mov dword[w + (n)*4], eax + mov edi, eax + crash.sha256.round a, b, c, d, e, f, g, h, (crash._.sha256_table + (n)*4) +} + +macro crash.sha256.round_17_64 a, b, c, d, e, f, g, h, n, rep_num +{ + recalculate_w n + mov edi, [w + (n)*4] + crash.sha256.round a, b, c, d, e, f, g, h, (crash._.sha256_table + (n+16*rep_num)*4) +} + + +proc crash.sha256 _sha256, _data, _len, _callback, _msglen +locals + final rd 1 + w rd 64 + A rd 1 + B rd 1 + C rd 1 + D rd 1 + E rd 1 + F rd 1 + G rd 1 + H rd 1 +endl + mov [final], 0 + .first: + mov eax, [_msglen] + mov ecx, [_len] + add [eax], ecx + mov esi, [_data] + test ecx, ecx + jz .callback + .begin: + sub [_len], 64 + jnc @f + add [_len], 64 + jmp .endofblock + @@: + mov edi, [_sha256] + mov eax, [edi + 0x00] + mov [A], eax + mov eax, [edi + 0x04] + mov [B], eax + mov eax, [edi + 0x08] + mov [C], eax + mov eax, [edi + 0x0c] + mov [D], eax + mov eax, [edi + 0x10] + mov [E], eax + mov eax, [edi + 0x14] + mov [F], eax + mov eax, [edi + 0x18] + mov [G], eax + mov eax, [edi + 0x1c] + mov [H], eax + + crash.sha256.round_1_16 A, B, C, D, E, F, G, H, 0 + crash.sha256.round_1_16 H, A, B, C, D, E, F, G, 1 + crash.sha256.round_1_16 G, H, A, B, C, D, E, F, 2 + crash.sha256.round_1_16 F, G, H, A, B, C, D, E, 3 + crash.sha256.round_1_16 E, F, G, H, A, B, C, D, 4 + crash.sha256.round_1_16 D, E, F, G, H, A, B, C, 5 + crash.sha256.round_1_16 C, D, E, F, G, H, A, B, 6 + crash.sha256.round_1_16 B, C, D, E, F, G, H, A, 7 + crash.sha256.round_1_16 A, B, C, D, E, F, G, H, 8 + crash.sha256.round_1_16 H, A, B, C, D, E, F, G, 9 + crash.sha256.round_1_16 G, H, A, B, C, D, E, F, 10 + crash.sha256.round_1_16 F, G, H, A, B, C, D, E, 11 + crash.sha256.round_1_16 E, F, G, H, A, B, C, D, 12 + crash.sha256.round_1_16 D, E, F, G, H, A, B, C, 13 + crash.sha256.round_1_16 C, D, E, F, G, H, A, B, 14 + crash.sha256.round_1_16 B, C, D, E, F, G, H, A, 15 + +repeat 3 + crash.sha256.round_17_64 A, B, C, D, E, F, G, H, 0, % + crash.sha256.round_17_64 H, A, B, C, D, E, F, G, 1, % + crash.sha256.round_17_64 G, H, A, B, C, D, E, F, 2, % + crash.sha256.round_17_64 F, G, H, A, B, C, D, E, 3, % + crash.sha256.round_17_64 E, F, G, H, A, B, C, D, 4, % + crash.sha256.round_17_64 D, E, F, G, H, A, B, C, 5, % + crash.sha256.round_17_64 C, D, E, F, G, H, A, B, 6, % + crash.sha256.round_17_64 B, C, D, E, F, G, H, A, 7, % + crash.sha256.round_17_64 A, B, C, D, E, F, G, H, 8, % + crash.sha256.round_17_64 H, A, B, C, D, E, F, G, 9, % + crash.sha256.round_17_64 G, H, A, B, C, D, E, F, 10, % + crash.sha256.round_17_64 F, G, H, A, B, C, D, E, 11, % + crash.sha256.round_17_64 E, F, G, H, A, B, C, D, 12, % + crash.sha256.round_17_64 D, E, F, G, H, A, B, C, 13, % + crash.sha256.round_17_64 C, D, E, F, G, H, A, B, 14, % + crash.sha256.round_17_64 B, C, D, E, F, G, H, A, 15, % +end repeat + + mov edi, [_sha256] + mov eax, [A] + add [edi + 0x00], eax + mov eax, [B] + add [edi + 0x04], eax + mov eax, [C] + add [edi + 0x08], eax + mov eax, [D] + add [edi + 0x0c], eax + mov eax, [E] + add [edi + 0x10], eax + mov eax, [F] + add [edi + 0x14], eax + mov eax, [G] + add [edi + 0x18], eax + mov eax, [H] + add [edi + 0x1c], eax + add esi, 64 + jmp .begin + .endofblock: + cmp [final], 1 + je .quit + + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + test eax, eax + jz @f + mov [_len], eax + jmp .first + @@: + + mov edi, [_data] + mov ecx, [_len] + rep movsb + mov eax, [_msglen] + mov eax, [eax] + and eax, 63 + mov ecx, 56 + sub ecx, eax + ja @f + add ecx, 64 + @@: + add [_len], ecx + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + bswap eax + bswap edx + mov dword[edi], edx + mov dword[edi + 4], eax + add [_len], 8 + mov [final], 1 + jmp .first + .quit: + mov esi, [_sha256] + mov edi, esi + mov ecx, 8 + @@: + lodsd + bswap eax + stosd + sub ecx, 1 + jnz @b + ret +endp + diff --git a/programs/develop/libraries/libcrash/trunk/sha384_512.asm b/programs/develop/libraries/libcrash/trunk/sha384_512.asm new file mode 100644 index 0000000000..da441f5a23 --- /dev/null +++ b/programs/develop/libraries/libcrash/trunk/sha384_512.asm @@ -0,0 +1,336 @@ +macro chn x, y, z +{ + movq mm0, [y] + pxor mm0, [z] + pand mm0, [x] + pxor mm0, [z] +} + +macro maj x, y, z +{ + movq mm0, [x] + pxor mm0, [y] + pand mm0, [z] + movq mm2, [x] + pand mm2, [y] + pxor mm0, mm2 +} + +macro Sigma0 x +{ + movq mm0, x + movq mm2, mm0 + movq mm7, mm2 + psrlq mm2, 28 + psllq mm7, 36 + por mm2, mm7 + movq mm7, mm0 + psrlq mm0, 34 + psllq mm7, 30 + por mm0, mm7 + pxor mm0, mm2 + movq mm2, x + movq mm7, mm2 + psrlq mm2, 39 + psllq mm7, 25 + por mm2, mm7 + pxor mm0, mm2 +} + +macro Sigma1 x +{ + movq mm0, x + movq mm2, mm0 + movq mm7, mm2 + psrlq mm2, 14 + psllq mm7, 50 + por mm2, mm7 + movq mm7, mm0 + psrlq mm0, 18 + psllq mm7, 46 + por mm0, mm7 + pxor mm0, mm2 + movq mm2, x + movq mm7, mm2 + psrlq mm2, 41 + psllq mm7, 23 + por mm2, mm7 + pxor mm0, mm2 +} + +macro sigma0 x +{ + movq mm0, x + movq mm2, mm0 + movq mm7, mm2 + psrlq mm2, 1 + psllq mm7, 63 + por mm2, mm7 + movq mm7, mm0 + psrlq mm0, 8 + psllq mm7, 56 + por mm0, mm7 + pxor mm0, mm2 + movq mm2, x + psrlq mm2, 7 + pxor mm0, mm2 +} + +macro sigma1 x +{ + movq mm0, x + movq mm2, mm0 + movq mm7, mm2 + psrlq mm2, 19 + psllq mm7, 45 + por mm2, mm7 + movq mm7, mm0 + psrlq mm0, 61 + psllq mm7, 3 + por mm0, mm7 + pxor mm0, mm2 + movq mm2, x + psrlq mm2, 6 + pxor mm0, mm2 +} + +macro recalculate_w n +{ + movq mm3, [w + ((n-2) and 15)*8] + sigma1 mm3 + paddq mm0, [w + ((n-7) and 15)*8] + movq mm6, mm0 + movq mm3, [w + ((n-15) and 15)*8] + sigma0 mm3 + movq mm2, mm6 + paddq mm0, mm2 + movq mm7, [w + (n)*8] + paddq mm7, mm0 + movq [w + (n)*8], mm7 +} + +macro crash.sha512.round a, b, c, d, e, f, g, h, k +{ + movq mm1, [h] + movq mm3, [e] + Sigma1 mm3 + paddq mm1, mm0 + chn e, f, g + paddq mm1, mm0 + paddq mm1, [k] + paddq mm1, mm5 + movq mm7, [d] + paddq mm7, mm1 + movq [d], mm7 + movq mm3, [a] + Sigma0 mm3 + paddq mm1, mm0 + maj a, b, c + paddq mm0, mm1 + movq [h], mm0 +} + + +macro crash.sha512.round_1_16 a, b, c, d, e, f, g, h, n +{ + + movq mm0, [esi + (n)*8] + movq [temp], mm0 + mov eax, dword[temp] + bswap eax + push eax + mov eax, dword[temp + 4] + bswap eax + mov dword[temp], eax + pop eax + mov dword[temp + 4], eax + movq mm0, [temp] + movq [w + (n)*8], mm0 + movq mm5, mm0 + crash.sha512.round a, b, c, d, e, f, g, h, (crash._.sha512_table + (n)*8) +} + +macro crash.sha512.round_17_64 a, b, c, d, e, f, g, h, n, rep_num +{ + recalculate_w n + movq mm5, [w + (n)*8] + crash.sha512.round a, b, c, d, e, f, g, h, (crash._.sha512_table + (n+16*rep_num)*8) +} + + +proc crash.sha512 _sha512, _data, _len, _callback, _msglen +locals + final rd 1 + w rq 80 + A rq 1 + B rq 1 + C rq 1 + D rq 1 + E rq 1 + F rq 1 + G rq 1 + H rq 1 + temp rq 1 +endl + mov [final], 0 + .first: + mov eax, [_msglen] + mov ecx, [_len] + add [eax], ecx + mov esi, [_data] + test ecx, ecx + jz .callback + .begin: + sub [_len], 128 + jnc @f + add [_len], 128 + jmp .endofblock + @@: + mov edi, [_sha512] + movq mm0, [edi + 0x00] + movq [A], mm0 + movq mm0, [edi + 0x08] + movq [B], mm0 + movq mm0, [edi + 0x10] + movq [C], mm0 + movq mm0, [edi + 0x18] + movq [D], mm0 + movq mm0, [edi + 0x20] + movq [E], mm0 + movq mm0, [edi + 0x28] + movq [F], mm0 + movq mm0, [edi + 0x30] + movq [G], mm0 + movq mm0, [edi + 0x38] + movq [H], mm0 + + + crash.sha512.round_1_16 A, B, C, D, E, F, G, H, 0 + crash.sha512.round_1_16 H, A, B, C, D, E, F, G, 1 + crash.sha512.round_1_16 G, H, A, B, C, D, E, F, 2 + crash.sha512.round_1_16 F, G, H, A, B, C, D, E, 3 + crash.sha512.round_1_16 E, F, G, H, A, B, C, D, 4 + crash.sha512.round_1_16 D, E, F, G, H, A, B, C, 5 + crash.sha512.round_1_16 C, D, E, F, G, H, A, B, 6 + crash.sha512.round_1_16 B, C, D, E, F, G, H, A, 7 + crash.sha512.round_1_16 A, B, C, D, E, F, G, H, 8 + crash.sha512.round_1_16 H, A, B, C, D, E, F, G, 9 + crash.sha512.round_1_16 G, H, A, B, C, D, E, F, 10 + crash.sha512.round_1_16 F, G, H, A, B, C, D, E, 11 + crash.sha512.round_1_16 E, F, G, H, A, B, C, D, 12 + crash.sha512.round_1_16 D, E, F, G, H, A, B, C, 13 + crash.sha512.round_1_16 C, D, E, F, G, H, A, B, 14 + crash.sha512.round_1_16 B, C, D, E, F, G, H, A, 15 + +repeat 4 + crash.sha512.round_17_64 A, B, C, D, E, F, G, H, 0, % + crash.sha512.round_17_64 H, A, B, C, D, E, F, G, 1, % + crash.sha512.round_17_64 G, H, A, B, C, D, E, F, 2, % + crash.sha512.round_17_64 F, G, H, A, B, C, D, E, 3, % + crash.sha512.round_17_64 E, F, G, H, A, B, C, D, 4, % + crash.sha512.round_17_64 D, E, F, G, H, A, B, C, 5, % + crash.sha512.round_17_64 C, D, E, F, G, H, A, B, 6, % + crash.sha512.round_17_64 B, C, D, E, F, G, H, A, 7, % + crash.sha512.round_17_64 A, B, C, D, E, F, G, H, 8, % + crash.sha512.round_17_64 H, A, B, C, D, E, F, G, 9, % + crash.sha512.round_17_64 G, H, A, B, C, D, E, F, 10, % + crash.sha512.round_17_64 F, G, H, A, B, C, D, E, 11, % + crash.sha512.round_17_64 E, F, G, H, A, B, C, D, 12, % + crash.sha512.round_17_64 D, E, F, G, H, A, B, C, 13, % + crash.sha512.round_17_64 C, D, E, F, G, H, A, B, 14, % + crash.sha512.round_17_64 B, C, D, E, F, G, H, A, 15, % +end repeat + + + mov edi, [_sha512] + movq mm0, [A] + paddq mm0, [edi + 0x00] + movq [edi + 0x00], mm0 + movq mm0, [B] + paddq mm0, [edi + 0x08] + movq [edi + 0x08], mm0 + movq mm0, [C] + paddq mm0, [edi + 0x10] + movq [edi + 0x10], mm0 + movq mm0, [D] + paddq mm0, [edi + 0x18] + movq [edi + 0x18], mm0 + movq mm0, [E] + paddq mm0, [edi + 0x20] + movq [edi + 0x20], mm0 + movq mm0, [F] + paddq mm0, [edi + 0x28] + movq [edi + 0x28], mm0 + movq mm0, [G] + paddq mm0, [edi + 0x30] + movq [edi + 0x30], mm0 + movq mm0, [H] + paddq mm0, [edi + 0x38] + movq [edi + 0x38], mm0 + add esi, 128 + jmp .begin + .endofblock: + cmp [final], 1 + je .quit + + .callback: + mov eax, [_callback] + test eax, eax + jz @f + call eax + test eax, eax + jz @f + mov [_len], eax + jmp .first + @@: + + mov edi, [_data] + mov ecx, [_len] + rep movsb + mov eax, [_msglen] + mov eax, [eax] + and eax, 127 + mov ecx, 112 + sub ecx, eax + ja @f + add ecx, 128 + @@: + add [_len], ecx + mov byte[edi], 0x80 + add edi, 1 + sub ecx, 1 + mov al, 0 + rep stosb + xor eax, eax + stosd + stosd + mov eax, [_msglen] + mov eax, [eax] + mov edx, 8 + mul edx + bswap eax + bswap edx + mov dword[edi], edx + mov dword[edi + 4], eax + add [_len], 16 + mov [final], 1 + jmp .first + .quit: + mov esi, [_sha512] + mov edi, esi + mov ecx, 8 + @@: + lodsd + bswap eax + mov ebx, eax + lodsd + bswap eax + stosd + mov eax, ebx + stosd + sub ecx, 1 + jnz @b + emms + ret +endp +