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 |
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 |
|