Subversion Repositories Kolibri OS

Rev

Rev 3431 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3431 Rev 3532
Line 33... Line 33...
33
include 'md4.asm'
33
include 'md4.asm'
34
include 'md5.asm'
34
include 'md5.asm'
35
include 'sha1.asm'
35
include 'sha1.asm'
36
include 'sha224_256.asm'
36
include 'sha224_256.asm'
37
include 'sha384_512.asm'
37
include 'sha384_512.asm'
-
 
38
include 'sha3.asm'
Line 38... Line 39...
38
 
39
 
39
 
40
 
40
proc lib_init
41
proc lib_init
Line 83... Line 84...
83
  .endofblock:
84
  .endofblock:
84
	cmp	[final], 1
85
	cmp	[final], 1
85
	je	.quit
86
	je	.quit
Line 86... Line 87...
86
 
87
 
-
 
88
  .callback:
-
 
89
	mov	edi, [_data]
-
 
90
	mov	ecx, [_len]
-
 
91
	rep	movsb
87
  .callback:
92
	push	esi edi
-
 
93
	stdcall	[_callback], [_len]
88
	call	[_callback]
94
	pop	edi esi
89
	test	eax, eax
95
	test	eax, eax
-
 
96
	jz	@f
-
 
97
	mov	edx, [_msglen]
-
 
98
	mov	ecx, [_len]
90
	jz	@f
99
	sub	[edx], ecx
91
	mov	[_len], eax
100
	add	[_len], eax
92
	jmp	.first
101
	jmp	.first
Line 93... Line -...
93
    @@:
-
 
94
 
-
 
95
	mov	edi, [_data]
-
 
96
	mov	ecx, [_len]
102
    @@:
97
	rep	movsb
103
 
-
 
104
	mov	eax, [_msglen]
98
	mov	eax, [_msglen]
105
	mov	eax, [eax]
99
	mov	eax, [eax]
106
	xor	edx, edx
100
	mov	edx, [hi]
107
	mov	ecx, [hi]
101
	mov	edx, [edx + crash_item.len_blk]
108
	mov	ecx, [ecx + crash_item.len_blk]
102
	sub	edx, 1
109
	div	ecx
103
	and	eax, edx
110
	mov	eax, edx
104
	mov	edx, [hi]
111
	mov	edx, [hi]
105
	mov	ecx, [edx + crash_item.len_blk]
112
	mov	ecx, [edx + crash_item.len_blk]
106
	sub	ecx, [edx + crash_item.len_size]
113
	sub	ecx, [edx + crash_item.len_size]
107
	sub	ecx, eax
114
	sub	ecx, eax
108
	ja	@f
115
	ja	@f
109
	add	ecx, [edx + crash_item.len_blk]
116
	add	ecx, [edx + crash_item.len_blk]
-
 
117
    @@:
-
 
118
	add	[_len], ecx
-
 
119
 
-
 
120
	mov	eax, [edx + crash_item.len_size]
110
    @@:
121
	add	[_len], eax
-
 
122
 
-
 
123
	mov	eax, [hi]
-
 
124
	stdcall	[eax + crash_item.finalproc], [hi], [_msglen]
-
 
125
 
-
 
126
	mov	[final], 1
-
 
127
	jmp	.first
-
 
128
  .quit:
-
 
129
	mov	eax, [hi]
-
 
130
	stdcall [eax + crash_item.postproc], [eax + crash_item.len_out], [_hash]
-
 
131
	ret
-
 
132
endp
-
 
133
 
-
 
134
 
111
	add	[_len], ecx
135
crash._.md4_finalproc:
112
	mov	eax, [hi]
136
proc crash._.md5_finalproc _hi, _msglen
113
	mov	byte[edi], 0x80
137
	mov	byte[edi], 0x80
114
	add	edi, 1
138
	add	edi, 1
115
	sub	ecx, 1
139
	sub	ecx, 1
116
	mov	al, 0
