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
SHA384512_BLOCK_SIZE = 128
19
SHA2_384512_BLOCK_SIZE = 128
20
SHA384_BLOCK_SIZE    = SHA384512_BLOCK_SIZE
20
SHA2_384_BLOCK_SIZE    = SHA2_384512_BLOCK_SIZE
21
SHA512_BLOCK_SIZE    = SHA384512_BLOCK_SIZE
-
 
22
SHA384_HASH_SIZE     = 48
-
 
23
SHA512_HASH_SIZE     = 64
21
SHA2_512_BLOCK_SIZE    = SHA2_384512_BLOCK_SIZE
24
 
22
 
25
SHA384512_INIT_SIZE  = 64
23
SHA2_384512_INIT_SIZE  = 64
26
SHA384512_ALIGN      = 16
24
SHA2_384512_ALIGN      = 16
27
SHA384512_ALIGN_MASK = SHA384512_ALIGN - 1
25
SHA2_384512_ALIGN_MASK = SHA2_384512_ALIGN - 1
28
 
26
 
29
struct ctx_sha384512
27
struct ctx_sha2_384512
30
        hash            rb SHA384512_INIT_SIZE
28
        hash            rb SHA2_384512_INIT_SIZE
31
        block           rb SHA384512_BLOCK_SIZE
29
        block           rb SHA2_384512_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
35
        msglen_2        rd 1
33
        msglen_2        rd 1
Line 46... Line 44...
46
        G               rq 1
44
        G               rq 1
47
        H               rq 1
45
        H               rq 1
48
        temp            rq 1
46
        temp            rq 1
49
ends
47
ends
Line 50... Line -...
50
 
-
 
51
if defined sizeof.crash_ctx
48
 
52
  assert sizeof.crash_ctx >= sizeof.ctx_sha384512
-
 
Line 53... Line 49...
53
end if
49
assert sizeof.ctx_sha2_384512 <= LIBCRASH_CTX_LEN
54
 
50
 
55
macro sha384512._.chn x, y, z
51
macro sha2_384512._.chn x, y, z
56
{
52
{
57
        movq    mm0, [y]
53
        movq    mm0, [y]
58
        pxor    mm0, [z]
54
        pxor    mm0, [z]
59
        pand    mm0, [x]
55
        pand    mm0, [x]
Line 60... Line 56...
60
        pxor    mm0, [z]
56
        pxor    mm0, [z]
61
}
57
}
62
 
58
 
63
macro sha384512._.maj x, y, z
59
macro sha2_384512._.maj x, y, z
64
{
60
{
65
        movq    mm0, [x]
61
        movq    mm0, [x]
66
        pxor    mm0, [y]
62
        pxor    mm0, [y]
67
        pand    mm0, [z]
63
        pand    mm0, [z]
68
        movq    mm2, [x]
64
        movq    mm2, [x]
Line 69... Line 65...
69
        pand    mm2, [y]
65
        pand    mm2, [y]
70
        pxor    mm0, mm2
66
        pxor    mm0, mm2
71
}
67
}
72
 
68
 
73
macro sha384512._.Sigma0 x
69
macro sha2_384512._.Sigma0 x
74
{
70
{
Line 89... Line 85...
89
        psllq   mm7, 25
85
        psllq   mm7, 25
90
        por     mm2, mm7
86
        por     mm2, mm7
91
        pxor    mm0, mm2
87
        pxor    mm0, mm2
92
}
88
}
Line 93... Line 89...
93
 
89
 
94
macro sha384512._.Sigma1 x
90
macro sha2_384512._.Sigma1 x
95
{
91
{
96
        movq    mm0, x
92
        movq    mm0, x
97
        movq    mm2, mm0
93
        movq    mm2, mm0
98
        movq    mm7, mm2
94
        movq    mm7, mm2
Line 110... Line 106...
110
        psllq   mm7, 23
106
        psllq   mm7, 23
111
        por     mm2, mm7
107
        por     mm2, mm7
112
        pxor    mm0, mm2
108
        pxor    mm0, mm2
113
}
109
}
Line 114... Line 110...
114
 
110
 
