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...
18
 
18
 
19
SHA224256_BLOCK_SIZE = 64
19
SHA2_224256_BLOCK_SIZE = 64
20
SHA224_BLOCK_SIZE    = SHA224256_BLOCK_SIZE
20
SHA2_224_BLOCK_SIZE    = SHA2_224256_BLOCK_SIZE
21
SHA256_BLOCK_SIZE    = SHA224256_BLOCK_SIZE
-
 
22
SHA224_HASH_SIZE     = 28
-
 
23
SHA256_HASH_SIZE     = 32
21
SHA2_256_BLOCK_SIZE    = SHA2_224256_BLOCK_SIZE
24
 
22
 
25
SHA224256_INIT_SIZE  = 32
23
SHA2_224256_INIT_SIZE  = 32
26
SHA224256_ALIGN      = 4
24
SHA2_224256_ALIGN      = 4
27
SHA224256_ALIGN_MASK = SHA224256_ALIGN - 1
25
SHA2_224256_ALIGN_MASK = SHA2_224256_ALIGN - 1
28
 
26
 
29
struct ctx_sha224256
27
struct ctx_sha2_224256
30
        hash            rb SHA224256_INIT_SIZE
28
        hash            rb SHA2_224256_INIT_SIZE
31
        block           rb SHA224256_BLOCK_SIZE
29
        block           rb SHA2_224256_BLOCK_SIZE
32
        index           rd 1
30
        index           rd 1
33
        msglen_0        rd 1
31
        msglen_0        rd 1
34
        msglen_1        rd 1
32
        msglen_1        rd 1
Line 35... Line -...
35
ends
-
 
36
 
33
ends
37
if defined sizeof.crash_ctx
-
 
38
  assert sizeof.crash_ctx >= sizeof.ctx_sha224256
-
 
Line 39... Line 34...
39
end if
34
 
40
 
35
assert sizeof.ctx_sha2_224256 <= LIBCRASH_CTX_LEN
41
 
36
 
42
macro sha224256._.chn x, y, z
37
macro sha2_224256._.chn x, y, z
43
{
38
{
44
        mov     eax, [y]
39
        mov     eax, [y]
45
        xor     eax, [z]
40
        xor     eax, [z]
Line 46... Line 41...
46
        and     eax, [x]
41
        and     eax, [x]
47
        xor     eax, [z]
42
        xor     eax, [z]
48
}
43
}
49
 
44
 
50
macro sha224256._.maj x, y, z
45
macro sha2_224256._.maj x, y, z
51
{
46
{
52
        mov     eax, [x]
47
        mov     eax, [x]
53
        xor     eax, [y]
48
        xor     eax, [y]
54
        and     eax, [z]
49
        and     eax, [z]
Line 55... Line 50...
55
        mov     ecx, [x]
50
        mov     ecx, [x]
56
        and     ecx, [y]
51
        and     ecx, [y]
57
        xor     eax, ecx
52
        xor     eax, ecx
58
}
53
}
59
 
54
 
60
macro sha224256._.Sigma0 x
55
macro sha2_224256._.Sigma0 x
Line 67... Line 62...
67
        mov     ecx, x
62
        mov     ecx, x
68
        ror     ecx, 22
63
        ror     ecx, 22
69
        xor     eax, ecx
64
        xor     eax, ecx
70
}
65
}
Line 71... Line 66...
71
 
66
 
72
macro sha224256._.Sigma1 x
67
macro sha2_224256._.Sigma1 x
73
{
68
{
74
        mov     eax, x
69
        mov     eax, x
75
        mov     ecx, eax
70
        mov     ecx, eax
76
        ror     ecx, 6
71
        ror     ecx, 6
Line 79... Line 74...
79
        mov     ecx, x
74
        mov     ecx, x
80
        ror     ecx, 25
75
        ror     ecx, 25
81
        xor     eax, ecx
76
        xor     eax, ecx
82
}
77
}
Line 83... Line 78...
83
 