140
	mov	al, 0
117
	rep	stosb
141
	rep	stosb
118
	push	ecx
142
	push	ecx
119
	xor	eax, eax
143
	xor	eax, eax
120
	mov	ecx, [hi]
144
	mov	ecx, [_hi]
121
	mov	ecx, [ecx + crash_item.len_size]
145
	mov	ecx, [ecx + crash_item.len_size]
122
	sub	ecx, 8			; FIXME for > 2^64 input length
146
	sub	ecx, 8			; FIXME for > 2^64 input length
123
	shr	ecx, 2
147
	shr	ecx, 2
124
	rep	stosd
148
	rep	stosd
125
	pop	ecx
149
	pop	ecx
126
	mov	eax, [_msglen]
150
	mov	eax, [_msglen]
127
	mov	eax, [eax]
151
	mov	eax, [eax]
128
	mov	edx, 8
152
	mov	edx, 8
-
 
153
	mul	edx
-
 
154
	mov	ecx, [_hi]
-
 
155
	mov	dword[edi], eax
-
 
156
	mov	dword[edi + 4], edx
-
 
157
	ret
-
 
158
endp
-
 
159
 
-
 
160
 
-
 
161
crash._.sha1_finalproc:
-
 
162
crash._.sha224_finalproc:
-
 
163
proc crash._.sha256_finalproc _hi, _msglen
-
 
164
	mov	byte[edi], 0x80
-
 
165
	add	edi, 1
-
 
166
	sub	ecx, 1
-
 
167
	mov	al, 0
-
 
168
	rep	stosb
-
 
169
	push	ecx
129
	mul	edx
170
	xor	eax, eax
-
 
171
	mov	ecx, [_hi]
-
 
172
	mov	ecx, [ecx + crash_item.len_size]
-
 
173
	sub	ecx, 8			; FIXME for > 2^64 input length
-
 
174
	shr	ecx, 2
-
 
175
	rep	stosd
-
 
176
	pop	ecx
-
 
177
	mov	eax, [_msglen]
130
	mov	ecx, [hi]
178
	mov	eax, [eax]
-
 
179
	mov	edx, 8
131
	cmp	[ecx + crash_item.endianness], LIBCRASH_ENDIAN_BIG
180
	mul	edx
132
	jne	@f
181
	mov	ecx, [_hi]
133
	bswap	eax
182
	bswap	eax
134
	bswap	edx
-
 
135
	xchg	eax, edx
183
	bswap	edx
136
    @@:
184
	xchg	eax, edx
-
 
185
	mov	dword[edi], eax
-
 
186
	mov	dword[edi + 4], edx
-
 
187
 
-
 
188
	ret
-
 
189
endp
-
 
190
 
-
 
191
 
-
 
192
crash._.sha384_finalproc:
-
 
193
proc crash._.sha512_finalproc _hi, _msglen
-
 
194
	mov	byte[edi], 0x80
-
 
195
	add	edi, 1
-
 
196
	sub	ecx, 1
-
 
197
	mov	al, 0
-
 
198
	rep	stosb
137
	mov	dword[edi], eax
199
	push	ecx
138
	mov	dword[edi + 4], edx
200
	xor	eax, eax
-
 
201
	mov	ecx, [_hi]
139
	mov	ecx, [hi]
202
	mov	ecx, [ecx + crash_item.len_size]
-
 
203
	sub	ecx, 8			; FIXME for > 2^64 input length
-
 
204
	shr	ecx, 2
-
 
205
	rep	stosd
140
	mov	eax, [ecx + crash_item.len_size]
206
	pop	ecx
141
	add	[_len], eax
207
	mov	eax, [_msglen]
142
	mov	[final], 1
208
	mov	eax, [eax]
143
	jmp	.first
209
	mov	edx, 8
-
 
210
	mul	edx
-
 
211
	mov	ecx, [_hi]
-
 
212
	bswap	eax
-
 