115
macro sha384512._.sigma0 x
111
macro sha2_384512._.sigma0 x
116
{
112
{
117
        movq    mm0, x
113
        movq    mm0, x
118
        movq    mm2, mm0
114
        movq    mm2, mm0
119
        movq    mm7, mm2
115
        movq    mm7, mm2
Line 128... Line 124...
128
        movq    mm2, x
124
        movq    mm2, x
129
        psrlq   mm2, 7
125
        psrlq   mm2, 7
130
        pxor    mm0, mm2
126
        pxor    mm0, mm2
131
}
127
}
Line 132... Line 128...
132
 
128
 
133
macro sha384512._.sigma1 x
129
macro sha2_384512._.sigma1 x
134
{
130
{
135
        movq    mm0, x
131
        movq    mm0, x
136
        movq    mm2, mm0
132
        movq    mm2, mm0
137
        movq    mm7, mm2
133
        movq    mm7, mm2
Line 146... Line 142...
146
        movq    mm2, x
142
        movq    mm2, x
147
        psrlq   mm2, 6
143
        psrlq   mm2, 6
148
        pxor    mm0, mm2
144
        pxor    mm0, mm2
149
}
145
}
Line 150... Line 146...
150
 
146
 
151
macro sha384512._.recalculate_w n
147
macro sha2_384512._.recalculate_w n
152
{
148
{
153
        movq    mm3, [w + ((n-2) and 15)*8]
149
        movq    mm3, [w + ((n-2) and 15)*8]
154
        sha384512._.sigma1  mm3
150
        sha2_384512._.sigma1  mm3
155
        paddq   mm0, [w + ((n-7) and 15)*8]
151
        paddq   mm0, [w + ((n-7) and 15)*8]
156
        movq    mm6, mm0
152
        movq    mm6, mm0
157
        movq    mm3, [w + ((n-15) and 15)*8]
153
        movq    mm3, [w + ((n-15) and 15)*8]
158
        sha384512._.sigma0  mm3
154
        sha2_384512._.sigma0  mm3
159
        movq    mm2, mm6
155
        movq    mm2, mm6
160
        paddq   mm0, mm2
156
        paddq   mm0, mm2
161
        movq    mm7, [w + (n)*8]
157
        movq    mm7, [w + (n)*8]
162
        paddq   mm7, mm0
158
        paddq   mm7, mm0
163
        movq    [w + (n)*8], mm7
159
        movq    [w + (n)*8], mm7
Line 164... Line 160...
164
}
160
}
165
 
161
 
166
macro sha384512._.round a, b, c, d, e, f, g, h, k
162
macro sha2_384512._.round a, b, c, d, e, f, g, h, k
167
{
163
{
168
        movq    mm1, [h]
164
        movq    mm1, [h]
169
        movq    mm3, [e]
165
        movq    mm3, [e]
170
        sha384512._.Sigma1  mm3
166
        sha2_384512._.Sigma1  mm3
171
        paddq   mm1, mm0
167
        paddq   mm1, mm0
172
        sha384512._.chn     e, f, g
168
        sha2_384512._.chn     e, f, g
173
        paddq   mm1, mm0
169
        paddq   mm1, mm0
174
        paddq   mm1, [k]
170
        paddq   mm1, [k]
175
        paddq   mm1, mm5
171
        paddq   mm1, mm5
176
        movq    mm7, [d]
172
        movq    mm7, [d]
177
        paddq   mm7, mm1
173
        paddq   mm7, mm1
178
        movq    [d], mm7
174
        movq    [d], mm7
179
        movq    mm3, [a]
175
        movq    mm3, [a]
180
        sha384512._.Sigma0  mm3
176
        sha2_384512._.Sigma0  mm3
181
        paddq   mm1, mm0
177
        paddq   mm1, mm0
182
        sha384512._.maj     a, b, c
178
        sha2_384512._.maj     a, b, c
183
        paddq   mm0, mm1
179
        paddq   mm0, mm1
Line 184... Line 180...
184
        movq    [h], mm0
180
        movq    [h], mm0
185
}
181
}
Line 186... Line 182...
186
 
182
 
187
 
183
 
188
macro sha384512._.round_1_16 a, b, c, d, e, f, g, h, n
184
macro sha2_384512._.round_1_16 a, b, c, d, e, f, g, h, n
Line 199... Line 195...
199
        pop     eax
195
        pop     eax
200
        mov     dword[temp + 4], eax
196
        mov     dword[temp + 4], eax
