2013-03-29 21:13:07 +01:00
|
|
|
; libcrash -- cryptographic hash functions
|
|
|
|
;
|
2016-07-12 23:16:28 +02:00
|
|
|
; Copyright (C) 2012-2014,2016 Ivan Baravy (dunkaist)
|
2013-03-29 21:13:07 +01:00
|
|
|
;
|
|
|
|
; 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/>.
|
|
|
|
|
2012-12-15 18:23:23 +01:00
|
|
|
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'
|
2016-07-12 23:16:28 +02:00
|
|
|
include 'crc32.asm'
|
2012-12-15 18:23:23 +01:00
|
|
|
include 'md4.asm'
|
|
|
|
include 'md5.asm'
|
|
|
|
include 'sha1.asm'
|
|
|
|
include 'sha224_256.asm'
|
|
|
|
include 'sha384_512.asm'
|
2013-05-24 17:27:40 +02:00
|
|
|
include 'sha3.asm'
|
2012-12-15 18:23:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
proc lib_init
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
2016-07-12 23:16:28 +02:00
|
|
|
proc crash.hash _hid, _data, _callback, _ctx
|
2012-12-15 18:23:23 +01:00
|
|
|
locals
|
2016-07-12 23:16:28 +02:00
|
|
|
size dd ?
|
2012-12-15 18:23:23 +01:00
|
|
|
endl
|
2016-07-12 23:16:28 +02:00
|
|
|
mov [size], 0
|
|
|
|
mov eax, [_hid]
|
|
|
|
imul eax, sizeof.crash_item
|
|
|
|
lea edx, [crash._.table + eax]
|
|
|
|
mov ebx, [_ctx]
|
|
|
|
|
|
|
|
stdcall [edx + crash_item.init], [_ctx]
|
|
|
|
|
|
|
|
.hash:
|
|
|
|
mov esi, [_data]
|
|
|
|
push edx
|
|
|
|
stdcall [edx + crash_item.update], [_ctx], [_data], [size]
|
|
|
|
mov [size], 0
|
|
|
|
pop edx
|
|
|
|
|
|
|
|
mov eax, [_callback]
|
|
|
|
test eax, eax
|
|
|
|
jz .quit
|
|
|
|
push edx
|
|
|
|
stdcall [_callback], [size]
|
|
|
|
pop edx
|
|
|
|
mov [size], eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .hash
|
|
|
|
|
|
|
|
stdcall [edx + crash_item.final], [_ctx]
|
2013-05-24 17:27:40 +02:00
|
|
|
.quit:
|
2016-07-12 23:16:28 +02:00
|
|
|
ret
|
2013-05-24 17:27:40 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
|
2016-07-12 23:16:28 +02:00
|
|
|
proc crash.bin2hex _bin, _hex, _hid
|
|
|
|
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]
|
2013-03-29 21:13:07 +01:00
|
|
|
.next_byte:
|
2016-07-12 23:16:28 +02:00
|
|
|
xor eax, eax
|
|
|
|
lodsb
|
|
|
|
shl eax, 4
|
|
|
|
shr al, 4
|
|
|
|
xlatb
|
|
|
|
xchg al, ah
|
|
|
|
xlatb
|
|
|
|
stosw
|
|
|
|
dec ecx
|
|
|
|
jnz .next_byte
|
|
|
|
xor al, al
|
|
|
|
stosb
|
|
|
|
ret
|
2012-12-15 18:23:23 +01:00
|
|
|
endp
|
|
|
|
|
|
|
|
|
2016-07-12 23:16:28 +02:00
|
|
|
section '.data' data readable align 16
|
|
|
|
crash._.bin2hex_table db '0123456789abcdef'
|
|
|
|
|
|
|
|
crash._.table dd \
|
|
|
|
crc32.init, crc32.update, crc32.final, CRC32_HASH_SIZE, \
|
|
|
|
md4.init, md4.update, md4.final, MD4_HASH_SIZE, \
|
|
|
|
md5.init, md5.update, md5.final, MD5_HASH_SIZE, \
|
|
|
|
sha1.init, sha1.update, sha1.final, SHA1_HASH_SIZE, \
|
|
|
|
sha224.init, sha224256.update, sha224256.final, SHA224_HASH_SIZE, \
|
|
|
|
sha256.init, sha224256.update, sha224256.final, SHA256_HASH_SIZE, \
|
|
|
|
sha384.init, sha384512.update, sha384512.final, SHA384_HASH_SIZE, \
|
|
|
|
sha512.init, sha384512.update, sha384512.final, SHA512_HASH_SIZE, \
|
|
|
|
sha3224.init, sha3.update, sha3.final, SHA3224_HASH_SIZE,\
|
|
|
|
sha3256.init, sha3.update, sha3.final, SHA3256_HASH_SIZE,\
|
|
|
|
sha3384.init, sha3.update, sha3.final, SHA3384_HASH_SIZE,\
|
|
|
|
sha3512.init, sha3.update, sha3.final, SHA3512_HASH_SIZE
|
2013-03-29 21:13:07 +01:00
|
|
|
|
2012-12-15 18:23:23 +01:00
|
|
|
align 4
|
|
|
|
@EXPORT:
|
|
|
|
|
|
|
|
export \
|
|
|
|
lib_init , 'lib_init' , \
|
|
|
|
crash.hash , 'crash_hash' , \
|
|
|
|
crash.bin2hex , 'crash_bin2hex'
|
|
|
|
|