OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / libdes / asm / coldfire_des.S
1         .file   "des_encrypt2.s"
2         .version        "01.01"
3 .text
4
5 /****************************************************************************/
6
7 .align  16
8 .globl des_encrypt3
9
10 des_encrypt3:
11         lea %sp@(-52),%sp
12         moveml %d2-%d7/%a2-%fp, (%sp)
13
14         move.l 56(%sp),%a3
15         move.l (%a3),%d5                /* l = data[0] */
16         move.l 4(%a3),%d4               /* r = data[1] */
17
18         move.l %d4,%d0                  /* tt = ((r>>4)^l)&0x0f0f0f0fL, */
19         lsr.l #4,%d0
20         eor.l %d5,%d0
21         and.l #252645135,%d0
22
23         eor.l %d0,%d5                   /* l ^= tt, */
24
25         lsl.l #4,%d0                    /* r ^= (tt<<4); */
26         eor.l %d0,%d4
27
28
29         move.l %d5,%d0                  /* tt = ((l>>16)^r)&0x0000ffffL, */
30         clr.w %d0
31         swap %d0
32         eor.l %d4,%d0
33         and.l #65535,%d0
34
35         eor.l %d0,%d4                   /* r ^= tt, */
36
37         swap %d0
38         clr.w %d0
39         eor.l %d0,%d5                   /* l ^= (tt<<16); */
40
41
42         move.l %d4,%d0                  /* tt = ((r>>2)^l)&0x33333333L, */
43         lsr.l #2,%d0
44         eor.l %d5,%d0
45         and.l #858993459,%d0
46
47         eor.l %d0,%d5                   /* l ^= tt, */
48
49         lsl.l #2,%d0                    /* r ^= (tt<<2); */
50         eor.l %d0,%d4
51
52
53         move.l %d5,%d0                  /* tt = ((l>>8)^r)&0x00ff00ff, */
54         lsr.l #8,%d0
55         eor.l %d4,%d0
56         and.l #16711935,%d0
57
58         eor.l %d0,%d4                   /* r ^= tt, */
59
60         lsl.l #8,%d0                    /* l ^= (tt<<8); */
61         eor.l %d0,%d5
62
63
64         move.l %d4,%d0                  /* tt = ((r>>1)^l)&0x55555555, */
65         lsr.l #1,%d0
66         eor.l %d5,%d0
67         and.l #1431655765,%d0
68
69         eor.l %d0,%d5                   /* l ^= tt, */
70
71         add.l %d0,%d0                   /* r ^= (tt<<1); */
72         eor.l %d0,%d4
73
74         /* ----------------------------------- */
75         /* ASSUME: r=data[0]=%d5, l=data[1]=%d4 */
76
77         moveq.l #29,%d7
78         move.l %d5,%d0                  /* r=ROTATE(r,29)&0xffffffffL; */
79         lsr.l %d7,%d0
80         lsl.l #3,%d5
81         add.l %d0,%d5
82
83         move.l %d4,%d0                  /* l=ROTATE(l,29)&0xffffffffL; */
84         lsr.l %d7,%d0
85         lsl.l #3,%d4
86         add.l %d0,%d4
87
88         lea des_SPtrans,%a3             /* Constants extracted from loop */
89         lea des_SPtrans+256,%a4
90         lea des_SPtrans+768,%a6
91         lea des_SPtrans+1280,%a5
92         move.l #252,%d1                 /* mask constant */
93
94
95         move.l 60(%sp),%a0              /* load key pointer */
96         move.l #8,%a1                   /* key incrementer */
97         jbsr des_fastencrypt2
98
99         move.l 64(%sp),%a0              /* load key pointer */
100         lea (120,%a0),%a0               /* start at end of key */
101         move.l #-8,%a1                  /* key incrementer */
102         jbsr des_fastencrypt2
103
104         move.l 68(%sp),%a0              /* load key pointer */
105         move.l #8,%a1                   /* key incrementer */
106         jbsr des_fastencrypt2
107
108
109         /* ASSUME: d5=data[0], d4=data[1] */
110         moveq.l #29,%d7
111         move.l %d5,%d0                  /* data[0]=ROTATE(l,3)&0xffffffffL; */
112         lsl.l %d7,%d0
113         lsr.l #3,%d5
114         or.l %d0,%d5
115
116         move.l %d4,%d1                  /* data[1]=ROTATE(r,3)&0xffffffffL; */
117         lsl.l %d7,%d1
118         lsr.l #3,%d4
119         or.l %d1,%d4
120
121         /* ----------------------------------- */
122
123         move.l %d4,%d0                  /* tt =(((r>>1)^l)&0x55555555L), */
124         lsr.l #1,%d0
125         eor.l %d5,%d0
126         and.l #1431655765,%d0
127
128         eor.l %d0,%d5                   /* l ^= tt, */
129
130         add.l %d0,%d0                   /* r ^= (tt<<1); */
131         eor.l %d0,%d4
132
133
134         move.l %d5,%d0                  /* tt =(((l>>8)^r)&0x00ff00ffL), */
135         lsr.l #8,%d0
136         eor.l %d4,%d0
137         and.l #16711935,%d0
138
139         eor.l %d0,%d4                   /* r ^= tt, */
140
141         lsl.l #8,%d0                    /* l ^= (tt<<8); */
142         eor.l %d0,%d5
143
144
145         move.l %d4,%d0                  /* tt =(((r>>2)^l)&0x33333333L), */
146         lsr.l #2,%d0
147         eor.l %d5,%d0
148         and.l #858993459,%d0
149
150         eor.l %d0,%d5                   /* l ^= tt, */
151
152         lsl.l #2,%d0                    /* r ^= (tt<<2); */
153         eor.l %d0,%d4
154
155
156         move.l %d5,%d0                  /* tt =(((l>>16)^r)&0x0000ffffL), */
157         clr.w %d0
158         swap %d0
159         eor.l %d4,%d0
160         and.l #65535,%d0
161
162         eor.l %d0,%d4                   /* r ^=tt, */
163
164         swap %d0                        /* l ^= (tt<<16); */
165         clr.w %d0
166         eor.l %d0,%d5
167
168         move.l %d4,%d0                  /* tt =(((r>>4)^l)&0x0f0f0f0fL), */
169         lsr.l #4,%d0
170         eor.l %d5,%d0
171         and.l #252645135,%d0
172
173         move.l 56(%sp),%a3
174         eor.l %d0,%d5                   /* l ^= tt, */
175         move.l %d5,(%a3)
176
177         lsl.l #4,%d0                    /* r ^= (tt<<4); */
178         eor.l %d0,%d4
179         move.l %d4,4(%a3)
180
181         moveml (%sp), %d2-%d7/%a2-%fp
182         add.l #52, %sp
183         rts
184
185 /****************************************************************************/
186
187 .align  16
188 .globl des_decrypt3
189
190 des_decrypt3:
191         lea %sp@(-52),%sp
192         moveml %d2-%d7/%a2-%fp, (%sp)
193
194         move.l 56(%sp),%a3
195         move.l (%a3),%d5                /* l = data[0] */
196         move.l 4(%a3),%d4               /* r = data[1] */
197
198         move.l %d4,%d0                  /* tt = ((r>>4)^l)&0x0f0f0f0fL, */
199         lsr.l #4,%d0
200         eor.l %d5,%d0
201         and.l #252645135,%d0
202
203         eor.l %d0,%d5                   /* l ^= tt, */
204
205         lsl.l #4,%d0                    /* r ^= (tt<<4); */
206         eor.l %d0,%d4
207
208
209         move.l %d5,%d0                  /* tt = ((l>>16)^r)&0x0000ffffL, */
210         clr.w %d0
211         swap %d0
212         eor.l %d4,%d0
213         and.l #65535,%d0
214
215         eor.l %d0,%d4                   /* r ^= tt, */
216
217         swap %d0
218         clr.w %d0
219         eor.l %d0,%d5                   /* l ^= (tt<<16); */
220
221
222         move.l %d4,%d0                  /* tt = ((r>>2)^l)&0x33333333L, */
223         lsr.l #2,%d0
224         eor.l %d5,%d0
225         and.l #858993459,%d0
226
227         eor.l %d0,%d5                   /* l ^= tt, */
228
229         lsl.l #2,%d0                    /* r ^= (tt<<2); */
230         eor.l %d0,%d4
231
232
233         move.l %d5,%d0                  /* tt = ((l>>8)^r)&0x00ff00ff, */
234         lsr.l #8,%d0
235         eor.l %d4,%d0
236         and.l #16711935,%d0
237
238         eor.l %d0,%d4                   /* r ^= tt, */
239
240         lsl.l #8,%d0                    /* l ^= (tt<<8); */
241         eor.l %d0,%d5
242
243
244         move.l %d4,%d0                  /* tt = ((r>>1)^l)&0x55555555, */
245         lsr.l #1,%d0
246         eor.l %d5,%d0
247         and.l #1431655765,%d0
248
249         eor.l %d0,%d5                   /* l ^= tt, */
250
251         add.l %d0,%d0                   /* r ^= (tt<<1); */
252         eor.l %d0,%d4
253
254         /* ----------------------------------- */
255         /* ASSUME: r=data[0]=%d5, l=data[1]=%d4 */
256
257         moveq.l #29,%d7
258         move.l %d5,%d0                  /* r=ROTATE(r,29)&0xffffffffL; */
259         lsr.l %d7,%d0
260         lsl.l #3,%d5
261         add.l %d0,%d5
262
263         move.l %d4,%d0                  /* l=ROTATE(l,29)&0xffffffffL; */
264         lsr.l %d7,%d0
265         lsl.l #3,%d4
266         add.l %d0,%d4
267
268         lea des_SPtrans,%a3             /* Constants extracted from loop */
269         lea des_SPtrans+256,%a4
270         lea des_SPtrans+768,%a6
271         lea des_SPtrans+1280,%a5
272         move.l #252,%d1                 /* mask constant */
273
274
275         move.l 68(%sp),%a0              /* load key pointer */
276         lea (120,%a0),%a0               /* start at end of key */
277         move.l #-8,%a1                  /* key incrementer */
278         jbsr des_fastencrypt2
279
280         move.l 64(%sp),%a0              /* load key pointer */
281         move.l #8,%a1                   /* key incrementer */
282         jbsr des_fastencrypt2
283
284         move.l 60(%sp),%a0              /* load key pointer */
285         lea (120,%a0),%a0               /* start at end of key */
286         move.l #-8,%a1                  /* key incrementer */
287         jbsr des_fastencrypt2
288
289
290         /* ASSUME: d5=data[0], d4=data[1] */
291         moveq.l #29,%d7
292         move.l %d5,%d0                  /* data[0]=ROTATE(l,3)&0xffffffffL; */
293         lsl.l %d7,%d0
294         lsr.l #3,%d5
295         or.l %d0,%d5
296
297         move.l %d4,%d1                  /* data[1]=ROTATE(r,3)&0xffffffffL; */
298         lsl.l %d7,%d1
299         lsr.l #3,%d4
300         or.l %d1,%d4
301
302         /* ----------------------------------- */
303
304         move.l %d4,%d0                  /* tt =(((r>>1)^l)&0x55555555L), */
305         lsr.l #1,%d0
306         eor.l %d5,%d0
307         and.l #1431655765,%d0
308
309         eor.l %d0,%d5                   /* l ^= tt, */
310
311         add.l %d0,%d0                   /* r ^= (tt<<1); */
312         eor.l %d0,%d4
313
314
315         move.l %d5,%d0                  /* tt =(((l>>8)^r)&0x00ff00ffL), */
316         lsr.l #8,%d0
317         eor.l %d4,%d0
318         and.l #16711935,%d0
319
320         eor.l %d0,%d4                   /* r ^= tt, */
321
322         lsl.l #8,%d0                    /* l ^= (tt<<8); */
323         eor.l %d0,%d5
324
325
326         move.l %d4,%d0                  /* tt =(((r>>2)^l)&0x33333333L), */
327         lsr.l #2,%d0
328         eor.l %d5,%d0
329         and.l #858993459,%d0
330
331         eor.l %d0,%d5                   /* l ^= tt, */
332
333         lsl.l #2,%d0                    /* r ^= (tt<<2); */
334         eor.l %d0,%d4
335
336
337         move.l %d5,%d0                  /* tt =(((l>>16)^r)&0x0000ffffL), */
338         clr.w %d0
339         swap %d0
340         eor.l %d4,%d0
341         and.l #65535,%d0
342
343         eor.l %d0,%d4                   /* r ^=tt, */
344
345         swap %d0                        /* l ^= (tt<<16); */
346         clr.w %d0
347         eor.l %d0,%d5
348
349         move.l %d4,%d0                  /* tt =(((r>>4)^l)&0x0f0f0f0fL), */
350         lsr.l #4,%d0
351         eor.l %d5,%d0
352         and.l #252645135,%d0
353
354         move.l 56(%sp),%a3
355         eor.l %d0,%d5                   /* l ^= tt, */
356         move.l %d5,(%a3)
357
358         lsl.l #4,%d0                    /* r ^= (tt<<4); */
359         eor.l %d0,%d4
360         move.l %d4,4(%a3)
361
362         moveml (%sp), %d2-%d7/%a2-%fp
363         add.l #52, %sp
364         rts
365
366 /****************************************************************************/
367
368 .align  16
369 .globl des_fastencrypt2
370
371 des_fastencrypt2:
372         /* ASSUME: a0=key, a1=incrementer, d5=r=data[0], d4=l=data[1] */
373
374         move.l #7, %d6                  /* for (i = 0; (i<32); i += 4) */
375
376 .L19:
377         move.l (%a0),%d2                /* u = r ^ s[i+0]; */
378         eor.l %d5,%d2
379
380         move.l 4(%a0),%d3               /* t = r ^ s[i+0+1]; */
381         eor.l %d5,%d3
382
383         move.l %d3,%d0                  /* t = ((t >> 4) + (t << (32-4)); */
384         lsr.l #4,%d0
385         moveq.l #28,%d7
386         lsl.l %d7,%d3
387         add.l %d0,%d3
388
389
390         move.l %d2,%d0                  /* des_SPtrans[0][(u>>2L)&0x3f] */
391         and.l %d1,%d0
392         move.l (%a3,%d0.l),%d0
393         eor.l %d0,%d4
394
395         move.l %d2,%d0                  /* des_SPtrans[2][(u>>10L)&0x3f] */
396         lsr.l #8,%d0
397         and.l %d1,%d0
398         lea des_SPtrans+512,%a2
399         move.l (%a2,%d0.l),%d0
400         eor.l %d0,%d4
401
402         clr.w %d2                       /* des_SPtrans[4][(u>>18L)&0x3f] */
403         swap %d2
404         move.l %d2,%d0
405         and.l %d1,%d0
406         lea des_SPtrans+1024,%a2
407         move.l (%a2,%d0.l),%d0
408         eor.l %d0,%d4
409
410         moveq.l #10,%d7                 /* des_SPtrans[6][(u>>26L)&0x3f] */
411         lsr.l %d7,%d2
412         lea des_SPtrans+1536,%a2
413         move.l (%a2,%d2.l*4),%d2
414         eor.l %d2,%d4
415
416         move.l %d3,%d0                  /* des_SPtrans[1][(t>>2L)&0x3f] */
417         and.l %d1,%d0
418         move.l (%a4,%d0.l),%d0
419         eor.l %d0,%d4
420
421         move.l %d3,%d0                  /* des_SPtrans[3][(t>>10L)&0x3f] */
422         lsr.l #8,%d0
423         and.l %d1,%d0
424         move.l (%a6,%d0.l),%d0
425         eor.l %d0,%d4
426
427         clr.w %d3                       /* des_SPtrans[5][(t>>18L)&0x3f] */
428         swap %d3
429         move.l %d3,%d0
430         and.l %d1,%d0
431         move.l (%a5,%d0.l),%d0
432         eor.l %d0,%d4
433
434         lsr.l %d7,%d3                   /* des_SPtrans[7][(t>>26L)&0x3f] */
435         lea des_SPtrans+1792,%a2
436         move.l (%a2,%d3.l*4),%d3
437         eor.l %d3,%d4
438
439         /* ---- */
440
441         add.l %a1,%a0                   /* s += 2 */
442
443         move.l (%a0),%d2                /* u = l ^ s[i+0]; */
444         eor.l %d4,%d2
445
446         move.l 4(%a0),%d3               /* t = l ^ s[i+0+1]; */
447         eor.l %d4,%d3
448
449         move.l %d3,%d0                  /* t = ((t >> 4) + (t << (32-4)); */
450         lsr.l #4,%d0
451         moveq.l #28,%d7
452         lsl.l %d7,%d3
453         add.l %d0,%d3
454
455
456         move.l %d2,%d0                  /* des_SPtrans[0][(u>>2L)&0x3f] */
457         and.l %d1,%d0
458         move.l (%a3,%d0.l),%d0
459         eor.l %d0,%d5
460
461         move.l %d2,%d0                  /* des_SPtrans[2][(u>>10L)&0x3f] */
462         lsr.l #8,%d0
463         and.l %d1,%d0
464         lea des_SPtrans+512,%a2
465         move.l (%a2,%d0.l),%d0
466         eor.l %d0,%d5
467
468         clr.w %d2                       /* des_SPtrans[4][(u>>18L)&0x3f] */
469         swap %d2
470         move.l %d2,%d0
471         and.l %d1,%d0
472         lea des_SPtrans+1024,%a2
473         move.l (%a2,%d0.l),%d0
474         eor.l %d0,%d5
475
476         moveq.l #10,%d7                 /* des_SPtrans[6][(u>>26L)&0x3f] */
477         lsr.l %d7,%d2
478         lea des_SPtrans+1536,%a2
479         move.l (%a2,%d2.l*4),%d2
480         eor.l %d2,%d5
481
482         move.l %d3,%d0                  /* des_SPtrans[1][(t>>2L)&0x3f] */
483         and.l %d1,%d0
484         move.l (%a4,%d0.l),%d0
485         eor.l %d0,%d5
486
487         move.l %d3,%d0                  /* des_SPtrans[3][(t>>10L)&0x3f] */
488         lsr.l #8,%d0
489         and.l %d1,%d0
490         move.l (%a6,%d0.l),%d0
491         eor.l %d0,%d5
492
493         clr.w %d3                       /* des_SPtrans[5][(t>>18L)&0x3f] */
494         swap %d3
495         move.l %d3,%d0
496         and.l %d1,%d0
497         move.l (%a5,%d0.l),%d0
498         eor.l %d0,%d5
499
500         lsr.l %d7,%d3                   /* des_SPtrans[7][(t>>26L)&0x3f] */
501         lea des_SPtrans+1792,%a2
502         move.l (%a2,%d3.l*4),%d3
503         eor.l %d3,%d5
504
505         /* ---- */
506
507         add.l %a1,%a0                   /* s += 2 */
508         subq.l #1, %d6                  /* i-- */
509         jbge .L19
510
511
512         move.l %d4,%d0
513         move.l %d5,%d4
514         move.l %d0,%d5
515         /* ASSUME: d5=r=data[0], d4=l=data[1] */
516         rts
517
518 /****************************************************************************/