201
        movq    mm0, [temp]
197
        movq    mm0, [temp]
202
        movq    [w + (n)*8], mm0
198
        movq    [w + (n)*8], mm0
203
        movq    mm5, mm0
199
        movq    mm5, mm0
204
        sha384512._.round a, b, c, d, e, f, g, h, (sha384512._.table + (n)*8)
200
        sha2_384512._.round a, b, c, d, e, f, g, h, (sha2_384512._.table + (n)*8)
205
}
201
}
Line 206... Line 202...
206
 
202
 
207
macro sha384512._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
203
macro sha2_384512._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
208
{
204
{
209
        sha384512._.recalculate_w n
205
        sha2_384512._.recalculate_w n
210
        movq    mm5, [w + (n)*8]
206
        movq    mm5, [w + (n)*8]
211
        sha384512._.round a, b, c, d, e, f, g, h, (sha384512._.table + (n+16*rep_num)*8)
207
        sha2_384512._.round a, b, c, d, e, f, g, h, (sha2_384512._.table + (n+16*rep_num)*8)
Line 212... Line 208...
212
}
208
}
213
 
209
 
214
 
210
 
215
proc sha384.init _ctx
211
proc sha2_384.init uses ebx esi edi, _ctx
216
        mov     ebx, [_ctx]
212
        mov     ebx, [_ctx]
217
        lea     edi, [ebx + ctx_sha384512.hash]
213
        lea     edi, [ebx + ctx_sha2_384512.hash]
218
        mov     esi, sha384._.hash_init
214
        mov     esi, sha2_384._.hash_init
219
        mov     ecx, SHA384512_INIT_SIZE/4
215
        mov     ecx, SHA2_384512_INIT_SIZE/4
220
        rep     movsd
216
        rep movsd
221
        xor     eax, eax
217
        xor     eax, eax
222
        mov     [ebx + ctx_sha384512.index], eax
218
        mov     [ebx + ctx_sha2_384512.index], eax
223
        mov     [ebx + ctx_sha384512.msglen_0], eax
219
        mov     [ebx + ctx_sha2_384512.msglen_0], eax
224
        mov     [ebx + ctx_sha384512.msglen_1], eax
220
        mov     [ebx + ctx_sha2_384512.msglen_1], eax
225
        mov     [ebx + ctx_sha384512.msglen_2], eax
221
        mov     [ebx + ctx_sha2_384512.msglen_2], eax
Line 226... Line 222...
226
        mov     [ebx + ctx_sha384512.msglen_3], eax
222
        mov     [ebx + ctx_sha2_384512.msglen_3], eax
227
        ret
223
        ret
228
endp
224
endp
229
 
225
 
230
 
226
 
231
proc sha512.init _ctx
227
proc sha2_512.init uses ebx esi edi, _ctx
232
        mov     ebx, [_ctx]
228
        mov     ebx, [_ctx]
233
        lea     edi, [ebx + ctx_sha384512.hash]
229
        lea     edi, [ebx + ctx_sha2_384512.hash]
234
        mov     esi, sha512._.hash_init
230
        mov     esi, sha2_512._.hash_init
235
        mov     ecx, SHA384512_INIT_SIZE/4
231
        mov     ecx, SHA2_384512_INIT_SIZE/4
236
        rep     movsd
232
        rep movsd
237
        xor     eax, eax
233
        xor     eax, eax
238
        mov     [ebx + ctx_sha384512.index], eax
234
        mov     [ebx + ctx_sha2_384512.index], eax
239
        mov     [ebx + ctx_sha384512.msglen_0], eax
235
        mov     [ebx + ctx_sha2_384512.msglen_0], eax
Line 240... Line 236...
240
        mov     [ebx + ctx_sha384512.msglen_1], eax
236
        mov     [ebx + ctx_sha2_384512.msglen_1], eax
241
        mov     [ebx + ctx_sha384512.msglen_2], eax
237
        mov     [ebx + ctx_sha2_384512.msglen_2], eax
242
        mov     [ebx + ctx_sha384512.msglen_3], eax
238
        mov     [ebx + ctx_sha2_384512.msglen_3], eax
243
        ret
239
        ret
244
endp
240
endp
245
 
241
 
