Subversion Repositories Kolibri OS

Rev

Rev 7698 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7698 Rev 9216
Line 1... Line 1...
1
;    libcrash -- cryptographic hash functions
1
; libcrash -- cryptographic hash (and other) functions
2
;
2
;
3
;    Copyright (C) 2012-2013,2016,2019 Ivan Baravy (dunkaist)
3
; Copyright (C) <2012-2013,2016,2019,2021> Ivan Baravy
4
;
4
;
5
;    This program is free software: you can redistribute it and/or modify
-
 
6
;    it under the terms of the GNU General Public License as published by
-
 
7
;    the Free Software Foundation, either version 3 of the License, or
-
 
8
;    (at your option) any later version.
5
; SPDX-License-Identifier: GPL-2.0-or-later
9
;
6
;
10
;    This program is distributed in the hope that it will be useful,
7
; This program is free software: you can redistribute it and/or modify it under
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
8
; the terms of the GNU General Public License as published by the Free Software
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
; Foundation, either version 2 of the License, or (at your option) any later
13
;    GNU General Public License for more details.
10
; version.
14
;
11
;
-
 
12
; This program is distributed in the hope that it will be useful, but WITHOUT
-
 
13
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-
 
14
; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
 
15
;
15
;    You should have received a copy of the GNU General Public License
16
; You should have received a copy of the GNU General Public License along with
16
;    along with this program.  If not, see .
17
; this program. If not, see .
17
 
-
 
Line 18... Line -...
18
 
-
 
19
SHA1_HASH_SIZE  = 20
18
 
Line 20... Line 19...
20
SHA1_BLOCK_SIZE = 64
19
SHA1_BLOCK_SIZE = 64
21
 
20
 
Line 22... Line 21...
22
SHA1_ALIGN      = 4
21
SHA1_ALIGN      = 4
23
SHA1_ALIGN_MASK = SHA1_ALIGN - 1
22
SHA1_ALIGN_MASK = SHA1_ALIGN - 1
24
 
23
 
25
struct ctx_sha1
24
struct ctx_sha1
26
        hash            rb SHA1_HASH_SIZE
25
        hash            rb SHA1_LEN
27
        block           rb SHA1_BLOCK_SIZE
26
        block           rb SHA1_BLOCK_SIZE
28
        index           rd 1
27
        index           rd 1
Line 29... Line -...
29
        msglen_0        rd 1
-
 
30
        msglen_1        rd 1
28
        msglen_0        rd 1
31
ends
-
 
Line 32... Line 29...
32
 
29
        msglen_1        rd 1
33
if defined sizeof.crash_ctx
30
ends
34
  assert sizeof.crash_ctx >= sizeof.ctx_sha1
31
 
35
end if
32
assert sizeof.ctx_sha1 <= LIBCRASH_CTX_LEN
Line 85... Line 82...
85
        mov     ebx, eax
82
        mov     ebx, eax
86
        mov     eax, [temp]
83
        mov     eax, [temp]
87
}
84
}
Line 88... Line 85...
88
 
85
 
89
 
86
 
90
proc sha1.init _ctx
87
proc sha1.init uses ebx esi edi, _ctx
91
        mov     ebx, [_ctx]
88
        mov     ebx, [_ctx]
92
        lea     edi, [ebx + ctx_sha1.hash]
89
        lea     edi, [ebx + ctx_sha1.hash]
93
        mov     esi, sha1._.hash_init
90
        mov     esi, sha1._.hash_init
94
        mov     ecx, SHA1_HASH_SIZE/4
91
        mov     ecx, SHA1_LEN/4
95
        rep     movsd
92
        rep movsd
96
        xor     eax, eax
93
        xor     eax, eax
97
        mov     [ebx + ctx_sha1.index], eax
94
        mov     [ebx + ctx_sha1.index], eax
Line 166... Line 163...
166
 
163
 
167
        ret
164
        ret
Line 168... Line 165...
168
endp
165
endp
169
 
166
 
170
 
167
 
171
proc sha1.update _ctx, _msg, _size
168
proc sha1.update uses ebx esi edi, _ctx, _msg, _size
172
        mov     ebx, [_ctx]
169
        mov     ebx, [_ctx]
Line 222... Line 219...
222
 
219
 
223
        ret
220
        ret
Line 224... Line 221...
224
endp
221
endp
225
 
222
 
226
 
223
 
227
proc sha1.final _ctx
224
proc sha1.finish uses ebx esi edi, _ctx
228
        mov     ebx, [_ctx]
225
        mov     ebx, [_ctx]
229
        lea     edi, [ebx + ctx_sha1.block]
226
        lea     edi, [ebx + ctx_sha1.block]
Line 286... Line 283...
286
 
283
 
287
 
284
 
288
proc sha1.oneshot _ctx, _data, _len
285
proc sha1.oneshot _ctx, _data, _len
289
	stdcall	sha1.init, [_ctx]
286
        stdcall sha1.init, [_ctx]
290
	stdcall	sha1.update, [_ctx], [_data], [_len]
287
        stdcall sha1.update, [_ctx], [_data], [_len]
291
	stdcall	sha1.final, [_ctx]
288
        stdcall sha1.finish, [_ctx]
Line 292... Line 289...
292
	ret
289
        ret