78
 
84
macro sha224256._.sigma0 x
79
macro sha2_224256._.sigma0 x
85
{
80
{
86
        mov     eax, x
81
        mov     eax, x
87
        mov     ecx, eax
82
        mov     ecx, eax
88
        ror     ecx, 7
83
        ror     ecx, 7
Line 91... Line 86...
91
        mov     ecx, x
86
        mov     ecx, x
92
        shr     ecx, 3
87
        shr     ecx, 3
93
        xor     eax, ecx
88
        xor     eax, ecx
94
}
89
}
Line 95... Line 90...
95
 
90
 
96
macro sha224256._.sigma1 x
91
macro sha2_224256._.sigma1 x
97
{
92
{
98
        mov     eax, x
93
        mov     eax, x
99
        mov     ecx, eax
94
        mov     ecx, eax
100
        ror     ecx, 17
95
        ror     ecx, 17
Line 103... Line 98...
103
        mov     ecx, x
98
        mov     ecx, x
104
        shr     ecx, 10
99
        shr     ecx, 10
105
        xor     eax, ecx
100
        xor     eax, ecx
106
}
101
}
Line 107... Line 102...
107
 
102
 
108
macro sha224256._.recalculate_w n
103
macro sha2_224256._.recalculate_w n
109
{
104
{
110
        mov     edx, [w + ((n-2) and 15)*4]
105
        mov     edx, [w + ((n-2) and 15)*4]
111
        sha224256._.sigma1  edx
106
        sha2_224256._.sigma1  edx
112
        add     eax, [w + ((n-7) and 15)*4]
107
        add     eax, [w + ((n-7) and 15)*4]
113
        push    eax
108
        push    eax
114
        mov     edx, [w + ((n-15) and 15)*4]
109
        mov     edx, [w + ((n-15) and 15)*4]
115
        sha224256._.sigma0  edx
110
        sha2_224256._.sigma0  edx
116
        pop     ecx
111
        pop     ecx
117
        add     eax, ecx
112
        add     eax, ecx
118
        add     [w + (n)*4], eax
113
        add     [w + (n)*4], eax
Line 119... Line 114...
119
}
114
}
120
 
115
 
121
macro sha224256._.round a, b, c, d, e, f, g, h, k
116
macro sha2_224256._.round a, b, c, d, e, f, g, h, k
122
{
117
{
123
        mov     ebx, [h]
118
        mov     ebx, [h]
Line 124... Line 119...
124
        mov     edx, [e]
119
        mov     edx, [e]
125
        sha224256._.Sigma1  edx
120
        sha2_224256._.Sigma1  edx
Line 126... Line 121...
126
 
121
 
127
        add     ebx, eax
122
        add     ebx, eax
128
        sha224256._.chn     e, f, g
123
        sha2_224256._.chn     e, f, g
Line 129... Line 124...
129
 
124
 
Line 130... Line 125...
130
        add     ebx, eax
125
        add     ebx, eax
131
        add     ebx, [k]
126
        add     ebx, [k]
132
        add     ebx, edi
127
        add     ebx, edi
133
 
128
 
134
        add     [d], ebx
129
        add     [d], ebx
135
 
130
 
136
        mov     edx, [a]
131
        mov     edx, [a]
Line 137... Line 132...
137
        sha224256._.Sigma0  edx
132
        sha2_224256._.Sigma0  edx
138
        add     ebx, eax
133
        add     ebx, eax
Line 139... Line 134...
139
        sha224256._.maj     a, b, c
134
        sha2_224256._.maj     a, b, c
140
        add     eax, ebx
135
        add     eax, ebx
Line 141... Line 136...
141
        mov     [h], eax
136
        mov     [h], eax
142
}
137
}
143
 
138
 
144
 
139
 