Line 255... Line 251...
255
;        F       rq 1
251
;        F       rq 1
256
;        G       rq 1
252
;        G       rq 1
257
;        H       rq 1
253
;        H       rq 1
258
;        temp    rq 1
254
;        temp    rq 1
259
;endl
255
;endl
260
w equ ebx + ctx_sha384512.w
256
w equ ebx + ctx_sha2_384512.w
261
A equ ebx + ctx_sha384512.A
257
A equ ebx + ctx_sha2_384512.A
262
B equ ebx + ctx_sha384512.B
258
B equ ebx + ctx_sha2_384512.B
263
C equ ebx + ctx_sha384512.C
259
C equ ebx + ctx_sha2_384512.C
264
D equ ebx + ctx_sha384512.D
260
D equ ebx + ctx_sha2_384512.D
265
E equ ebx + ctx_sha384512.E
261
E equ ebx + ctx_sha2_384512.E
266
F equ ebx + ctx_sha384512.F
262
F equ ebx + ctx_sha2_384512.F
267
G equ ebx + ctx_sha384512.G
263
G equ ebx + ctx_sha2_384512.G
268
H equ ebx + ctx_sha384512.H
264
H equ ebx + ctx_sha2_384512.H
269
temp equ ebx + ctx_sha384512.temp
265
temp equ ebx + ctx_sha2_384512.temp
Line 270... Line 266...
270
 
266
 
271
        mov     edi, [_hash]
267
        mov     edi, [_hash]
272
        movq    mm0, [edi + 0x00]
268
        movq    mm0, [edi + 0x00]
273
        movq    [A], mm0
269
        movq    [A], mm0
Line 285... Line 281...
285
        movq    [G], mm0
281
        movq    [G], mm0
286
        movq    mm0, [edi + 0x38]
282
        movq    mm0, [edi + 0x38]
287
        movq    [H], mm0
283
        movq    [H], mm0
Line 288... Line 284...
288
 
284
 
289
 
285
 
290
        sha384512._.round_1_16  A, B, C, D, E, F, G, H,  0
286
        sha2_384512._.round_1_16  A, B, C, D, E, F, G, H,  0
291
        sha384512._.round_1_16  H, A, B, C, D, E, F, G,  1
287
        sha2_384512._.round_1_16  H, A, B, C, D, E, F, G,  1
292
        sha384512._.round_1_16  G, H, A, B, C, D, E, F,  2
288
        sha2_384512._.round_1_16  G, H, A, B, C, D, E, F,  2
293
        sha384512._.round_1_16  F, G, H, A, B, C, D, E,  3
289
        sha2_384512._.round_1_16  F, G, H, A, B, C, D, E,  3
294
        sha384512._.round_1_16  E, F, G, H, A, B, C, D,  4
290
        sha2_384512._.round_1_16  E, F, G, H, A, B, C, D,  4
295
        sha384512._.round_1_16  D, E, F, G, H, A, B, C,  5
291
        sha2_384512._.round_1_16  D, E, F, G, H, A, B, C,  5
296
        sha384512._.round_1_16  C, D, E, F, G, H, A, B,  6
292
        sha2_384512._.round_1_16  C, D, E, F, G, H, A, B,  6
297
        sha384512._.round_1_16  B, C, D, E, F, G, H, A,  7
293
        sha2_384512._.round_1_16  B, C, D, E, F, G, H, A,  7
298
        sha384512._.round_1_16  A, B, C, D, E, F, G, H,  8
294
        sha2_384512._.round_1_16  A, B, C, D, E, F, G, H,  8
299
        sha384512._.round_1_16  H, A, B, C, D, E, F, G,  9
295
        sha2_384512._.round_1_16  H, A, B, C, D, E, F, G,  9
300
        sha384512._.round_1_16  G, H, A, B, C, D, E, F, 10
296
        sha2_384512._.round_1_16  G, H, A, B, C, D, E, F, 10
301
        sha384512._.round_1_16  F, G, H, A, B, C, D, E, 11
297
        sha2_384512._.round_1_16  F, G, H, A, B, C, D, E, 11
302
        sha384512._.round_1_16  E, F, G, H, A, B, C, D, 12
298
        sha2_384512._.round_1_16  E, F, G, H, A, B, C, D, 12
303
        sha384512._.round_1_16  D, E, F, G, H, A, B, C, 13
