/programs/develop/libraries/libcrash/trunk/crc32.asm |
---|
File deleted |
/programs/develop/libraries/libcrash/trunk/crashtest.asm |
---|
1,7 → 1,7 |
use32 |
org 0x0 |
db 'MENUET01' |
dd 0x01,start,i_end,e_end,e_end,0,0 |
dd 0x01,start,i_end,e_end,e_end,0,this_file_name |
include '../../../../proc32.inc' |
include '../../../../macros.inc' |
19,12 → 19,12 |
or eax, eax |
jnz quit |
invoke file.open, input_file, O_READ |
invoke file.open, this_file_name, O_READ |
or eax, eax |
jz quit |
mov [fh], eax |
invoke file.size, input_file |
invoke file.size, this_file_name |
mov [file_len], ebx |
stdcall mem.Alloc, ebx |
101,8 → 101,6 |
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 |
110,7 → 108,7 |
count dd BUFFER_SIZE |
dst dd data_buffer |
res2 db 0 |
fname dd input_file |
fname dd this_file_name |
align 4 |
@IMPORT: |
142,6 → 140,7 |
file_data rd 1 |
file_len rd 1 |
this_file_name rb 4096 |
rb 0x400 ;stack |
e_end: |
/programs/develop/libraries/libcrash/trunk/libcrash.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
format MS COFF |
public @EXPORT as 'EXPORTS' |
11,8 → 28,8 |
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' |
21,101 → 38,207 |
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 |
proc crash.hash _hid, _hash, _data, _len, _callback, _msglen |
locals |
hash_func rd 1 |
final rd 1 |
hi 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 eax, [_hid] |
imul eax, sizeof.crash_item |
lea eax, [crash._.table + eax] |
mov [hi], eax |
mov eax, [hi] |
mov edx, [eax + crash_item.function] |
mov esi, [eax + crash_item.init_val] |
mov edi, [_hash] |
mov [hash_func], edx |
and ecx, 0x0000ff00 |
shr ecx, 8 |
mov ecx, [hi] |
mov ecx, [ecx + crash_item.len_in] |
rep movsd |
stdcall [hash_func], [_hash], [_data], [_len], [_callback], [_msglen] |
mov [final], 0 |
.first: |
mov eax, [_msglen] |
mov ecx, [_len] |
add [eax], ecx |
mov esi, [_data] |
test ecx, ecx |
jz .callback |
.begin: |
mov eax, [hi] |
mov eax, [eax + crash_item.len_blk] |
sub [_len], eax |
jnc @f |
add [_len], eax |
jmp .endofblock |
@@: |
stdcall [hash_func], [_hash], [_data] |
jmp .begin |
.endofblock: |
cmp [final], 1 |
je .quit |
.callback: |
call [_callback] |
test eax, eax |
jz @f |
mov [_len], eax |
jmp .first |
@@: |
mov edi, [_data] |
mov ecx, [_len] |
rep movsb |
mov eax, [_msglen] |
mov eax, [eax] |
mov edx, [hi] |
mov edx, [edx + crash_item.len_blk] |
sub edx, 1 |
and eax, edx |
mov edx, [hi] |
mov ecx, [edx + crash_item.len_blk] |
sub ecx, [edx + crash_item.len_size] |
sub ecx, eax |
ja @f |
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] |
add [_len], eax |
mov [final], 1 |
jmp .first |
.quit: |
mov eax, [hi] |
stdcall [eax + crash_item.postproc], [eax + crash_item.len_out], [_hash] |
ret |
endp |
proc crash.bin2hex _bin, _hex, _type |
xor eax, eax |
proc crash._.md4_md5_postprocess _len_out, _hash |
ret |
endp |
proc crash._.sha1_224_256_postprocess _len_out, _hash |
mov ecx, [_len_out] |
mov esi, [_hash] |
mov edi, esi |
@@: |
lodsd |
bswap eax |
stosd |
dec ecx |
jnz @b |
ret |
endp |
proc crash._.sha384_512_postprocess _len_out, _hash |
mov ecx, [_len_out] |
mov esi, [_hash] |
mov edi, esi |
@@: |
lodsd |
mov ebx, eax |
lodsd |
bswap eax |
bswap ebx |
stosd |
mov eax, ebx |
stosd |
dec ecx |
jnz @b |
emms |
ret |
endp |
proc crash.bin2hex _bin, _hex, _hid ; FIXME _hid param? |
mov eax, [_hid] |
imul eax, sizeof.crash_item |
mov ecx, [crash._.table + eax + crash_item.len_out] |
mov ebx, crash._.bin2hex_table |
mov esi, [_bin] |
mov edi, [_hex] |
mov ecx, [_type] |
and ecx, 0x00ff0000 |
shr ecx, 16 - 2 |
.byte: |
shl ecx, 2 |
.next_byte: |
xor eax, eax |
lodsb |
mov ah, al |
shr ah, 4 |
and al, 0x0f |
shl eax, 4 |
shr al, 4 |
xlatb |
xchg al, ah |
xlatb |
stosw |
dec ecx |
jnz .byte |
jnz .next_byte |
xor al, al |
stosb |
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 |
; 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._.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,\ |
146,6 → 269,7 |
0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\ |
0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 |
align 4 |
@EXPORT: |
/programs/develop/libraries/libcrash/trunk/libcrash.inc |
---|
1,8 → 1,38 |
LIBCRASH_CRC32 = 0x00010101 |
LIBCRASH_MD4 = 0x00040402 |
LIBCRASH_MD5 = 0x00040403 |
LIBCRASH_SHA1 = 0x00050504 |
LIBCRASH_SHA224 = 0x00070805 |
LIBCRASH_SHA256 = 0x00080806 |
LIBCRASH_SHA384 = 0x000c1007 |
LIBCRASH_SHA512 = 0x00101008 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
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 |
struct crash_item |
function dd ? |
init_val dd ? |
postproc dd ? |
len_in dd ? |
len_out dd ? |
len_blk dd ? |
len_size dd ? |
endianness dd ? |
ends |
/programs/develop/libraries/libcrash/trunk/md4.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
macro crash.md4.f b, c, d |
{ |
push c |
36,24 → 53,7 |
} |
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 |
@@: |
proc crash.md4 _md4, _data |
mov edi, [_md4] |
mov eax, [edi + 0x0] |
mov ebx, [edi + 0x4] |
117,49 → 117,7 |
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 |
/programs/develop/libraries/libcrash/trunk/md5.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
macro crash.md5.f b, c, d |
{ |
push c |
44,24 → 61,7 |
} |
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 |
@@: |
proc crash.md5 _md5, _data |
mov edi, [_md5] |
mov eax, [edi + 0x0] |
mov ebx, [edi + 0x4] |
142,49 → 142,7 |
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 |
/programs/develop/libraries/libcrash/trunk/sha1.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
proc crash.sha1.f |
push ebx ecx edx |
xor ecx, edx |
29,30 → 46,33 |
ret |
endp |
macro crash.sha1.round f, k, c |
{ |
mov esi, eax |
rol esi, 5 |
mov [temp], esi |
call f |
proc crash.sha1 _sha1, _data, _len, _callback, _msglen |
add esi, edi |
add [temp], esi |
mov esi, [w + (c)*4] |
add esi, k |
add [temp], esi |
mov edi, edx |
mov edx, ecx |
mov ecx, ebx |
rol ecx, 30 |
mov ebx, eax |
mov eax, [temp] |
} |
proc crash.sha1 _sha1, _data |
locals |
final rd 1 |
temp rd 1 |
counter rd 1 |
summand rd 1 |
shafunc rd 1 |
w rd 80 |
temp 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 |
@@: |
84,111 → 104,22 |
push esi |
mov [counter], 0 |
mov [summand], 0x5a827999 |
mov [shafunc], crash.sha1.f |
@@: |
mov esi, eax |
rol esi, 5 |
mov [temp], esi |
call [shafunc] |
repeat 20 |
crash.sha1.round crash.sha1.f, 0x5a827999, %-1 |
end repeat |
add esi, edi |
add [temp], esi |
mov esi, [counter] |
mov esi, [w + esi*4] |
add esi, [summand] |
add [temp], esi |
repeat 20 |
crash.sha1.round crash.sha1.g, 0x6ed9eba1, %-1+20 |
end repeat |
mov edi, edx |
mov edx, ecx |
mov ecx, ebx |
rol ecx, 30 |
mov ebx, eax |
mov eax, [temp] |
repeat 20 |
crash.sha1.round crash.sha1.h, 0x8f1bbcdc, %-1+40 |
end repeat |
add [counter], 1 |
cmp [counter], 20 |
jne @b |
repeat 20 |
crash.sha1.round crash.sha1.g, 0xca62c1d6, %-1+60 |
end repeat |
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 |
199,60 → 130,7 |
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 |
/programs/develop/libraries/libcrash/trunk/sha224_256.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
macro chn x, y, z |
{ |
mov eax, [y] |
120,9 → 137,8 |
} |
proc crash.sha256 _sha256, _data, _len, _callback, _msglen |
proc crash.sha256 _sha256, _data |
locals |
final rd 1 |
w rd 64 |
A rd 1 |
B rd 1 |
133,20 → 149,6 |
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 |
219,60 → 221,7 |
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 |
/programs/develop/libraries/libcrash/trunk/sha384_512.asm |
---|
1,3 → 1,20 |
; libcrash -- cryptographic hash functions |
; |
; Copyright (C) 2012-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 <http://www.gnu.org/licenses/>. |
macro chn x, y, z |
{ |
movq mm0, [y] |
158,9 → 175,8 |
} |
proc crash.sha512 _sha512, _data, _len, _callback, _msglen |
proc crash.sha512 _sha512, _data |
locals |
final rd 1 |
w rq 80 |
A rq 1 |
B rq 1 |
172,20 → 188,6 |
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 |
268,69 → 270,7 |
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 |