Subversion Repositories Kolibri OS

Rev

Rev 6461 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6461 Rev 6465
1
;    libcrash -- cryptographic hash functions
1
;    libcrash -- cryptographic hash functions
2
;
2
;
3
;    Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
3
;    Copyright (C) 2012-2013,2016 Ivan Baravy (dunkaist)
4
;
4
;
5
;    This program is free software: you can redistribute it and/or modify
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
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
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
8
;    (at your option) any later version.
9
;
9
;
10
;    This program is distributed in the hope that it will be useful,
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
13
;    GNU General Public License for more details.
14
;
14
;
15
;    You should have received a copy of the GNU General Public License
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
16
;    along with this program.  If not, see .
17
 
17
 
18
 
-
 
19
SHA224256_BLOCK_SIZE = 64
-
 
20
SHA224256_INIT_SIZE  = 32
-
 
21
SHA224_HASH_SIZE     = 28
-
 
22
SHA256_HASH_SIZE     = 32
-
 
23
SHA224256_ALIGN      = 4
-
 
24
SHA224256_ALIGN_MASK = SHA224256_ALIGN - 1
-
 
25
 
-
 
26
struct ctx_sha224256
-
 
27
        hash            rb SHA224256_INIT_SIZE
-
 
28
        block           rb SHA224256_BLOCK_SIZE
-
 
29
        index           rd 1
-
 
30
        msglen_0        rd 1
-
 
31
        msglen_1        rd 1
-
 
32
ends
-
 
33
 
-
 
34
 
18
 
35
macro sha224256._.chn x, y, z
19
macro sha224256._.chn x, y, z
36
{
20
{
37
        mov     eax, [y]
21
        mov     eax, [y]
38
        xor     eax, [z]
22
        xor     eax, [z]
39
        and     eax, [x]
23
        and     eax, [x]
40
        xor     eax, [z]
24
        xor     eax, [z]
41
}
25
}
42
 
26
 
43
macro sha224256._.maj x, y, z
27
macro sha224256._.maj x, y, z
44
{
28
{
45
        mov     eax, [x]
29
        mov     eax, [x]
46
        xor     eax, [y]
30
        xor     eax, [y]
47
        and     eax, [z]
31
        and     eax, [z]
48
        mov     ecx, [x]
32
        mov     ecx, [x]
49
        and     ecx, [y]
33
        and     ecx, [y]
50
        xor     eax, ecx
34
        xor     eax, ecx
51
}
35
}
52
 
36
 
53
macro sha224256._.Sigma0 x
37
macro sha224256._.Sigma0 x
54
{
38
{
55
        mov     eax, x
39
        mov     eax, x
56
        mov     ecx, eax
40
        mov     ecx, eax
57
        ror     ecx, 2
41
        ror     ecx, 2
58
        ror     eax, 13
42
        ror     eax, 13
59
        xor     eax, ecx
43
        xor     eax, ecx
60
        mov     ecx, x
44
        mov     ecx, x
61
        ror     ecx, 22
45
        ror     ecx, 22
62
        xor     eax, ecx
46
        xor     eax, ecx
63
}
47
}
64
 
48
 
65
macro sha224256._.Sigma1 x
49
macro sha224256._.Sigma1 x
66
{
50
{
67
        mov     eax, x
51
        mov     eax, x
68
        mov     ecx, eax
52
        mov     ecx, eax
69
        ror     ecx, 6
53
        ror     ecx, 6
70
        ror     eax, 11
54
        ror     eax, 11
71
        xor     eax, ecx
55
        xor     eax, ecx
72
        mov     ecx, x
56
        mov     ecx, x
73
        ror     ecx, 25
57
        ror     ecx, 25
74
        xor     eax, ecx
58
        xor     eax, ecx
75
}
59
}
76
 
60
 
77
macro sha224256._.sigma0 x
61
macro sha224256._.sigma0 x
78
{
62
{
79
        mov     eax, x
63
        mov     eax, x
80
        mov     ecx, eax
64
        mov     ecx, eax
81
        ror     ecx, 7
65
        ror     ecx, 7
82
        ror     eax, 18
66
        ror     eax, 18
83
        xor     eax, ecx
67
        xor     eax, ecx
84
        mov     ecx, x
68
        mov     ecx, x
85
        shr     ecx, 3
69
        shr     ecx, 3
86
        xor     eax, ecx
70
        xor     eax, ecx
87
}
71
}
88
 