Line 145... Line 140...
145
macro sha224256._.round_1_16 a, b, c, d, e, f, g, h, n
140
macro sha2_224256._.round_1_16 a, b, c, d, e, f, g, h, n
146
{
141
{
147
 
142
 
148
        mov     eax, [esi + (n)*4]
143
        mov     eax, [esi + (n)*4]
149
        bswap   eax
144
        bswap   eax
150
 
145
 
Line 151... Line 146...
151
        mov     dword[w + (n)*4], eax
146
        mov     dword[w + (n)*4], eax
152
        mov     edi, eax
147
        mov     edi, eax
153
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n)*4)
148
        sha2_224256._.round a, b, c, d, e, f, g, h, (sha2_256_table + (n)*4)
154
}
149
}
155
 
150
 
156
macro sha224256._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
151
macro sha2_224256._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
157
{
152
{
158
        sha224256._.recalculate_w n
153
        sha2_224256._.recalculate_w n
159
        mov     edi, [w + (n)*4]
154
        mov     edi, [w + (n)*4]
160
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n+16*rep_num)*4)
155
        sha2_224256._.round a, b, c, d, e, f, g, h, (sha2_256_table + (n+16*rep_num)*4)
161
}
156
}
162
 
157
 
Line 163... Line 158...
163
 
158
 
164
proc sha224.init _ctx
159
proc sha2_224.init uses ebx esi edi, _ctx
165
        mov     ebx, [_ctx]
160
        mov     ebx, [_ctx]
166
        lea     edi, [ebx + ctx_sha224256.hash]
161
        lea     edi, [ebx + ctx_sha2_224256.hash]
167
        mov     esi, sha224._.hash_init
162
        mov     esi, sha2_224._.hash_init
168
        mov     ecx, SHA224256_INIT_SIZE/4
163
        mov     ecx, SHA2_224256_INIT_SIZE/4
169
        rep     movsd
164
        rep movsd
170
        xor     eax, eax
165
        xor     eax, eax
171
        mov     [ebx + ctx_sha224256.index], eax
166
        mov     [ebx + ctx_sha2_224256.index], eax
172
        mov     [ebx + ctx_sha224256.msglen_0], eax
167
        mov     [ebx + ctx_sha2_224256.msglen_0], eax
173
        mov     [ebx + ctx_sha224256.msglen_1], eax
168
        mov     [ebx + ctx_sha2_224256.msglen_1], eax
174
        ret
169
        ret
Line 175... Line 170...
175
endp
170
endp
176
 
171
 
177
 
172
 
178
proc sha256.init _ctx
173
proc sha2_256.init uses ebx esi edi, _ctx
179
        mov     ebx, [_ctx]
174
        mov     ebx, [_ctx]
180
        lea     edi, [ebx + ctx_sha224256.hash]
175
        lea     edi, [ebx + ctx_sha2_224256.hash]
Line 217... Line 212...
217
        mov     eax, [edi + 0x18]
212
        mov     eax, [edi + 0x18]
218
        mov     [G], eax
213
        mov     [G], eax
219
        mov     eax, [edi + 0x1c]
214
        mov     eax, [edi + 0x1c]
220
        mov     [H], eax
215
        mov     [H], eax
Line 221... Line 216...
221
 
216
 
222
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  0
217
        sha2_224256._.round_1_16  A, B, C, D, E, F, G, H,  0
223
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  1
218
        sha2_224256._.round_1_16  H, A, B, C, D, E, F, G,  1
224
        sha224256._.round_1_16  G, H, A, B, C, D, E, F,  2
219
        sha2_224256._.round_1_16  G, H, A, B, C, D, E, F,  2
225
        sha224256._.round_1_16  F, G, H, A, B, C, D, E,  3
220
        sha2_224256._.round_1_16  F, G, H, A, B, C, D, E,  3
226
        sha224256._.round_1_16  E, F, G, H, A, B, C, D,  4
221
        sha2_224256._.round_1_16  E, F, G, H, A, B, C, D,  4
