-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrsa386.s
406 lines (357 loc) · 5.7 KB
/
rsa386.s
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*
RSA386.s - processor-specific C library routines for RSAEURO
Copyright (c) J.S.A.Kapp 1994 - 1996.
RSAEURO - RSA Library compatible with RSAREF 2.0.
All functions prototypes are the Same as for RSAREF.
To aid compatiblity the source and the files follow the
same naming comventions that RSAREF uses. This should aid
direct importing to your applications.
This library is legal everywhere outside the US. And should
NOT be imported to the US and used there.
Secure Standard Library Routines, i386 assembler versions.
These are only applicable if NN_DIGIT equal to a 32-bit word.
Revision history
0.90 First revision, this is code designed to run on a i386
processor when compiled using gcc. Support for R_STDLIB.C
functions.
0.91 Next revision, this added code for a selection of NN.C
functions to improve the speed on the multi-precision math
routines. Functions added:
_NN_Digits, _NN_Assign,
_NN_Add, _NN_Decode,
_NN_Encode, _NN_Sub,
_NN_Cmp
Some speed increases where noticed with the addition of
these functions.
*/
/* Multipresecion Math Routines */
.align 2
.globl _NN_Cmp
_NN_Cmp:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 16(%ebp), %ecx
testl %ecx, %ecx
je ncmp1
ncmp5:
decl %ecx
leal 0(,%ecx,4),%eax
movl 8(%ebp),%edx
movl (%edx,%eax),%eax
leal 0(,%ecx,4),%edx
movl 12(%ebp),%ebx
cmpl %eax,(%ebx,%edx)
jae ncmp2
movl $1,%eax
jmp ncmp3
.align 2, 0x90
ncmp2:
jbe ncmp4
movl $-1,%eax
jmp ncmp3
.align 2, 0x90
ncmp4:
cmpl $0, %ecx
jne ncmp5
ncmp1:
xorl %eax,%eax
ncmp3:
movl -4(%ebp),%ebx
leave
ret
.align 2
.globl _NN_Zero
_NN_Zero:
pushl %ebp
movl %esp,%ebp
pushl %esi
movl 12(%ebp), %ecx
testl %ecx,%ecx
je nzero1
movl 8(%ebp), %esi
xorl %eax,%eax
nzero3:
cmpl $0, (%esi)
jne nzero2
addl $4, %esi
loop nzero3
nzero1:
inc %eax
nzero2:
popl %esi
leave
ret
.align 2
.globl _NN_Digits
_NN_Digits:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %ecx
testl %ecx,%ecx
je digit1
movl 8(%ebp), %edx
digit3:
dec %ecx
cmpl $0, (%edx, %ecx, 4)
jnz digit2
cmp $-1, %ecx
jnz digit3
digit2:
movl %ecx, %eax
inc %eax
digit1:
leave
ret
.align 2
.globl _NN_Assign
_NN_Assign:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %ecx
testl %ecx,%ecx
je assign1
pushl %esi
pushl %edi
movl 8(%ebp), %edi
movl 12(%ebp), %esi
cld
rep
movsl
popl %edi
popl %esi
assign1:
leave
ret
.align 2
.globl _NN_AssignZero
_NN_AssignZero:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %ecx
testl %ecx,%ecx
je zero1
pushl %edi
movl 8(%ebp), %edi
xorl %eax, %eax
rep
stosl
popl %edi
zero1:
leave
ret
.align 2
.globl _NN_Add
_NN_Add:
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
pushl %ebx
xorl %eax,%eax
movl 20(%ebp),%edx
cmpl %edx,%eax
jae add1
movl 8(%ebp),%ebx
movl 16(%ebp),%ecx
movl 12(%ebp),%esi
leal (%ebx,%edx,4),%edi
add4:
movl %eax,%edx
addl (%esi),%edx
cmpl %eax,%edx
jae add2
movl (%ecx),%edx
jmp add3
add2:
addl (%ecx),%edx
cmpl %edx,(%ecx)
seta %al
andl $255,%eax
add3:
movl %edx,(%ebx)
addl $4,%ebx
addl $4,%ecx
addl $4,%esi
cmpl %edi,%ebx
jb add4
add1:
leal -12(%ebp),%esp
popl %ebx
popl %esi
popl %edi
leave
ret
.align 2
.globl _NN_Decode
_NN_Decode:
pushl %ebp
movl %esp,%ebp
subl $8,%esp
pushl %edi
pushl %esi
pushl %ebx
movl $0,-8(%ebp)
movl 20(%ebp),%edx
decl %edx
js dec1
movl 8(%ebp),%edi
movl %edi,-4(%ebp)
dec4:
xorl %ebx,%ebx
xorl %ecx,%ecx
testl %edx,%edx
jl dec2
dec3:
movl 16(%ebp),%esi
movzbl (%edx,%esi),%eax
sall %cl,%eax
orl %eax,%ebx
decl %edx
addl $8,%ecx
testl %edx,%edx
jl dec2
cmpl $31,%ecx
jbe dec3
dec2:
movl -4(%ebp),%edi
movl %ebx,(%edi)
addl $4,-4(%ebp)
incl -8(%ebp)
testl %edx,%edx
jge dec4
dec1:
movl 12(%ebp),%esi
cmpl %esi,-8(%ebp)
jae dec5
movl -8(%ebp),%edi
movl 8(%ebp),%esi
leal (%esi,%edi,4),%eax
movl 12(%ebp),%edi
leal (%esi,%edi,4),%edx
dec6:
movl $0,(%eax)
addl $4,%eax
cmpl %edx,%eax
jb dec6
dec5:
leal -20(%ebp),%esp
popl %ebx
popl %esi
popl %edi
leave
ret
.align 2
.globl _NN_Encode
_NN_Encode:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
pushl %edi
pushl %esi
pushl %ebx
movl 8(%ebp),%edi
movl 20(%ebp),%eax
movl 12(%ebp),%edx
decl %edx
testl %eax,%eax
je enc1
movl 16(%ebp),%ebx
leal (%ebx,%eax,4),%eax
movl %eax,-4(%ebp)
enc4:
movl (%ebx),%esi
xorl %ecx,%ecx
testl %edx,%edx
jl enc2
enc3:
movl %esi,%eax
shrl %cl,%eax
movb %al,(%edx,%edi)
decl %edx
addl $8,%ecx
testl %edx,%edx
jl enc2
cmpl $31,%ecx
jbe enc3
enc2:
addl $4,%ebx
cmpl %ebx,-4(%ebp)
ja enc4
jmp enc1
enc5:
movb $0,(%edx,%edi)
decl %edx
enc1:
testl %edx,%edx
jge enc5
leal -16(%ebp),%esp
popl %ebx
popl %esi
popl %edi
leave
ret
/* R_STDLIB Assembler Routines */
.align 2
.globl _R_memcpy
_R_memcpy:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %ecx
testl %ecx,%ecx
je cpyexit
pushl %esi
pushl %edi
movl 8(%ebp), %edi
movl 12(%ebp), %esi
cld
rep
movsb
cld
popl %edi
popl %esi
cpyexit:
leave
ret
.align 2
.globl _R_memcmp
_R_memcmp:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %ecx
testl %ecx,%ecx
je cmpexit
pushl %esi
pushl %edi
movl 8(%ebp), %edi
movl 12(%ebp), %esi
cld
rep
cmpsb
xor %eax, %eax
cwtl
movb -1(%esi), %al
movb -1(%edi), %dl
subb %dl, %al
popl %edi
popl %esi
cmpexit:
leave
ret
.align 2
.globl _R_memset
_R_memset:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %ecx
testl %ecx,%ecx
je setexit
pushl %edi
movl 8(%ebp), %edi
movl 12(%ebp), %eax
rep
stosb
popl %edi
setexit:
leave
ret