72
 
89
macro sha224256._.sigma1 x
73
macro sha224256._.sigma1 x
90
{
74
{
91
        mov     eax, x
75
        mov     eax, x
92
        mov     ecx, eax
76
        mov     ecx, eax
93
        ror     ecx, 17
77
        ror     ecx, 17
94
        ror     eax, 19
78
        ror     eax, 19
95
        xor     eax, ecx
79
        xor     eax, ecx
96
        mov     ecx, x
80
        mov     ecx, x
97
        shr     ecx, 10
81
        shr     ecx, 10
98
        xor     eax, ecx
82
        xor     eax, ecx
99
}
83
}
100
 
84
 
101
macro sha224256._.recalculate_w n
85
macro sha224256._.recalculate_w n
102
{
86
{
103
        mov     edx, [w + ((n-2) and 15)*4]
87
        mov     edx, [w + ((n-2) and 15)*4]
104
        sha224256._.sigma1  edx
88
        sha224256._.sigma1  edx
105
        add     eax, [w + ((n-7) and 15)*4]
89
        add     eax, [w + ((n-7) and 15)*4]
106
        push    eax
90
        push    eax
107
        mov     edx, [w + ((n-15) and 15)*4]
91
        mov     edx, [w + ((n-15) and 15)*4]
108
        sha224256._.sigma0  edx
92
        sha224256._.sigma0  edx
109
        pop     ecx
93
        pop     ecx
110
        add     eax, ecx
94
        add     eax, ecx
111
        add     [w + (n)*4], eax
95
        add     [w + (n)*4], eax
112
}
96
}
113
 
97
 
114
macro sha224256._.round a, b, c, d, e, f, g, h, k
98
macro sha224256._.round a, b, c, d, e, f, g, h, k
115
{
99
{
116
        mov     ebx, [h]
100
        mov     ebx, [h]
117
        mov     edx, [e]
101
        mov     edx, [e]
118
        sha224256._.Sigma1  edx
102
        sha224256._.Sigma1  edx
119
 
103
 
120
        add     ebx, eax
104
        add     ebx, eax
121
        sha224256._.chn     e, f, g
105
        sha224256._.chn     e, f, g
122
 
106
 
123
        add     ebx, eax
107
        add     ebx, eax
124
        add     ebx, [k]
108
        add     ebx, [k]
125
        add     ebx, edi
109
        add     ebx, edi
126
 
110
 
127
        add     [d], ebx
111
        add     [d], ebx
128
 
112
 
129
        mov     edx, [a]
113
        mov     edx, [a]
130
        sha224256._.Sigma0  edx
114
        sha224256._.Sigma0  edx
131
        add     ebx, eax
115
        add     ebx, eax
132
        sha224256._.maj     a, b, c
116
        sha224256._.maj     a, b, c
133
        add     eax, ebx
117
        add     eax, ebx
134
        mov     [h], eax
118
        mov     [h], eax
135
}
119
}
136
 
120
 
137
 
121
 
138
macro sha224256._.round_1_16 a, b, c, d, e, f, g, h, n
122
macro sha224256._.round_1_16 a, b, c, d, e, f, g, h, n
139
{
123
{
140
 
124
 
141
        mov     eax, [esi + (n)*4]
125
        mov     eax, [esi + (n)*4]
142
        bswap   eax
126
        bswap   eax
143
 
127
 
144
        mov     dword[w + (n)*4], eax
128
        mov     dword[w + (n)*4], eax
145
        mov     edi, eax
129
        mov     edi, eax
146
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n)*4)
130
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n)*4)
147
}
131
}
148
 
132
 
149
macro sha224256._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
133
macro sha224256._.round_17_64 a, b, c, d, e, f, g, h, n, rep_num
150
{
134
{
151
        sha224256._.recalculate_w n
135
        sha224256._.recalculate_w n
152
        mov     edi, [w + (n)*4]
136
        mov     edi, [w + (n)*4]
153
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n+16*rep_num)*4)
137
        sha224256._.round a, b, c, d, e, f, g, h, (sha256_table + (n+16*rep_num)*4)
