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
proc crash.sha1.f
18
proc crash.sha1.f
2
	push	ebx ecx edx
19
	push	ebx ecx edx
3
	xor	ecx, edx
20
	xor	ecx, edx
4
	and	ebx, ecx
21
	and	ebx, ecx
5
	xor	ebx, edx
22
	xor	ebx, edx
Line 27... Line 44...
27
	or	esi, ebx
44
	or	esi, ebx
28
	pop	edx ecx ebx
45
	pop	edx ecx ebx
29
	ret
46
	ret
30
endp
47
endp
Line -... Line 48...
-
 
48
 
-
 
49
macro crash.sha1.round f, k, c
-
 
50
{
-
 
51
	mov	esi, eax
-
 
52
	rol	esi, 5
-
 
53
	mov	[temp], esi
-
 
54
	call	f
-
 
55
 
-
 
56
	add	esi, edi
-
 
57
	add	[temp], esi
-
 
58
	mov	esi, [w + (c)*4]
-
 
59
	add	esi, k
-
 
60
	add	[temp], esi
-
 
61
 
-
 
62
	mov	edi, edx
-
 
63
	mov	edx, ecx
-
 
64
	mov	ecx, ebx
-
 
65
	rol	ecx, 30
-
 
66
	mov	ebx, eax
-
 
67
	mov	eax, [temp]
-
 
68
}
Line 31... Line 69...
31
 
69
 
32
 
70
 
33
proc crash.sha1 _sha1, _data, _len, _callback, _msglen
-
 
34
locals
71
proc crash.sha1 _sha1, _data
35
	final	rd 1
-
 
36
	temp	rd 1
-
 
37
	counter	rd 1
-
 
38
	summand	rd 1
72
locals
39
	shafunc	rd 1
73
	temp	 rd 1
40
	w	rd 80
-
 
41
endl
-
 
42
	mov	[final], 0
-
 
43
  .first:
-
 
44
	mov	eax, [_msglen]
-
 
45
	mov	ecx, [_len]
-
 
46
	add	[eax], ecx
-
 
47
	mov	esi, [_data]
-
 
48
	test	ecx, ecx
-
 
49
	jz	.callback
-
 
50
  .begin:
-
 
51
	sub	[_len], 64
-
 
52
	jnc	@f
-
 
53
	add	[_len], 64
-
 
54
	jmp	.endofblock
74
	w	 rd 80
55
    @@:
75
endl
56
	lea	edi, [w]
76
	lea	edi, [w]
57
	xor	ecx, ecx
77
	xor	ecx, ecx
58
    @@:
78
    @@:
Line 82... Line 102...
82
	mov	edx, [edi + 0x0c]
102
	mov	edx, [edi + 0x0c]
83
	mov	edi, [edi + 0x10]
103
	mov	edi, [edi + 0x10]
Line 84... Line 104...
84
 
104
 
Line 85... Line 105...
85
	push	esi
105
	push	esi
86
 
106
 
87
	mov	[counter], 0
-
 
88
	mov	[summand], 0x5a827999
-
 
89
	mov	[shafunc], crash.sha1.f
-
 
90
    @@:
-
 
91
	mov	esi, eax
-
 
92
	rol	esi, 5
-
 
93
	mov	[temp], esi
-
 
94
	call	[shafunc]
107
repeat 20
95
 
-
 
96
	add	esi, edi
-
 
97
	add	[temp], esi
-
 
98
	mov	esi, [counter]
-
 
99
	mov	esi, [w + esi*4]
-
 
100
	add	esi, [summand]
108
	crash.sha1.round	crash.sha1.f, 0x5a827999, %-1
101
	add	[temp], esi
-
 
102
 
-
 
103
	mov	edi, edx
-
 
104
	mov	edx, ecx
109
end repeat
105
	mov	ecx, ebx
-
 
106
	rol	ecx, 30
-
 
107
	mov	ebx, eax
-
 
108
	mov	eax, [temp]
-
 
109
 
-
 
110
	add	[counter], 1
-
 
111
	cmp	[counter], 20
-
 
112
	jne	@b
110
 
113
 
-
 
114
	mov	[summand], 0x6ed9eba1
-
 
115
	mov	[shafunc], crash.sha1.g
-
 
116
    @@:
-
 
117
	mov	esi, eax
-
 
118
	rol	esi, 5
-
 
119
	mov	[temp], esi
-
 
120
	call	dword[shafunc]
111
repeat 20
121
 
-
 
122
	add	esi, edi
-
 
123
	add	[temp], esi
-
 
124
	mov	esi, [counter]
-
 
125
	mov	esi, [w + esi*4]
-
 
126
	add	esi, [summand]
112
	crash.sha1.round	crash.sha1.g, 0x6ed9eba1, %-1+20
127
	add	[temp], esi
-
 
128
 
-
 
129
	mov	edi, edx
-
 
130
	mov	edx, ecx
113
end repeat
131
	mov	ecx, ebx
-
 
132
	rol	ecx, 30
-
 
133
	mov	ebx, eax
-
 
134
	mov	eax, [temp]