299
        sha2_384512._.round_1_16  D, E, F, G, H, A, B, C, 13
Line 304... Line 300...
304
        sha384512._.round_1_16  C, D, E, F, G, H, A, B, 14
300
        sha2_384512._.round_1_16  C, D, E, F, G, H, A, B, 14
305
        sha384512._.round_1_16  B, C, D, E, F, G, H, A, 15
301
        sha2_384512._.round_1_16  B, C, D, E, F, G, H, A, 15
306
 
302
 
307
repeat 4
303
repeat 4
308
        sha384512._.round_17_64 A, B, C, D, E, F, G, H,  0, %
304
        sha2_384512._.round_17_64 A, B, C, D, E, F, G, H,  0, %
309
        sha384512._.round_17_64 H, A, B, C, D, E, F, G,  1, %
305
        sha2_384512._.round_17_64 H, A, B, C, D, E, F, G,  1, %
310
        sha384512._.round_17_64 G, H, A, B, C, D, E, F,  2, %
306
        sha2_384512._.round_17_64 G, H, A, B, C, D, E, F,  2, %
311
        sha384512._.round_17_64 F, G, H, A, B, C, D, E,  3, %
307
        sha2_384512._.round_17_64 F, G, H, A, B, C, D, E,  3, %
312
        sha384512._.round_17_64 E, F, G, H, A, B, C, D,  4, %
308
        sha2_384512._.round_17_64 E, F, G, H, A, B, C, D,  4, %
313
        sha384512._.round_17_64 D, E, F, G, H, A, B, C,  5, %
309
        sha2_384512._.round_17_64 D, E, F, G, H, A, B, C,  5, %
314
        sha384512._.round_17_64 C, D, E, F, G, H, A, B,  6, %
310
        sha2_384512._.round_17_64 C, D, E, F, G, H, A, B,  6, %
315
        sha384512._.round_17_64 B, C, D, E, F, G, H, A,  7, %
311
        sha2_384512._.round_17_64 B, C, D, E, F, G, H, A,  7, %
316
        sha384512._.round_17_64 A, B, C, D, E, F, G, H,  8, %
312
        sha2_384512._.round_17_64 A, B, C, D, E, F, G, H,  8, %
317
        sha384512._.round_17_64 H, A, B, C, D, E, F, G,  9, %
313
        sha2_384512._.round_17_64 H, A, B, C, D, E, F, G,  9, %
318
        sha384512._.round_17_64 G, H, A, B, C, D, E, F, 10, %
314
        sha2_384512._.round_17_64 G, H, A, B, C, D, E, F, 10, %
319
        sha384512._.round_17_64 F, G, H, A, B, C, D, E, 11, %
315
        sha2_384512._.round_17_64 F, G, H, A, B, C, D, E, 11, %
320
        sha384512._.round_17_64 E, F, G, H, A, B, C, D, 12, %
316
        sha2_384512._.round_17_64 E, F, G, H, A, B, C, D, 12, %
321
        sha384512._.round_17_64 D, E, F, G, H, A, B, C, 13, %
317
        sha2_384512._.round_17_64 D, E, F, G, H, A, B, C, 13, %
Line 322... Line 318...
322
        sha384512._.round_17_64 C, D, E, F, G, H, A, B, 14, %
318
        sha2_384512._.round_17_64 C, D, E, F, G, H, A, B, 14, %
323
        sha384512._.round_17_64 B, C, D, E, F, G, H, A, 15, %
319
        sha2_384512._.round_17_64 B, C, D, E, F, G, H, A, 15, %
Line 353... Line 349...
353
        ret
349
        ret
354
restore w,A,B,C,D,E,F,G,H,temp
350
restore w,A,B,C,D,E,F,G,H,temp
355
endp
351
endp
Line 356... Line 352...
356
 
352
 
357
 
353
 
358
sha384.update = sha384512.update
354
sha2_384.update = sha2_384512.update
359
sha512.update = sha384512.update
355
sha2_512.update = sha2_384512.update
360
proc sha384512.update _ctx, _msg, _size
356
proc sha2_384512.update uses ebx esi edi, _ctx, _msg, _size
361
        mov     ebx, [_ctx]
357
        mov     ebx, [_ctx]
362
        mov     ecx, [_size]
358
        mov     ecx, [_size]