154
}
138
}
155
 
139
 
156
 
140
 
157
proc sha224.init _ctx
141
proc sha224.init _ctx
158
        mov     ebx, [_ctx]
142
        mov     ebx, [_ctx]
159
        lea     edi, [ebx + ctx_sha224256.hash]
143
        lea     edi, [ebx + ctx_sha224256.hash]
160
        mov     esi, sha224._.hash_init
144
        mov     esi, sha224._.hash_init
161
        mov     ecx, SHA224256_INIT_SIZE/4
145
        mov     ecx, SHA224256_INIT_SIZE/4
162
        rep     movsd
146
        rep     movsd
163
        xor     eax, eax
147
        xor     eax, eax
164
        mov     [ebx + ctx_sha224256.index], eax
148
        mov     [ebx + ctx_sha224256.index], eax
165
        mov     [ebx + ctx_sha224256.msglen_0], eax
149
        mov     [ebx + ctx_sha224256.msglen_0], eax
166
        mov     [ebx + ctx_sha224256.msglen_1], eax
150
        mov     [ebx + ctx_sha224256.msglen_1], eax
167
        ret
151
        ret
168
endp
152
endp
169
 
153
 
170
 
154
 
171
proc sha256.init _ctx
155
proc sha256.init _ctx
172
        mov     ebx, [_ctx]
156
        mov     ebx, [_ctx]
173
        lea     edi, [ebx + ctx_sha224256.hash]
157
        lea     edi, [ebx + ctx_sha224256.hash]
174
        mov     esi, sha256._.hash_init
158
        mov     esi, sha256._.hash_init
175
        mov     ecx, SHA224256_INIT_SIZE/4
159
        mov     ecx, SHA224256_INIT_SIZE/4
176
        rep     movsd
160
        rep     movsd
177
        xor     eax, eax
161
        xor     eax, eax
178
        mov     [ebx + ctx_sha224256.index], eax
162
        mov     [ebx + ctx_sha224256.index], eax
179
        mov     [ebx + ctx_sha224256.msglen_0], eax
163
        mov     [ebx + ctx_sha224256.msglen_0], eax
180
        mov     [ebx + ctx_sha224256.msglen_1], eax
164
        mov     [ebx + ctx_sha224256.msglen_1], eax
181
        ret
165
        ret
182
endp
166
endp
183
 
167
 
184
 
168
 
185
proc sha224256._.block _hash
169
proc sha224256._.block _hash
186
locals
170
locals
187
        w       rd 64
171
        w       rd 64
188
        A       rd 1
172
        A       rd 1
189
        B       rd 1
173
        B       rd 1
190
        C       rd 1
174
        C       rd 1
191
        D       rd 1
175
        D       rd 1
192
        E       rd 1
176
        E       rd 1
193
        F       rd 1
177
        F       rd 1
194
        G       rd 1
178
        G       rd 1
195
        H       rd 1
179
        H       rd 1
196
endl
180
endl
197
        mov     edi, [_hash]
181
        mov     edi, [_hash]
198
        mov     eax, [edi + 0x00]
182
        mov     eax, [edi + 0x00]
199
        mov     [A], eax
183
        mov     [A], eax
200
        mov     eax, [edi + 0x04]
184
        mov     eax, [edi + 0x04]
201
        mov     [B], eax
185
        mov     [B], eax
202
        mov     eax, [edi + 0x08]
186
        mov     eax, [edi + 0x08]
203
        mov     [C], eax
187
        mov     [C], eax
204
        mov     eax, [edi + 0x0c]
188
        mov     eax, [edi + 0x0c]
205
        mov     [D], eax
189
        mov     [D], eax
206
        mov     eax, [edi + 0x10]
190
        mov     eax, [edi + 0x10]
207
        mov     [E], eax
191
        mov     [E], eax
208
        mov     eax, [edi + 0x14]
192
        mov     eax, [edi + 0x14]
209
        mov     [F], eax
193
        mov     [F], eax
210
        mov     eax, [edi + 0x18]
194
        mov     eax, [edi + 0x18]
211
        mov     [G], eax
