forked from KolibriOS/kolibrios
libcrash:
move common code parts from all the *hash*.asm files to libcrash.asm replace procedures to macroses in sha1 in favour of readability and uniformity add license notes git-svn-id: svn://kolibrios.org@3431 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -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 @@ macro crash.sha256.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
|
||||
}
|
||||
|
||||
|
||||
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 @@ locals
|
||||
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 @@ end repeat
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user