213
	bswap	edx
-
 
214
	xchg	eax, edx
-
 
215
	mov	dword[edi], eax
-
 
216
	mov	dword[edi + 4], edx
-
 
217
 
-
 
218
	ret
-
 
219
endp
-
 
220
 
-
 
221
 
-
 
222
crash._.sha3_224_finalproc:
144
  .quit:
223
crash._.sha3_256_finalproc:
-
 
224
crash._.sha3_384_finalproc:
-
 
225
proc crash._.sha3_512_finalproc _hi, _msglen
-
 
226
	mov	byte[edi], 0x01
-
 
227
	add	edi, 1
-
 
228
	sub	ecx, 1
-
 
229
	mov	eax, 0
145
	mov	eax, [hi]
230
	rep	stosb
146
	stdcall [eax + crash_item.postproc], [eax + crash_item.len_out], [_hash]
231
	or	byte[edi - 1], 0x80
Line -... Line 232...
-
 
232
	ret
147
	ret
233
endp
148
endp
234
 
149
 
235
 
Line -... Line 236...
-
 
236
crash._.md4_postprocess:
-
 
237
proc crash._.md5_postprocess _len_out, _hash
150
 
238
	ret
151
proc crash._.md4_md5_postprocess _len_out, _hash
239
endp
152
	ret
240
 
153
endp
241
 
154
 
242
crash._.sha1_postprocess:
155
 
243
crash._.sha224_postprocess:
Line 165... Line 253...
165
	jnz	@b
253
	jnz	@b
166
	ret
254
	ret
167
endp
255
endp
Line -... Line 256...
-
 
256
 
168
 
257
 
169
 
258
crash._.sha384_postprocess:
170
proc crash._.sha384_512_postprocess _len_out, _hash
259
proc crash._.sha512_postprocess _len_out, _hash
171
	mov	ecx, [_len_out]
260
	mov	ecx, [_len_out]
172
	mov	esi, [_hash]
261
	mov	esi, [_hash]
173
	mov	edi, esi
262
	mov	edi, esi
Line 185... Line 274...
185
	emms
274
	emms
186
	ret
275
	ret
187
endp
276
endp
Line -... Line 277...
-
 
277
 
-
 
278
 
-
 
279
crash._.sha3_224_postprocess:
-
 
280
crash._.sha3_256_postprocess:
-
 
281
crash._.sha3_384_postprocess:
-
 
282
proc crash._.sha3_512_postprocess _len_out, _hash
-
 
283
	emms
-
 
284
	ret
-
 
285
endp
188
 
286
 
189
 
287
 
190
proc crash.bin2hex _bin, _hex, _hid	; FIXME _hid param?
288
proc crash.bin2hex _bin, _hex, _hid	; FIXME _hid param?
191
	mov	eax, [_hid]
289
	mov	eax, [_hid]
192
	imul	eax, sizeof.crash_item
290
	imul	eax, sizeof.crash_item
Line 213... Line 311...
213
 
311
 
Line 214... Line 312...
214
 
312
 
215
crash._.bin2hex_table	db	'0123456789abcdef'
313
crash._.bin2hex_table	db	'0123456789abcdef'
216
 
314
 
217
; see crash_item struct for details
315
; see crash_item struct for details
218
crash._.table		dd	crash.md4,	crash._.md4_init,    crash._.md4_md5_postprocess,       4,  4,  64,  8, 0
316
crash._.table		dd	crash.md4,	crash._.md4_init,      crash._.md4_finalproc,      crash._.md4_postprocess,       4,  4,  64,  8
219
			dd	crash.md5,	crash._.md5_init,    crash._.md4_md5_postprocess,       4,  4,  64,  8, 0
317
			dd	crash.md5,	crash._.md5_init,      crash._.md5_finalproc,      crash._.md5_postprocess,       4,  4,  64,  8
220
			dd	crash.sha1,	crash._.sha1_init,   crash._.sha1_224_256_postprocess,  5,  5,  64,  8, 1