195
        mov     [G], eax
212
        mov     eax, [edi + 0x1c]
196
        mov     eax, [edi + 0x1c]
213
        mov     [H], eax
197
        mov     [H], eax
214
 
198
 
215
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  0
199
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  0
216
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  1
200
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  1
217
        sha224256._.round_1_16  G, H, A, B, C, D, E, F,  2
201
        sha224256._.round_1_16  G, H, A, B, C, D, E, F,  2
218
        sha224256._.round_1_16  F, G, H, A, B, C, D, E,  3
202
        sha224256._.round_1_16  F, G, H, A, B, C, D, E,  3
219
        sha224256._.round_1_16  E, F, G, H, A, B, C, D,  4
203
        sha224256._.round_1_16  E, F, G, H, A, B, C, D,  4
220
        sha224256._.round_1_16  D, E, F, G, H, A, B, C,  5
204
        sha224256._.round_1_16  D, E, F, G, H, A, B, C,  5
221
        sha224256._.round_1_16  C, D, E, F, G, H, A, B,  6
205
        sha224256._.round_1_16  C, D, E, F, G, H, A, B,  6
222
        sha224256._.round_1_16  B, C, D, E, F, G, H, A,  7
206
        sha224256._.round_1_16  B, C, D, E, F, G, H, A,  7
223
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  8
207
        sha224256._.round_1_16  A, B, C, D, E, F, G, H,  8
224
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  9
208
        sha224256._.round_1_16  H, A, B, C, D, E, F, G,  9
225
        sha224256._.round_1_16  G, H, A, B, C, D, E, F, 10
209
        sha224256._.round_1_16  G, H, A, B, C, D, E, F, 10
226
        sha224256._.round_1_16  F, G, H, A, B, C, D, E, 11
210
        sha224256._.round_1_16  F, G, H, A, B, C, D, E, 11
227
        sha224256._.round_1_16  E, F, G, H, A, B, C, D, 12
211
        sha224256._.round_1_16  E, F, G, H, A, B, C, D, 12
228
        sha224256._.round_1_16  D, E, F, G, H, A, B, C, 13
212
        sha224256._.round_1_16  D, E, F, G, H, A, B, C, 13
229
        sha224256._.round_1_16  C, D, E, F, G, H, A, B, 14
213
        sha224256._.round_1_16  C, D, E, F, G, H, A, B, 14
230
        sha224256._.round_1_16  B, C, D, E, F, G, H, A, 15
214
        sha224256._.round_1_16  B, C, D, E, F, G, H, A, 15
231
 
215
 
232
repeat 3
216
repeat 3
233
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  0, %
217
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  0, %
234
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  1, %
218
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  1, %
235
        sha224256._.round_17_64 G, H, A, B, C, D, E, F,  2, %
219
        sha224256._.round_17_64 G, H, A, B, C, D, E, F,  2, %
236
        sha224256._.round_17_64 F, G, H, A, B, C, D, E,  3, %
220
        sha224256._.round_17_64 F, G, H, A, B, C, D, E,  3, %
237
        sha224256._.round_17_64 E, F, G, H, A, B, C, D,  4, %
221
        sha224256._.round_17_64 E, F, G, H, A, B, C, D,  4, %
238
        sha224256._.round_17_64 D, E, F, G, H, A, B, C,  5, %
222
        sha224256._.round_17_64 D, E, F, G, H, A, B, C,  5, %
239
        sha224256._.round_17_64 C, D, E, F, G, H, A, B,  6, %
223
        sha224256._.round_17_64 C, D, E, F, G, H, A, B,  6, %
240
        sha224256._.round_17_64 B, C, D, E, F, G, H, A,  7, %
224
        sha224256._.round_17_64 B, C, D, E, F, G, H, A,  7, %
241
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  8, %
225
        sha224256._.round_17_64 A, B, C, D, E, F, G, H,  8, %
242
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  9, %
226
        sha224256._.round_17_64 H, A, B, C, D, E, F, G,  9, %
243
        sha224256._.round_17_64 G, H, A, B, C, D, E, F, 10, %
227
        sha224256._.round_17_64 G, H, A, B, C, D, E, F, 10, %