227
        sha224256._.round_1_16  D, E, F, G, H, A, B, C,  5
222
        sha2_224256._.round_1_16  D, E, F, G, H, A, B, C,  5
228
        sha224256._.round_1_16  C, D, E, F, G, H, A, B,  6
223
        sha2_224256._.round_1_16  C, D, E, F, G, H, A, B,  6
229
        sha224256._.round_1_16  B, C, D, E, F, G, H, A,  7
224
        sha2_224256._.round_1_16  B, C, D, E, F, G, H, A,  7
230
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  8
225
        sha2_224256._.round_1_16  A, B, C, D, E, F, G, H,  8
231
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  9
226
        sha2_224256._.round_1_16  H, A, B, C, D, E, F, G,  9
232
        sha224256._.round_1_16  G, H, A, B, C, D, E, F, 10
227
        sha2_224256._.round_1_16  G, H, A, B, C, D, E, F, 10
233
        sha224256._.round_1_16  F, G, H, A, B, C, D, E, 11
228
        sha2_224256._.round_1_16  F, G, H, A, B, C, D, E, 11
234
        sha224256._.round_1_16  E, F, G, H, A, B, C, D, 12
229
        sha2_224256._.round_1_16  E, F, G, H, A, B, C, D, 12
235
        sha224256._.round_1_16  D, E, F, G, H, A, B, C, 13
230
        sha2_224256._.round_1_16  D, E, F, G, H, A, B, C, 13
236
        sha224256._.round_1_16  C, D, E, F, G, H, A, B, 14
231
        sha2_224256._.round_1_16  C, D, E, F, G, H, A, B, 14
Line 237... Line 232...
237
        sha224256._.round_1_16  B, C, D, E, F, G, H, A, 15
232
        sha2_224256._.round_1_16  B, C, D, E, F, G, H, A, 15
238
 
233
 
239
repeat 3
234
repeat 3
240
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  0, %
235
        sha2_224256._.round_17_64 A, B, C, D, E, F, G, H,  0, %
241
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  1, %
236
        sha2_224256._.round_17_64 H, A, B, C, D, E, F, G,  1, %
242
        sha224256._.round_17_64 G, H, A, B, C, D, E, F,  2, %
237
        sha2_224256._.round_17_64 G, H, A, B, C, D, E, F,  2, %
243
        sha224256._.round_17_64 F, G, H, A, B, C, D, E,  3, %
238
        sha2_224256._.round_17_64 F, G, H, A, B, C, D, E,  3, %
244
        sha224256._.round_17_64 E, F, G, H, A, B, C, D,  4, %
239
        sha2_224256._.round_17_64 E, F, G, H, A, B, C, D,  4, %
245
        sha224256._.round_17_64 D, E, F, G, H, A, B, C,  5, %
240
        sha2_224256._.round_17_64 D, E, F, G, H, A, B, C,  5, %
246
        sha224256._.round_17_64 C, D, E, F, G, H, A, B,  6, %
241
        sha2_224256._.round_17_64 C, D, E, F, G, H, A, B,  6, %
247
        sha224256._.round_17_64 B, C, D, E, F, G, H, A,  7, %
242
        sha2_224256._.round_17_64 B, C, D, E, F, G, H, A,  7, %
248
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  8, %
243
        sha2_224256._.round_17_64 A, B, C, D, E, F, G, H,  8, %
249
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  9, %
244
        sha2_224256._.round_17_64 H, A, B, C, D, E, F, G,  9, %
250
        sha224256._.round_17_64 G, H, A, B, C, D, E, F, 10, %
245
        sha2_224256._.round_17_64 G, H, A, B, C, D, E, F, 10, %
251
        sha224256._.round_17_64 F, G, H, A, B, C, D, E, 11, %
246
        sha2_224256._.round_17_64 F, G, H, A, B, C, D, E, 11, %
