Subversion Repositories Kolibri OS

Rev

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

Rev 3115 Rev 3431
Line -... Line 1...
-
 
1
;    libcrash -- cryptographic hash functions
-
 
2
;
-
 
3
;    Copyright (C) 2012-2013 Ivan Baravy (dunkaist)
-
 
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.
-
 
9
;
-
 
10
;    This program is distributed in the hope that it will be useful,
-
 
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
 
13
;    GNU General Public License for more details.
-
 
14
;
-
 
15
;    You should have received a copy of the GNU General Public License
-
 
16
;    along with this program.  If not, see .
-
 
17
 
1
macro chn x, y, z
18
macro chn x, y, z
2
{
19
{
3
	movq	mm0, [y]
20
	movq	mm0, [y]
4
	pxor	mm0, [z]
21
	pxor	mm0, [z]
5
	pand	mm0, [x]
22
	pand	mm0, [x]
Line 156... Line 173...
156
	movq	mm5, [w + (n)*8]
173
	movq	mm5, [w + (n)*8]
157
	crash.sha512.round a, b, c, d, e, f, g, h, (crash._.sha512_table + (n+16*rep_num)*8)
174
	crash.sha512.round a, b, c, d, e, f, g, h, (crash._.sha512_table + (n+16*rep_num)*8)
158
}
175
}
Line 159... Line 176...
159
 
176
 
160
 
177
 
161
proc crash.sha512 _sha512, _data, _len, _callback, _msglen
-
 
162
locals
178
proc crash.sha512 _sha512, _data
163
	final	rd 1
179
locals
164
	w	rq 80
180
	w	rq 80
165
	A	rq 1
181
	A	rq 1
166
	B	rq 1
182
	B	rq 1
Line 170... Line 186...
170
	F	rq 1
186
	F	rq 1
171
	G	rq 1
187
	G	rq 1
172
	H	rq 1
188
	H	rq 1
173
	temp	rq 1
189
	temp	rq 1
174
endl
190
endl
175
	mov	[final], 0
-
 
176
  .first:
-
 
177
	mov	eax, [_msglen]
-
 
178
	mov	ecx, [_len]
-
 
179
	add	[eax], ecx
-
 
180
	mov	esi, [_data]
-
 
181
	test	ecx, ecx
-
 
182
	jz	.callback
-
 
183
  .begin:
-
 
184
	sub	[_len], 128
-
 
185
	jnc	@f
-
 
186
	add	[_len], 128
-
 
187
	jmp	.endofblock
-
 
188
    @@:
-
 
189
	mov	edi, [_sha512]
191
	mov	edi, [_sha512]
190
	movq	mm0, [edi + 0x00]
192
	movq	mm0, [edi + 0x00]
191
	movq	[A], mm0
193
	movq	[A], mm0
192
	movq	mm0, [edi + 0x08]
194
	movq	mm0, [edi + 0x08]
193
	movq	[B], mm0
195
	movq	[B], mm0
Line 266... Line 268...
266
	movq	[edi + 0x30], mm0
268
	movq	[edi + 0x30], mm0
267
	movq	mm0, [H]
269
	movq	mm0, [H]
268
	paddq	mm0, [edi + 0x38]
270
	paddq	mm0, [edi + 0x38]
269
	movq	[edi + 0x38], mm0
271
	movq	[edi + 0x38], mm0
270
	add	esi, 128
272
	add	esi, 128
271
	jmp	.begin
-
 
272
  .endofblock:
-
 
273
	cmp	[final], 1
-
 
274
	je	.quit
-
 
275
 
273
 
276
  .callback:
-
 
277
	mov	eax, [_callback]
-
 
278
	test	eax, eax
-
 
279
	jz	@f
-
 
280
	call	eax
-
 
281
	test	eax, eax
-
 
282
	jz	@f
-
 
283
	mov	[_len], eax
-
 
284
	jmp	.first
-
 
285
    @@:
-
 
286
 
-
 
287
	mov	edi, [_data]
-
 
288
	mov	ecx, [_len]
-
 
289
	rep	movsb
-
 
290
	mov	eax, [_msglen]
-
 
291
	mov	eax, [eax]
-
 
292
	and	eax, 127
-
 
293
	mov	ecx, 112
-
 
294
	sub	ecx, eax
-
 
295
	ja	@f
-
 
296
	add	ecx, 128
-
 
297
    @@:
-
 
298
	add	[_len], ecx
-
 
299
	mov	byte[edi], 0x80
-
 
300
	add	edi, 1
-
 
301
	sub	ecx, 1
-
 
302
	mov	al, 0
-
 
303
	rep	stosb
-
 
304
	xor	eax, eax
-
 
305
	stosd
-
 
306
	stosd
-
 
307
	mov	eax, [_msglen]
-
 
308
	mov	eax, [eax]
-
 
309
	mov	edx, 8
-
 
310
	mul	edx
-
 
311
	bswap	eax
-
 
312
	bswap	edx
-
 
313
	mov	dword[edi], edx
-
 
314
	mov	dword[edi + 4], eax
-
 
315
	add	[_len], 16
-
 
316
	mov	[final], 1
-
 
317
	jmp	.first
-
 
318
  .quit:
-
 
319
	mov	esi, [_sha512]
-
 
320
	mov	edi, esi
-
 
321
	mov	ecx, 8
-
 
322
    @@:
-
 
323
	lodsd
-
 
324
	bswap	eax
-
 
325
	mov	ebx, eax
-
 
326
	lodsd
-
 
327
	bswap	eax
-
 
328
	stosd
-
 
329
	mov	eax, ebx
-
 
330
	stosd
-
 
331
	sub	ecx, 1
-
 
332
	jnz	@b
-
 
333
	emms
-
 
334
	ret
274
	ret
335
endp
275
endp