244
        sha224256._.round_17_64 F, G, H, A, B, C, D, E, 11, %
228
        sha224256._.round_17_64 F, G, H, A, B, C, D, E, 11, %
245
        sha224256._.round_17_64 E, F, G, H, A, B, C, D, 12, %
229
        sha224256._.round_17_64 E, F, G, H, A, B, C, D, 12, %
246
        sha224256._.round_17_64 D, E, F, G, H, A, B, C, 13, %
230
        sha224256._.round_17_64 D, E, F, G, H, A, B, C, 13, %
247
        sha224256._.round_17_64 C, D, E, F, G, H, A, B, 14, %
231
        sha224256._.round_17_64 C, D, E, F, G, H, A, B, 14, %
248
        sha224256._.round_17_64 B, C, D, E, F, G, H, A, 15, %
232
        sha224256._.round_17_64 B, C, D, E, F, G, H, A, 15, %
249
end repeat
233
end repeat
250
 
234
 
251
        mov     edi, [_hash]
235
        mov     edi, [_hash]
252
        mov     eax, [A]
236
        mov     eax, [A]
253
        add     [edi + 0x00], eax
237
        add     [edi + 0x00], eax
254
        mov     eax, [B]
238
        mov     eax, [B]
255
        add     [edi + 0x04], eax
239
        add     [edi + 0x04], eax
256
        mov     eax, [C]
240
        mov     eax, [C]
257
        add     [edi + 0x08], eax
241
        add     [edi + 0x08], eax
258
        mov     eax, [D]
242
        mov     eax, [D]
259
        add     [edi + 0x0c], eax
243
        add     [edi + 0x0c], eax
260
        mov     eax, [E]
244
        mov     eax, [E]
261
        add     [edi + 0x10], eax
245
        add     [edi + 0x10], eax
262
        mov     eax, [F]
246
        mov     eax, [F]
263
        add     [edi + 0x14], eax
247
        add     [edi + 0x14], eax
264
        mov     eax, [G]
248
        mov     eax, [G]
265
        add     [edi + 0x18], eax
249
        add     [edi + 0x18], eax
266
        mov     eax, [H]
250
        mov     eax, [H]
267
        add     [edi + 0x1c], eax
251
        add     [edi + 0x1c], eax
268
 
252
 
269
        ret
253
        ret
270
endp
254
endp
271
 
-
 
-
 
255
 
272
 
256
sha256.update = sha224.update
273
proc sha224256.update _ctx, _msg, _size
257
proc sha224.update _ctx, _msg, _size
274
        mov     ebx, [_ctx]
258
        mov     ebx, [_ctx]
275
        mov     ecx, [_size]
259
        mov     ecx, [_size]
276
        add     [ebx + ctx_sha224256.msglen_0], ecx
260
        add     [ebx + ctx_sha224256.msglen_0], ecx
277
        adc     [ebx + ctx_sha224256.msglen_1], 0
261
        adc     [ebx + ctx_sha224256.msglen_1], 0
278
 
262
 
279
  .next_block:
263
  .next_block:
280
        mov     ebx, [_ctx]
264
        mov     ebx, [_ctx]
281
        mov     esi, [_msg]
265
        mov     esi, [_msg]
282
        mov     eax, [ebx + ctx_sha224256.index]
266
        mov     eax, [ebx + ctx_sha224256.index]
283
        and     eax, SHA224256_BLOCK_SIZE-1
267
        and     eax, SHA224256_BLOCK_SIZE-1
284
        jnz     .copy_to_buf
268
        jnz     .copy_to_buf
285
        test    esi, SHA224256_ALIGN_MASK
269
        test    esi, SHA224256_ALIGN_MASK
286
        jnz     .copy_to_buf
270
        jnz     .copy_to_buf
287
  .no_copy:
271
  .no_copy:
288
        ; data is aligned, hash it in place without copying
272
        ; data is aligned, hash it in place without copying
289
        mov     ebx, [_ctx]
273
        mov     ebx, [_ctx]
290
        cmp     [_size], SHA224256_BLOCK_SIZE
274
        cmp     [_size], SHA224256_BLOCK_SIZE
291
        jb      .copy_quit
275
        jb      .copy_quit
292
        lea     eax, [ebx + ctx_sha224256.hash]