252
        sha224256._.round_17_64 E, F, G, H, A, B, C, D, 12, %
247
        sha2_224256._.round_17_64 E, F, G, H, A, B, C, D, 12, %
253
        sha224256._.round_17_64 D, E, F, G, H, A, B, C, 13, %
248
        sha2_224256._.round_17_64 D, E, F, G, H, A, B, C, 13, %
254
        sha224256._.round_17_64 C, D, E, F, G, H, A, B, 14, %
249
        sha2_224256._.round_17_64 C, D, E, F, G, H, A, B, 14, %
Line 255... Line 250...
255
        sha224256._.round_17_64 B, C, D, E, F, G, H, A, 15, %
250
        sha2_224256._.round_17_64 B, C, D, E, F, G, H, A, 15, %
256
end repeat
251
end repeat
257
 
252
 
Line 275... Line 270...
275
 
270
 
276
        ret
271
        ret
Line 277... Line 272...
277
endp
272
endp
278
 
273
 
279
 
274
 
280
sha224.update = sha224256.update
275
sha2_224.update = sha2_224256.update
281
sha256.update = sha224256.update
276
sha2_256.update = sha2_224256.update
282
proc sha224256.update _ctx, _msg, _size
277
proc sha2_224256.update uses ebx esi edi, _ctx, _msg, _size
283
        mov     ebx, [_ctx]
278
        mov     ebx, [_ctx]
Line 284... Line 279...
284
        mov     ecx, [_size]
279
        mov     ecx, [_size]
285
        add     [ebx + ctx_sha224256.msglen_0], ecx
280
        add     [ebx + ctx_sha2_224256.msglen_0], ecx
286
        adc     [ebx + ctx_sha224256.msglen_1], 0
281
        adc     [ebx + ctx_sha2_224256.msglen_1], 0
287
 
282
 
288
  .next_block:
283
.next_block:
289
        mov     ebx, [_ctx]
284
        mov     ebx, [_ctx]
290
        mov     esi, [_msg]
285
        mov     esi, [_msg]
291
        mov     eax, [ebx + ctx_sha224256.index]
286
        mov     eax, [ebx + ctx_sha2_224256.index]
292
        and     eax, SHA224256_BLOCK_SIZE-1
287
        and     eax, SHA2_224256_BLOCK_SIZE-1
293
        jnz     .copy_to_buf
288
        jnz     .copy_to_buf
294
        test    esi, SHA224256_ALIGN_MASK
289
        test    esi, SHA2_224256_ALIGN_MASK
295
        jnz     .copy_to_buf
290
        jnz     .copy_to_buf
296
  .no_copy:
291
.no_copy:
297
        ; data is aligned, hash it in place without copying
292
        ; data is aligned, hash it in place without copying
298
        mov     ebx, [_ctx]
293
        mov     ebx, [_ctx]
299
        cmp     [_size], SHA224256_BLOCK_SIZE
294
        cmp     [_size], SHA2_224256_BLOCK_SIZE
300
        jb      .copy_quit
295
        jb      .copy_quit
301
        lea     eax, [ebx + ctx_sha224256.hash]
296
        lea     eax, [ebx + ctx_sha2_224256.hash]
Line 302... Line 297...
302
        stdcall sha224256._.block, eax
297
        stdcall sha2_224256._.block, eax
303
        sub     [_size], SHA224256_BLOCK_SIZE
298
        sub     [_size], SHA2_224256_BLOCK_SIZE
304
        add     esi, SHA224256_BLOCK_SIZE           ; FIXME
299
        add     esi, SHA2_224256_BLOCK_SIZE           ; FIXME
305
        jmp     .no_copy
300
        jmp     .no_copy
306
 
301
 
307
  .copy_to_buf:
302
.copy_to_buf:
308
        lea     edi, [ebx + ctx_sha224256.block]
303
        lea     edi, [ebx + ctx_sha2_224256.block]
309
        add     edi, eax