318
			dd	crash.sha1,	crash._.sha1_init,     crash._.sha1_finalproc,     crash._.sha1_postprocess,      5,  5,  64,  8
221
			dd	crash.sha256,	crash._.sha224_init, crash._.sha1_224_256_postprocess,  8,  7,  64,  8, 1
319
			dd	crash.sha256,	crash._.sha224_init,   crash._.sha224_finalproc,   crash._.sha224_postprocess,    8,  7,  64,  8
222
			dd	crash.sha256,	crash._.sha256_init, crash._.sha1_224_256_postprocess,  8,  8,  64,  8, 1
-
 
-
 
320
			dd	crash.sha256,	crash._.sha256_init,   crash._.sha256_finalproc,   crash._.sha256_postprocess,    8,  8,  64,  8
-
 
321
			dd	crash.sha512,	crash._.sha384_init,   crash._.sha384_finalproc,   crash._.sha384_postprocess,   16, 12, 128, 16
-
 
322
			dd	crash.sha512,	crash._.sha512_init,   crash._.sha512_finalproc,   crash._.sha512_postprocess,   16, 16, 128, 16
223
			dd	crash.sha512,	crash._.sha384_init, crash._.sha384_512_postprocess, 16, 12, 128, 16, 1
323
			dd	crash.sha3_224,	crash._.sha3_224_init, crash._.sha3_224_finalproc, crash._.sha3_224_postprocess, 50,  7, 144,  0
Line 224... Line 324...
224
			dd	crash.sha512,	crash._.sha512_init, crash._.sha384_512_postprocess, 16, 16, 128, 16, 1
324
			dd	crash.sha3_256,	crash._.sha3_256_init, crash._.sha3_256_finalproc, crash._.sha3_256_postprocess, 50,  8, 136,  0
225
 
325
			dd	crash.sha3_384,	crash._.sha3_384_init, crash._.sha3_384_finalproc, crash._.sha3_384_postprocess, 50, 12, 104,  0
226
crash._.crc_init	dd	0xffffffff
326
			dd	crash.sha3_512,	crash._.sha3_512_init, crash._.sha3_512_finalproc, crash._.sha3_512_postprocess, 50, 16,  72,  0
Line 237... Line 337...
237
				0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
337
				0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
Line 238... Line 338...
238
 
338
 
239
crash._.sha512_init	dq	0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\
339
crash._.sha512_init	dq	0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,\
Line -... Line 340...
-
 
340
				0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179
-
 
341
 
-
 
342
crash._.sha3_512_init:
-
 
343
crash._.sha3_384_init:
-
 
344
crash._.sha3_256_init:
240
				0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179
345
crash._.sha3_224_init	dq	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
241
 
346
 
242
crash._.sha256_table	dd	0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
347
crash._.sha256_table	dd	0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
243
				0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
348
				0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
244
				0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
349
				0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
Line 267... Line 372...
267
				0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178,\
372
				0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178,\
268
				0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,\
373
				0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,\
269
				0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\
374
				0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,\
270
				0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817
375
				0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817
Line -... Line 376...
-
 
376
 
-
 
377
crash._.sha3_round	dq	0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000,\
-
 
378
				0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,\
-
 
379
				0x000000000000008A, 0x0000000000000088, 0x0000000080008009, 0x000000008000000A,\
-
 
380
				0x000000008000808B, 0x800000000000008B, 0x8000000000008089, 0x8000000000008003,\
-
 
381
				0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,\
-
 
382
				0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
Line 271... Line 383...
271
 
383
 
272
 
384
 
Line 273... Line 385...
273
align 4
385
align 4
274
@EXPORT:
386
@EXPORT:
275
 
387
 
276
export                                   \
388
export                                   \
Line 277... Line -...
277
    lib_init        , 'lib_init'       , \
-
 
278
    crash.hash      , 'crash_hash'     , \
-