276
        lea     eax, [ebx + ctx_sha224256.hash]
293
        stdcall sha224256._.block, eax
277
        stdcall sha224256._.block, eax
294
        sub     [_size], SHA224256_BLOCK_SIZE
278
        sub     [_size], SHA224256_BLOCK_SIZE
295
        add     esi, SHA224256_BLOCK_SIZE           ; FIXME
279
        add     esi, SHA224256_BLOCK_SIZE           ; FIXME
296
        jmp     .no_copy
280
        jmp     .no_copy
297
 
281
 
298
  .copy_to_buf:
282
  .copy_to_buf:
299
        lea     edi, [ebx + ctx_sha224256.block]
283
        lea     edi, [ebx + ctx_sha224256.block]
300
        add     edi, eax
284
        add     edi, eax
301
        mov     ecx, SHA224256_BLOCK_SIZE
285
        mov     ecx, SHA224256_BLOCK_SIZE
302
        sub     ecx, eax
286
        sub     ecx, eax
303
        cmp     [_size], ecx
287
        cmp     [_size], ecx
304
        jb      .copy_quit
288
        jb      .copy_quit
305
        sub     [_size], ecx
289
        sub     [_size], ecx
306
        add     [_msg], ecx
290
        add     [_msg], ecx
307
        add     [ebx + ctx_sha224256.index], ecx
291
        add     [ebx + ctx_sha224256.index], ecx
308
        rep     movsb
292
        rep     movsb
309
        lea     eax, [ebx + ctx_sha224256.hash]
293
        lea     eax, [ebx + ctx_sha224256.hash]
310
        lea     esi, [ebx + ctx_sha224256.block]
294
        lea     esi, [ebx + ctx_sha224256.block]
311
        stdcall sha224256._.block, eax
295
        stdcall sha224256._.block, eax
312
        jmp     .next_block
296
        jmp     .next_block
313
 
297
 
314
  .copy_quit:
298
  .copy_quit:
315
        mov     ebx, [_ctx]
299
        mov     ebx, [_ctx]
316
        lea     edi, [ebx + ctx_sha224256.block]
300
        lea     edi, [ebx + ctx_sha224256.block]
317
        mov     eax, [ebx + ctx_sha224256.index]
301
        mov     eax, [ebx + ctx_sha224256.index]
318
        and     eax, SHA224256_BLOCK_SIZE-1
302
        and     eax, SHA224256_BLOCK_SIZE-1
319
        add     edi, eax
303
        add     edi, eax
320
        mov     ecx, [_size]
304
        mov     ecx, [_size]
321
        add     [ebx + ctx_sha224256.index], ecx
305
        add     [ebx + ctx_sha224256.index], ecx
322
        rep     movsb
306
        rep     movsb
323
  .quit:
307
  .quit:
324
 
308
 
325
        ret
309
        ret
326
endp
310
endp
327
 
311
 
-
 
312
 
328
 
313
sha256.final = sha224.final
329
proc sha224256.final _ctx
314
proc sha224.final _ctx
330
        mov     ebx, [_ctx]
315
        mov     ebx, [_ctx]
331
        lea     edi, [ebx + ctx_sha224256.block]
316
        lea     edi, [ebx + ctx_sha224256.block]
332
        mov     ecx, [ebx + ctx_sha224256.msglen_0]
317
        mov     ecx, [ebx + ctx_sha224256.msglen_0]
333
        and     ecx, SHA224256_BLOCK_SIZE-1
318
        and     ecx, SHA224256_BLOCK_SIZE-1
334
        add     edi, ecx
319
        add     edi, ecx
335
        mov     byte[edi], 0x80
320
        mov     byte[edi], 0x80
336
        inc     edi
321
        inc     edi
337
        neg     ecx
322
        neg     ecx
338
        add     ecx, SHA224256_BLOCK_SIZE
323
        add     ecx, SHA224256_BLOCK_SIZE
339
        cmp     ecx, 8
324
        cmp     ecx, 8
340
        ja      .last
325
        ja      .last
341
 
326
 
342
        dec     ecx
327
        dec     ecx
343
        xor     eax, eax
328
        xor     eax, eax
344
        rep     stosb
