File: sha1opt.i586.asm

package info (click to toggle)
beecrypt 2.2.0-pre1-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,820 kB
  • ctags: 1,325
  • sloc: ansic: 12,215; sh: 9,073; asm: 2,715; makefile: 80
file content (292 lines) | stat: -rw-r--r-- 7,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#
# sha1opt.i586.asm
#
# Assembler optimized SHA-1 routines for Intel Pentium processors
#
# Compile target is Metrowerks CodeWarrior Pro 5 for Windows
#
# Copyright (c) 2000 Virtual Unlimited B.V.
#
# Author: Bob Deblier <bob@virtualunlimited.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

K00	.equ	0x5a827999
K20	.equ	0x6ed9eba1
K40	.equ	0x8f1bbcdc
K60	.equ	0xca62c1d6

PARAM_H			.equ	0
PARAM_DATA		.equ	20
PARAM_OFFSET	.equ	352

subround1:	.macro b,c,d,e,w
	mov ecx,c
	mov ebx,b
	mov edx,d
	rol eax,5
	xor ecx,edx
	add eax,e
	and ecx,ebx
	add eax,K00
	ror ebx,2
	add eax,w
	xor ecx,edx
	mov b,ebx
	add eax,ecx
	mov e,eax
	.endm

subround2:	.macro b,c,d,e,w
	mov ecx,c
	mov ebx,b
	rol eax,5
	xor ecx,ebx
	add eax,e
	xor ecx,d
	add eax,K20
	ror ebx,2
	add eax,w
	mov b,ebx
	add eax,ecx
	mov e,eax
	.endm

subround3:	.macro b,c,d,e,w
	mov ecx,c
	rol eax,5
	mov ebx,b
	mov edx,ecx
	add eax,e
	or ecx,ebx # (b|c)
	and edx,ebx # (b&c)
	and ecx,d # (b|c)&d
	add eax,K40
	or ecx,edx
	add eax,w
	ror ebx,2
	add eax,ecx
	mov b,ebx
	mov e,eax
	.endm

subround4:	.macro b,c,d,e,w
	mov ecx,c
	mov ebx,b
	rol eax,5
	xor ecx,ebx
	add eax,e
	xor ecx,d
	add eax,K60
	ror ebx,2
	add eax,w
	mov b,ebx
	add eax,ecx
	mov e,eax
	.endm

	.text

	.align	8
	.globl _sha1Process

_sha1Process:
	push edi
	push esi
	push ebx
	push ebp
	# allocate local variables
	mov esi,[esp+20]
	sub esp,20
	lea edi,[esi+PARAM_DATA]
	mov ebp,esp

	mov ecx,4
@loads:
	mov edx,[esi+ecx*4]
	mov [ebp+ecx*4],edx
	dec ecx
	jns @loads

	mov ecx,15
	xor eax,eax

	.align 4
@swaps:
	mov edx,[edi+ecx*4]
	bswap edx
	mov	[edi+ecx*4],edx
	dec ecx
	jns @swaps

	lea edi,[esi+PARAM_DATA]
	mov [esi+PARAM_OFFSET],al
	mov ecx,16

	.align 4
@xors:
	mov eax,[edi+52]
	mov ebx,[edi+56]
	xor eax,[edi+32]
	xor ebx,[edi+36]
	xor eax,[edi+ 8]
	xor ebx,[edi+12]
	xor eax,[edi   ]
	xor ebx,[edi+ 4]
	rol eax,1
	rol ebx,1
	mov [edi+64],eax
	mov [edi+68],ebx
	mov eax,[edi+60]
	mov ebx,[edi+64]
	xor eax,[edi+40]
	xor ebx,[edi+44]
	xor eax,[edi+16]
	xor ebx,[edi+20]
	xor eax,[edi+ 8]
	xor ebx,[edi+12]
	rol eax,1
	rol ebx,1
	mov [edi+72],eax
	mov [edi+76],ebx
	add edi,16
	dec ecx
	jnz @xors

	mov edi,PARAM_DATA

	# to optimize further, use esi only, and store the add constant into edi
	# will make code smaller and faster
	
@round01to20:
	mov eax,[ebp]
	subround1 [ebp+4],[ebp+8],[ebp+12],[ebp+16],[esi+edi]
	subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	
@round21to40:
	subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20

@round41to60:
	subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20

@round61to80:
	subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	add edi,20
	subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi]
	subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4]
	subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8]
	subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12]
	subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16]
	# add edi,20

	mov ecx,4

@adds:
	mov eax,[ebp+ecx*4]
	add [esi+ecx*4],eax
	dec ecx
	jns @adds

	add esp,20
	pop ebp
	pop ebx
	pop esi
	pop edi
	ret