304
        add     edi, eax
310
        mov     ecx, SHA224256_BLOCK_SIZE
305
        mov     ecx, SHA2_224256_BLOCK_SIZE
311
        sub     ecx, eax
306
        sub     ecx, eax
312
        cmp     [_size], ecx
307
        cmp     [_size], ecx
313
        jb      .copy_quit
308
        jb      .copy_quit
314
        sub     [_size], ecx
309
        sub     [_size], ecx
315
        add     [_msg], ecx
310
        add     [_msg], ecx
316
        add     [ebx + ctx_sha224256.index], ecx
311
        add     [ebx + ctx_sha2_224256.index], ecx
Line 317... Line 312...
317
        rep     movsb
312
        rep movsb
318
        lea     eax, [ebx + ctx_sha224256.hash]
313
        lea     eax, [ebx + ctx_sha2_224256.hash]
319
        lea     esi, [ebx + ctx_sha224256.block]
314
        lea     esi, [ebx + ctx_sha2_224256.block]
320
        stdcall sha224256._.block, eax
315
        stdcall sha2_224256._.block, eax
321
        jmp     .next_block
316
        jmp     .next_block
322
 
317
 
323
  .copy_quit:
318
.copy_quit:
324
        mov     ebx, [_ctx]
319
        mov     ebx, [_ctx]
325
        lea     edi, [ebx + ctx_sha224256.block]
320
        lea     edi, [ebx + ctx_sha2_224256.block]
326
        mov     eax, [ebx + ctx_sha224256.index]
321
        mov     eax, [ebx + ctx_sha2_224256.index]
Line 327... Line 322...
327
        and     eax, SHA224256_BLOCK_SIZE-1
322
        and     eax, SHA2_224256_BLOCK_SIZE-1
328
        add     edi, eax
323
        add     edi, eax
Line 329... Line 324...
329
        mov     ecx, [_size]
324
        mov     ecx, [_size]
330
        add     [ebx + ctx_sha224256.index], ecx
325
        add     [ebx + ctx_sha2_224256.index], ecx
331
        rep     movsb
326
        rep movsb
332
  .quit:
327
.quit:
333
 
328
 
334
        ret
329
        ret
335
endp
330
endp
336
 
331
 
337
 
332
 
338
sha224.final = sha224256.final
333
sha2_224.finish = sha2_224256.finish
339
sha256.final = sha224256.final
334
sha2_256.finish = sha2_224256.finish
340
proc sha224256.final _ctx
335
proc sha2_224256.finish uses ebx esi edi, _ctx
341
        mov     ebx, [_ctx]
336
        mov     ebx, [_ctx]
342
        lea     edi, [ebx + ctx_sha224256.block]
337
        lea     edi, [ebx + ctx_sha2_224256.block]
Line 343... Line 338...
343
        mov     ecx, [ebx + ctx_sha224256.msglen_0]
338
        mov     ecx, [ebx + ctx_sha2_224256.msglen_0]
344
        and     ecx, SHA224256_BLOCK_SIZE-1
339
        and     ecx, SHA2_224256_BLOCK_SIZE-1
345
        add     edi, ecx
340
        add     edi, ecx
346
        mov     byte[edi], 0x80
341
        mov     byte[edi], 0x80
347
        inc     edi
342
        inc     edi
348
        neg     ecx
343
        neg     ecx
349
        add     ecx, SHA224256_BLOCK_SIZE
344
        add     ecx, SHA2_224256_BLOCK_SIZE
350
        cmp     ecx, 8
345
        cmp     ecx, 8
351
        ja      .last
346
        ja      .last
352
 
347
 
353
        dec     ecx
348
        dec     ecx
354
        xor     eax, eax
349
        xor     eax, eax
355
        rep     stosb
350
        rep stosb
356
        lea     esi, [ebx + ctx_sha224256.block]
351
        lea     esi, [ebx + ctx_sha2_224256.block]