329
        rep     stosb
345
        lea     esi, [ebx + ctx_sha224256.block]
330
        lea     esi, [ebx + ctx_sha224256.block]
346
        lea     eax, [ebx + ctx_sha224256.hash]
331
        lea     eax, [ebx + ctx_sha224256.hash]
347
        stdcall sha224256._.block, eax
332
        stdcall sha224256._.block, eax
348
        mov     ebx, [_ctx]
333
        mov     ebx, [_ctx]
349
        lea     edi, [ebx + ctx_sha224256.block]
334
        lea     edi, [ebx + ctx_sha224256.block]
350
        mov     ecx, SHA224256_BLOCK_SIZE+1
335
        mov     ecx, SHA224256_BLOCK_SIZE+1
351
  .last:
336
  .last:
352
        dec     ecx
337
        dec     ecx
353
        sub     ecx, 8
338
        sub     ecx, 8
354
        xor     eax, eax
339
        xor     eax, eax
355
        rep     stosb
340
        rep     stosb
356
        mov     eax, [ebx + ctx_sha224256.msglen_0]
341
        mov     eax, [ebx + ctx_sha224256.msglen_0]
357
        mov     edx, [ebx + ctx_sha224256.msglen_1]
342
        mov     edx, [ebx + ctx_sha224256.msglen_1]
358
        shld    edx, eax, 3
343
        shld    edx, eax, 3
359
        shl     eax, 3
344
        shl     eax, 3
360
        bswap   eax
345
        bswap   eax
361
        bswap   edx
346
        bswap   edx
362
        mov     dword[edi], edx
347
        mov     dword[edi], edx
363
        mov     dword[edi+4], eax
348
        mov     dword[edi+4], eax
364
        lea     esi, [ebx + ctx_sha224256.block]
349
        lea     esi, [ebx + ctx_sha224256.block]
365
        lea     eax, [ebx + ctx_sha224256.hash]
350
        lea     eax, [ebx + ctx_sha224256.hash]
366
        stdcall sha224256._.block, eax
351
        stdcall sha224256._.block, eax
367
 
352
 
368
        mov     ebx, [_ctx]
353
        mov     ebx, [_ctx]
369
        lea     eax, [ebx + ctx_sha224256.hash]
354
        lea     eax, [ebx + ctx_sha224256.hash]
370
        stdcall sha224256._.postprocess, ebx, eax
355
        stdcall sha224256._.postprocess, ebx, eax
371
 
356
 
372
        ret
357
        ret
373
endp
358
endp
374
 
359
 
375
 
360
 
376
proc sha224256._.postprocess _ctx, _hash
361
proc sha224256._.postprocess _ctx, _hash
377
        mov     ecx, 8
362
        mov     ecx, 8
378
        mov     esi, [_hash]
363
        mov     esi, [_hash]
379
        mov     edi, esi
364
        mov     edi, esi
380
    @@:
365
    @@:
381
        lodsd
366
        lodsd
382
        bswap   eax
367
        bswap   eax
383
        stosd
368
        stosd
384
        dec     ecx
369
        dec     ecx
385
        jnz     @b
370
        jnz     @b
386
        ret
371
        ret
387
endp
372
endp
388
 
373
 
389
 
374
 
390
align SHA224256_ALIGN
375
align SHA224256_ALIGN
391
 
376
 
392
sha224._.hash_init      dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,\
377
sha224._.hash_init      dd 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,\
393
                           0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
378
                           0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
394
 
379
 
395
sha256._.hash_init      dd 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\
380
sha256._.hash_init      dd 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\
396
                           0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
381
                           0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
397
 
382
 
398
sha256_table            dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
383
sha256_table            dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
399
                           0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
384
                           0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
400
                           0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
385
                           0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
401
                           0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
386
                           0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
402
                           0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
387
                           0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
403
                           0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
388
                           0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
404
                           0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
389
                           0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
405
                           0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
390
                           0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
406
                           0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
391
                           0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
407
                           0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
392
                           0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
408
                           0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
393
                           0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
409
                           0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
394
                           0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
410
                           0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
395
                           0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
411
                           0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
396
                           0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
412
                           0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
397
                           0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
413
                           0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
398
                           0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2