363
        add     [ebx + ctx_sha384512.msglen_0], ecx
359
        add     [ebx + ctx_sha2_384512.msglen_0], ecx
364
        adc     [ebx + ctx_sha384512.msglen_1], 0
360
        adc     [ebx + ctx_sha2_384512.msglen_1], 0
Line 365... Line 361...
365
        adc     [ebx + ctx_sha384512.msglen_2], 0
361
        adc     [ebx + ctx_sha2_384512.msglen_2], 0
366
        adc     [ebx + ctx_sha384512.msglen_3], 0
362
        adc     [ebx + ctx_sha2_384512.msglen_3], 0
367
 
363
 
368
  .next_block:
364
.next_block:
369
        mov     ebx, [_ctx]
365
        mov     ebx, [_ctx]
370
        mov     esi, [_msg]
366
        mov     esi, [_msg]
371
        mov     eax, [ebx + ctx_sha384512.index]
367
        mov     eax, [ebx + ctx_sha2_384512.index]
372
        and     eax, SHA384512_BLOCK_SIZE-1
368
        and     eax, SHA2_384512_BLOCK_SIZE-1
373
        jnz     .copy_to_buf
369
        jnz     .copy_to_buf
374
        test    esi, SHA384512_ALIGN_MASK
370
        test    esi, SHA2_384512_ALIGN_MASK
375
        jnz     .copy_to_buf
371
        jnz     .copy_to_buf
376
  .no_copy:
372
.no_copy:
377
        ; data is aligned, hash it in place without copying
373
        ; data is aligned, hash it in place without copying
378
        mov     ebx, [_ctx]
374
        mov     ebx, [_ctx]
379
        cmp     [_size], SHA384512_BLOCK_SIZE
375
        cmp     [_size], SHA2_384512_BLOCK_SIZE
380
        jb      .copy_quit
376
        jb      .copy_quit
381
        lea     eax, [ebx + ctx_sha384512.hash]
377
        lea     eax, [ebx + ctx_sha2_384512.hash]
382
        stdcall sha384512._.block, eax
378
        stdcall sha2_384512._.block, eax
Line 383... Line 379...
383
        sub     [_size], SHA384512_BLOCK_SIZE
379
        sub     [_size], SHA2_384512_BLOCK_SIZE
384
        add     esi, SHA384512_BLOCK_SIZE           ; FIXME
380
        add     esi, SHA2_384512_BLOCK_SIZE           ; FIXME
385
        jmp     .no_copy
381
        jmp     .no_copy
386
 
382
 
387
  .copy_to_buf:
383
.copy_to_buf:
388
        lea     edi, [ebx + ctx_sha384512.block]
384
        lea     edi, [ebx + ctx_sha2_384512.block]
389
        add     edi, eax
385
        add     edi, eax
390
        mov     ecx, SHA384512_BLOCK_SIZE
386
        mov     ecx, SHA2_384512_BLOCK_SIZE
391
        sub     ecx, eax
387
        sub     ecx, eax
392
        cmp     [_size], ecx
388
        cmp     [_size], ecx
393
        jb      .copy_quit
389
        jb      .copy_quit
394
        sub     [_size], ecx
390
        sub     [_size], ecx
395
        add     [_msg], ecx
391
        add     [_msg], ecx
396
        add     [ebx + ctx_sha384512.index], ecx
392
        add     [ebx + ctx_sha2_384512.index], ecx
397
        rep     movsb
393
        rep movsb
Line 398... Line 394...
398
        lea     eax, [ebx + ctx_sha384512.hash]
394
        lea     eax, [ebx + ctx_sha2_384512.hash]
399
        lea     esi, [ebx + ctx_sha384512.block]
395
        lea     esi, [ebx + ctx_sha2_384512.block]
400
        stdcall sha384512._.block, eax
396
        stdcall sha2_384512._.block, eax
401
        jmp     .next_block
397
        jmp     .next_block
402
 
398
 
403
  .copy_quit:
399
.copy_quit:
404
        mov     ebx, [_ctx]
400
        mov     ebx, [_ctx]
405
        lea     edi, [ebx + ctx_sha384512.block]
401
        lea     edi, [ebx + ctx_sha2_384512.block]
406
        mov     eax, [ebx + ctx_sha384512.index]
