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
	mov	eax, [y]
20
	mov	eax, [y]
4
	xor	eax, [z]
21
	xor	eax, [z]
5
	and	eax, [x]
22
	and	eax, [x]
Line 118... Line 135...
118
	mov	edi, [w + (n)*4]
135
	mov	edi, [w + (n)*4]
119
	crash.sha256.round a, b, c, d, e, f, g, h, (crash._.sha256_table + (n+16*rep_num)*4)
136
	crash.sha256.round a, b, c, d, e, f, g, h, (crash._.sha256_table + (n+16*rep_num)*4)
120
}
137
}
Line 121... Line 138...
121
 
138
 
122
 
139
 
123
proc crash.sha256 _sha256, _data, _len, _callback, _msglen
-
 
124
locals
140
proc crash.sha256 _sha256, _data
125
	final	rd 1
141
locals
126
	w	rd 64
142
	w	rd 64
127
	A	rd 1
143
	A	rd 1
128
	B	rd 1
144
	B	rd 1
129
	C	rd 1
145
	C	rd 1
130
	D	rd 1
146
	D	rd 1
131
	E	rd 1
147
	E	rd 1
132
	F	rd 1
148
	F	rd 1
133
	G	rd 1
149
	G	rd 1
134
	H	rd 1
-
 
135
endl
-
 
136
	mov	[final], 0
-
 
137
  .first:
-
 
138
	mov	eax, [_msglen]
-
 
139
	mov	ecx, [_len]
-
 
140
	add	[eax], ecx
-
 
141
	mov	esi, [_data]
-
 
142
	test	ecx, ecx
-
 
143
	jz	.callback
-
 
144
  .begin:
-
 
145
	sub	[_len], 64
-
 
146
	jnc	@f
-
 
147
	add	[_len], 64
-
 
148
	jmp	.endofblock
150
	H	rd 1
149
    @@:
151
endl
150
	mov	edi, [_sha256]
152
	mov	edi, [_sha256]
151
	mov	eax, [edi + 0x00]
153
	mov	eax, [edi + 0x00]
152
	mov	[A], eax
154
	mov	[A], eax
Line 217... Line 219...
217
	mov	eax, [G]
219
	mov	eax, [G]
218
	add	[edi + 0x18], eax
220
	add	[edi + 0x18], eax
219
	mov	eax, [H]
221
	mov	eax, [H]
220
	add	[edi + 0x1c], eax
222
	add	[edi + 0x1c], eax
221
	add	esi, 64
223
	add	esi, 64
222
	jmp	.begin
-
 
223
  .endofblock:
-
 
224
	cmp	[final], 1
-
 
225
	je	.quit
-
 
226
 
224
 
227
  .callback:
-
 
228
	mov	eax, [_callback]
-
 
229
	test	eax, eax
-
 
230
	jz	@f
-
 
231
	call	eax
-
 
232
	test	eax, eax
-
 
233
	jz	@f
-
 
234
	mov	[_len], eax
-
 
235
	jmp	.first
-
 
236
    @@:
-
 
237
 
-
 
238
	mov	edi, [_data]
-
 
239
	mov	ecx, [_len]
-
 
240
	rep	movsb
-
 
241
	mov	eax, [_msglen]
-
 
242
	mov	eax, [eax]
-
 
243
	and	eax, 63
-
 
244
	mov	ecx, 56
-
 
245
	sub	ecx, eax
-
 
246
	ja	@f
-
 
247
	add	ecx, 64
-
 
248
    @@:
-
 
249
	add	[_len], ecx
-
 
250
	mov	byte[edi], 0x80
-
 
251
	add	edi, 1
-
 
252
	sub	ecx, 1
-
 
253
	mov	al, 0
-
 
254
	rep	stosb
-
 
255
	mov	eax, [_msglen]
-
 
256
	mov	eax, [eax]
-
 
257
	mov	edx, 8
-
 
258
	mul	edx
-
 
259
	bswap	eax
-
 
260
	bswap	edx
-
 
261
	mov	dword[edi], edx
-
 
262
	mov	dword[edi + 4], eax
-
 
263
	add	[_len], 8
-
 
264
	mov	[final], 1
-
 
265
	jmp	.first
-
 
266
  .quit:
-
 
267
	mov	esi, [_sha256]
-
 
268
	mov	edi, esi
-
 
269
	mov	ecx, 8
-
 
270
    @@:
-
 
271
	lodsd
-
 
272
	bswap	eax
-
 
273
	stosd
-
 
274
	sub	ecx, 1
-
 
275
	jnz	@b
-
 
276
	ret
225
	ret
277
endp
226
endp