-
 
135
 
-
 
136
	add	[counter], 1
-
 
137
	cmp	[counter], 40
-
 
138
	jne	@b
114
 
139
 
-
 
140
	mov	[summand], 0x8f1bbcdc
-
 
141
	mov	[shafunc], crash.sha1.h
-
 
142
    @@:
-
 
143
	mov	esi, eax
-
 
144
	rol	esi, 5
-
 
145
	mov	[temp], esi
-
 
146
	call	dword[shafunc]
115
repeat 20
147
 
-
 
148
	add	esi, edi
-
 
149
	add	[temp], esi
-
 
150
	mov	esi, [counter]
-
 
151
	mov	esi, [w + esi*4]
-
 
152
	add	esi, [summand]
116
	crash.sha1.round	crash.sha1.h, 0x8f1bbcdc, %-1+40
153
	add	[temp], esi
-
 
154
 
-
 
155
	mov	edi, edx
-
 
156
	mov	edx, ecx
117
end repeat
157
	mov	ecx, ebx
-
 
158
	rol	ecx, 30
-
 
159
	mov	ebx, eax
-
 
160
	mov	eax, [temp]
-
 
161
 
-
 
162
	add	[counter], 1
-
 
163
	cmp	[counter], 60
-
 
164
	jne	@b
118
 
165
 
-
 
166
	mov	[summand], 0xca62c1d6
-
 
167
	mov	[shafunc], crash.sha1.g
-
 
168
    @@:
-
 
169
	mov	esi, eax
-
 
170
	rol	esi, 5
-
 
171
	mov	[temp], esi
-
 
172
	call	dword[shafunc]
-
 
173
 
-
 
174
	add	esi, edi
-
 
175
	add	[temp], esi
-
 
176
	mov	esi, [counter]
-
 
177
	mov	esi, [w + esi*4]
-
 
178
	add	esi, [summand]
-
 
179
	add	[temp], esi
-
 
180
 
-
 
181
	mov	edi, edx
-
 
182
	mov	edx, ecx
-
 
183
	mov	ecx, ebx
119
repeat 20
184
	rol	ecx, 30
-
 
185
	mov	ebx, eax
-
 
186
	mov	eax, [temp]
-
 
187
 
-
 
188
	add	[counter], 1
-
 
Line 189... Line 120...
189
	cmp	[counter], 80
120
	crash.sha1.round	crash.sha1.g, 0xca62c1d6, %-1+60
Line 190... Line 121...
190
	jne	@b
121
end repeat
191
 
122
 
Line 197... Line 128...
197
	add	[edi + 0x04], ebx
128
	add	[edi + 0x04], ebx
198
	add	[edi + 0x08], ecx
129
	add	[edi + 0x08], ecx
199
	add	[edi + 0x0c], edx
130
	add	[edi + 0x0c], edx
200
	mov	eax, [temp]
131
	mov	eax, [temp]
201
	add	[edi + 0x10], eax
132
	add	[edi + 0x10], eax
202
	jmp	.begin
-
 
203
  .endofblock:
-
 
204
	cmp	[final], 1
-
 
205
	je	.quit
-
 
206
 
-
 
207
  .callback:
-
 
208
	mov	eax, [_callback]
-
 
209
	test	eax, eax
-
 
210
	jz	@f
-
 
211
	call	eax
-
 
212
	test	eax, eax
-
 
213
	jz	@f
-
 
214
	mov	[_len], eax
-
 
215
	jmp	.first
-
 
216
    @@:
-
 
Line 217... Line -...
217
 
-
 
218
	mov	edi, [_data]
-
 
219
	mov	ecx, [_len]
-
 
220
	rep	movsb
-
 
221
	mov	eax, [_msglen]
-
 
222
	mov	eax, [eax]
-
 
223
	and	eax, 63
-
 
224
	mov	ecx, 56
-
 
225
	sub	ecx, eax
-
 
226
	ja	@f
-
 
227
	add	ecx, 64
-
 
228
    @@:
-
 
229
	add	[_len], ecx
-
 
230
	mov	byte[edi], 0x80
-
 
231
	add	edi, 1
-
 
232
	sub	ecx, 1
-
 
233
	mov	al, 0
-
 
234
	rep	stosb
-
 
235
	mov	eax, [_msglen]
-
 
236
	mov	eax, [eax]
-
 
237
	mov	edx, 8
-
 
238
	mul	edx
-
 
239
	bswap	eax
-
 
240
	bswap	edx
-
 
241
	mov	dword[edi], edx
-
 
242
	mov	dword[edi + 4], eax
-
 
243
	add	[_len], 8
-
 
244
	mov	[final], 1
-
 
245
	jmp	.first
-
 
246
  .quit:
-
 
247
	mov	esi, [_sha1]
-
 
248
	mov	edi, esi
-
 
249
	mov	ecx, 5
-
 
250
    @@:
-
 
251
	lodsd
-
 
252
	bswap	eax
-
 
253
	stosd
-
 
254
	sub	ecx, 1
-
 
255
	jnz	@b
133
 
256
	ret
134
	ret