402
        mov     eax, [ebx + ctx_sha2_384512.index]
407
        and     eax, SHA384512_BLOCK_SIZE-1
403
        and     eax, SHA2_384512_BLOCK_SIZE-1
Line 408... Line 404...
408
        add     edi, eax
404
        add     edi, eax
409
        mov     ecx, [_size]
405
        mov     ecx, [_size]
Line 410... Line 406...
410
        add     [ebx + ctx_sha384512.index], ecx
406
        add     [ebx + ctx_sha2_384512.index], ecx
411
        rep     movsb
407
        rep movsb
412
  .quit:
408
.quit:
413
 
409
 
414
        ret
410
        ret
415
endp
411
endp
416
 
412
 
417
 
413
 
418
sha384.final = sha384512.final
414
sha2_384.finish = sha2_384512.finish
419
sha512.final = sha384512.final
415
sha2_512.finish = sha2_384512.finish
420
proc sha384512.final _ctx
416
proc sha2_384512.finish uses ebx esi edi, _ctx
421
        mov     ebx, [_ctx]
417
        mov     ebx, [_ctx]
422
        lea     edi, [ebx + ctx_sha384512.block]
418
        lea     edi, [ebx + ctx_sha2_384512.block]
423
        mov     ecx, [ebx + ctx_sha384512.msglen_0]
419
        mov     ecx, [ebx + ctx_sha2_384512.msglen_0]
Line 424... Line 420...
424
        and     ecx, SHA384512_BLOCK_SIZE-1
420
        and     ecx, SHA2_384512_BLOCK_SIZE-1
425
        add     edi, ecx
421
        add     edi, ecx
426
        mov     byte[edi], 0x80
422
        mov     byte[edi], 0x80
427
        inc     edi
423
        inc     edi
428
        neg     ecx
424
        neg     ecx
429
        add     ecx, SHA384512_BLOCK_SIZE
425
        add     ecx, SHA2_384512_BLOCK_SIZE
430
        cmp     ecx, 16
426
        cmp     ecx, 16
431
        ja      .last
427
        ja      .last
432
 
428
 
433
        dec     ecx
429
        dec     ecx
434
        xor     eax, eax
430
        xor     eax, eax
435
        rep     stosb
431
        rep stosb
436
        lea     esi, [ebx + ctx_sha384512.block]
432
        lea     esi, [ebx + ctx_sha2_384512.block]
437
        lea     eax, [ebx + ctx_sha384512.hash]
433
        lea     eax, [ebx + ctx_sha2_384512.hash]
438
        stdcall sha384512._.block, eax
434
        stdcall sha2_384512._.block, eax
439
        mov     ebx, [_ctx]
435
        mov     ebx, [_ctx]
440
        lea     edi, [ebx + ctx_sha384512.block]
436
        lea     edi, [ebx + ctx_sha2_384512.block]
441
        mov     ecx, SHA384512_BLOCK_SIZE+1
437
        mov     ecx, SHA2_384512_BLOCK_SIZE+1
442
  .last:
438
.last:
443
        dec     ecx
439
        dec     ecx
444
        sub     ecx, 16
440
        sub     ecx, 16
445
        xor     eax, eax
441
        xor     eax, eax
446
        rep     stosb
442
        rep stosb
447
        mov     eax, [ebx + ctx_sha384512.msglen_1]
443
        mov     eax, [ebx + ctx_sha2_384512.msglen_1]
448
        shld    [ebx + ctx_sha384512.msglen_0], eax, 3
444
        shld    [ebx + ctx_sha2_384512.msglen_0], eax, 3
449
        mov     eax, [ebx + ctx_sha384512.msglen_2]
445
        mov     eax, [ebx + ctx_sha2_384512.msglen_2]
450
        shld    [ebx + ctx_sha384512.msglen_1], eax, 3
446
        shld    [ebx + ctx_sha2_384512.msglen_1], eax, 3
451
        mov     eax, [ebx + ctx_sha384512.msglen_3]
447
        mov     eax, [ebx + ctx_sha2_384512.msglen_3]
452
        shld    [ebx + ctx_sha384512.msglen_2], eax, 3
448
        shld    [ebx + ctx_sha2_384512.msglen_2], eax, 3
453
        shl     eax, 3
449
        shl     eax, 3
454
        bswap   eax