357
        lea     eax, [ebx + ctx_sha224256.hash]
352
        lea     eax, [ebx + ctx_sha2_224256.hash]
358
        stdcall sha224256._.block, eax
353
        stdcall sha2_224256._.block, eax
359
        mov     ebx, [_ctx]
354
        mov     ebx, [_ctx]
360
        lea     edi, [ebx + ctx_sha224256.block]
355
        lea     edi, [ebx + ctx_sha2_224256.block]
361
        mov     ecx, SHA224256_BLOCK_SIZE+1
356
        mov     ecx, SHA2_224256_BLOCK_SIZE+1
362
  .last:
357
.last:
363
        dec     ecx
358
        dec     ecx
364
        sub     ecx, 8
359
        sub     ecx, 8
365
        xor     eax, eax
360
        xor     eax, eax
366
        rep     stosb
361
        rep stosb
367
        mov     eax, [ebx + ctx_sha224256.msglen_0]
362
        mov     eax, [ebx + ctx_sha2_224256.msglen_0]
Line 368... Line 363...
368
        mov     edx, [ebx + ctx_sha224256.msglen_1]
363
        mov     edx, [ebx + ctx_sha2_224256.msglen_1]
369
        shld    edx, eax, 3
364
        shld    edx, eax, 3
370
        shl     eax, 3
365
        shl     eax, 3
Line 371... Line 366...
371
        bswap   eax
366
        bswap   eax
372
        bswap   edx
367
        bswap   edx
Line 373... Line 368...
373
        mov     dword[edi], edx
368
        mov     dword[edi], edx
374
        mov     dword[edi+4], eax
369
        mov     dword[edi+4], eax
375
        lea     esi, [ebx + ctx_sha224256.block]
370
        lea     esi, [ebx + ctx_sha2_224256.block]
376
        lea     eax, [ebx + ctx_sha224256.hash]
371
        lea     eax, [ebx + ctx_sha2_224256.hash]
377
        stdcall sha224256._.block, eax
372
        stdcall sha2_224256._.block, eax
378
 
373
 
Line 396... Line 391...
396
        jnz     @b
391
        jnz     @b
397
        ret
392
        ret
398
endp
393
endp
Line 399... Line 394...
399
 
394
 
400
 
395
 
401
proc sha224.oneshot _ctx, _data, _len
396
proc sha2_224.oneshot _ctx, _data, _len
402
	stdcall	sha224.init, [_ctx]
397
        stdcall sha2_224.init, [_ctx]
403
	stdcall	sha224.update, [_ctx], [_data], [_len]
398
        stdcall sha2_224.update, [_ctx], [_data], [_len]
404
	stdcall	sha224.final, [_ctx]
399
        stdcall sha2_224.finish, [_ctx]
Line 405... Line 400...
405
	ret
400
        ret
406
endp
401
endp
407
 
402
 
408
 
403
 
409
proc sha256.oneshot _ctx, _data, _len
404
proc sha2_256.oneshot _ctx, _data, _len
410
	stdcall	sha256.init, [_ctx]
405
        stdcall sha2_256.init, [_ctx]
Line 411... Line 406...
411
	stdcall	sha256.update, [_ctx], [_data], [_len]
406
        stdcall sha2_256.update, [_ctx], [_data], [_len]
412
	stdcall	sha256.final, [_ctx]
407
        stdcall sha2_256.finish, [_ctx]
413
	ret
408
        ret
414
endp
409
endp
Line 415... Line 410...
415
 
410
 
416
 
411
 
Line 417... Line 412...
417
iglobal
412
iglobal
418
align SHA224256_ALIGN
413
align SHA2_224256_ALIGN
419
sha224._.hash_init      dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,\
414
sha2_224._.hash_init    dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,\
420
                           0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
415
                           0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
421
 
416
 
422
sha256._.hash_init      dd 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\
417
sha2_256._.hash_init    dd 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\