450
        bswap   eax
455
        mov     dword[edi + 0], eax
451
        mov     dword[edi + 0], eax
456
        mov     eax, [ebx + ctx_sha384512.msglen_2]
452
        mov     eax, [ebx + ctx_sha2_384512.msglen_2]
457
        bswap   eax
453
        bswap   eax
458
        mov     dword[edi + 4], eax
454
        mov     dword[edi + 4], eax
459
        mov     eax, [ebx + ctx_sha384512.msglen_1]
455
        mov     eax, [ebx + ctx_sha2_384512.msglen_1]
Line 460... Line 456...
460
        bswap   eax
456
        bswap   eax
461
        mov     dword[edi + 8], eax
457
        mov     dword[edi + 8], eax
462
        mov     eax, [ebx + ctx_sha384512.msglen_0]
458
        mov     eax, [ebx + ctx_sha2_384512.msglen_0]
Line 463... Line 459...
463
        bswap   eax
459
        bswap   eax
464
        mov     dword[edi + 12], eax
460
        mov     dword[edi + 12], eax
Line 465... Line 461...
465
        mov     ebx, [_ctx]
461
        mov     ebx, [_ctx]
466
        lea     esi, [ebx + ctx_sha384512.block]
462
        lea     esi, [ebx + ctx_sha2_384512.block]
467
        lea     eax, [ebx + ctx_sha384512.hash]
463
        lea     eax, [ebx + ctx_sha2_384512.hash]
468
        stdcall sha384512._.block, eax
464
        stdcall sha2_384512._.block, eax
469
 
465
 
470
        mov     ebx, [_ctx]
466
        mov     ebx, [_ctx]
Line 493... Line 489...
493
        emms
489
        emms
494
        ret
490
        ret
495
endp
491
endp
Line 496... Line 492...
496
 
492
 
497
 
493
 
498
proc sha384.oneshot _ctx, _data, _len
494
proc sha2_384.oneshot _ctx, _data, _len
499
	stdcall	sha384.init, [_ctx]
495
        stdcall sha2_384.init, [_ctx]
500
	stdcall	sha384.update, [_ctx], [_data], [_len]
496
        stdcall sha2_384.update, [_ctx], [_data], [_len]
501
	stdcall	sha384.final, [_ctx]
497
        stdcall sha2_384.finish, [_ctx]
Line 502... Line 498...
502
	ret
498
        ret
503
endp
499
endp
504
 
500
 
505
 
501
 
506
proc sha512.oneshot _ctx, _data, _len
502
proc sha2_512.oneshot _ctx, _data, _len
507
	stdcall	sha512.init, [_ctx]
503
        stdcall sha2_512.init, [_ctx]
Line 508... Line 504...
508
	stdcall	sha512.update, [_ctx], [_data], [_len]
504
        stdcall sha2_512.update, [_ctx], [_data], [_len]
509
	stdcall	sha512.final, [_ctx]
505
        stdcall sha2_512.finish, [_ctx]
510
	ret
506
        ret
511
endp
507
endp
512
 
508
 
513
 
509
 
Line 514... Line 510...
514
iglobal
510
iglobal
515
align SHA384512_ALIGN
511
align SHA2_384512_ALIGN
516
sha384._.hash_init      dq 0xcbbb9d5dc1059ed8, 0x629a292a367cd507,\
512
sha2_384._.hash_init    dq 0xcbbb9d5dc1059ed8, 0x629a292a367cd507,\
517
                           0x9159015a3070dd17, 0x152fecd8f70e5939,\
513
                           0x9159015a3070dd17, 0x152fecd8f70e5939,\
Line 518... Line 514...
518
                           0x67332667ffc00b31, 0x8eb44a8768581511,\
514
                           0x67332667ffc00b31, 0x8eb44a8768581511,\
519
                           0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
515
                           0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
520
 
516
 
521
sha512._.hash_init      dq 0x6a09e667f3bcc908, 0xbb67ae8584caa73b,\
517
sha2_512._.hash_init    dq 0x6a09e667f3bcc908, 0xbb67ae8584caa73b,\
522
                           0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\
518
                           0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\
523
                           0x510e527fade682d1, 0x9b05688c2b3e6c1f,\
519
                           0x510e527fade682d1, 0x9b05688c2b3e6c1f,\