1!  des_enc.m4
2!  des_enc.S  (generated from des_enc.m4)
3!
4!  UltraSPARC assembler version of the LibDES/SSLeay/OpenSSL des_enc.c file.
5!
6!  Version 1.0. 32-bit version.
7!
8!  June 8, 2000.
9!
10!  Version 2.0. 32/64-bit, PIC-ification, blended CPU adaptation
11!		by Andy Polyakov.
12!
13!  January 1, 2003.
14!
15!  Assembler version: Copyright Svend Olaf Mikkelsen.
16!
17!  Original C code: Copyright Eric A. Young.
18!
19!  This code can be freely used by LibDES/SSLeay/OpenSSL users.
20!
21!  The LibDES/SSLeay/OpenSSL copyright notices must be respected.
22!
23!  This version can be redistributed.
24!
25!  To expand the m4 macros: m4 -B 8192 des_enc.m4 > des_enc.S
26!
27!  Global registers 1 to 5 are used. This is the same as done by the
28!  cc compiler. The UltraSPARC load/store little endian feature is used.
29!
30!  Instruction grouping often refers to one CPU cycle.
31!
32!  Assemble through gcc: gcc -c -mcpu=ultrasparc -o des_enc.o des_enc.S
33!
34!  Assemble through cc:  cc -c -xarch=v8plusa -o des_enc.o des_enc.S
35!
36!  Performance improvement according to './apps/openssl speed des'
37!
38!	32-bit build:
39!		23%  faster than cc-5.2 -xarch=v8plus -xO5
40!		115% faster than gcc-3.2.1 -m32 -mcpu=ultrasparc -O5
41!	64-bit build:
42!		50%  faster than cc-5.2 -xarch=v9 -xO5
43!		100% faster than gcc-3.2.1 -m64 -mcpu=ultrasparc -O5
44!
45
46.ident "des_enc.m4 2.1"
47.file  "des_enc-sparc.S"
48
49#if defined(__SUNPRO_C) && defined(__sparcv9)
50# define ABI64  /* They've said -xarch=v9 at command line */
51#elif defined(__GNUC__) && defined(__arch64__)
52# define ABI64  /* They've said -m64 at command line */
53#endif
54
55#ifdef ABI64
56  .register	%g2,#scratch
57  .register	%g3,#scratch
58# define	FRAME	-192
59# define	BIAS	2047
60# define	LDPTR	ldx
61# define	STPTR	stx
62# define	ARG0	128
63# define	ARGSZ	8
64# ifndef __sparc_v9__
65# define __sparc_v9__
66# endif
67#else
68# define	FRAME	-96
69# define	BIAS	0
70# define	LDPTR	ld
71# define	STPTR	st
72# define	ARG0	68
73# define	ARGSZ	4
74#endif
75
76#define LOOPS 7
77
78#define global0 %g0
79#define global1 %g1
80#define global2 %g2
81#define global3 %g3
82#define global4 %g4
83#define global5 %g5
84
85#define local0 %l0
86#define local1 %l1
87#define local2 %l2
88#define local3 %l3
89#define local4 %l4
90#define local5 %l5
91#define local7 %l6
92#define local6 %l7
93
94#define in0 %i0
95#define in1 %i1
96#define in2 %i2
97#define in3 %i3
98#define in4 %i4
99#define in5 %i5
100#define in6 %i6
101#define in7 %i7
102
103#define out0 %o0
104#define out1 %o1
105#define out2 %o2
106#define out3 %o3
107#define out4 %o4
108#define out5 %o5
109#define out6 %o6
110#define out7 %o7
111
112#define stub stb
113
114
115
116
117! Macro definitions:
118
119
120! ip_macro
121!
122! The logic used in initial and final permutations is the same as in
123! the C code. The permutations are done with a clever , xor, and
124! technique.
125!
126! The macro also loads address sbox 1 to 5 to global 1 to 5, address
127! sbox 6 to local6, and addres sbox 8 to out3.
128!
129! Rotates the halfs 3 left to bring the sbox bits in convenient positions.
130!
131! Loads key first round from address in parameter 5 to out0, out1.
132!
133! After the the original LibDES initial permutation, the resulting left
134! is in the variable initially used for right and vice versa. The macro
135! implements the possibility to keep the halfs in the original registers.
136!
137! parameter 1  left
138! parameter 2  right
139! parameter 3  result left (modify in first round)
140! parameter 4  result right (use in first round)
141! parameter 5  key address
142! parameter 6  1/2 for include encryption/decryption
143! parameter 7  1 for move in1 to in3
144! parameter 8  1 for move in3 to in4, 2 for move in4 to in3
145! parameter 9  1 for load ks3 and ks2 to in4 and in3
146
147
148
149
150! rounds_macro
151!
152! The logic used in the DES rounds is the same as in the C code,
153! except that calculations for sbox 1 and sbox 5 begin before
154! the previous round is finished.
155!
156! In each round one half (work) is modified based on key and the
157! other half (use).
158!
159! In this version we do two rounds in a loop repeated 7 times
160! and two rounds seperately.
161!
162! One half has the bits for the sboxes in the following positions:
163!
164!	777777xx555555xx333333xx111111xx
165!
166!	88xx666666xx444444xx222222xx8888
167!
168! The bits for each sbox are xor-ed with the key bits for that box.
169! The above xx bits are cleared, and the result used for lookup in
170! the sbox table. Each sbox entry contains the 4 output bits permuted
171! into 32 bits according to the P permutation.
172!
173! In the description of DES, left and right are switched after
174! each round, except after last round. In this code the original
175! left and right are kept in the same register in all rounds, meaning
176! that after the 16 rounds the result for right is in the register
177! originally used for left.
178!
179! parameter 1  first work (left in first round)
180! parameter 2  first use (right in first round)
181! parameter 3  enc/dec  1/-1
182! parameter 4  loop label
183! parameter 5  key address register
184! parameter 6  optional address for key next encryption/decryption
185! parameter 7  not empty for include retl
186!
187! also compares in2 to 8
188
189
190
191
192! fp_macro
193!
194!  parameter 1   right (original left)
195!  parameter 2   left (original right)
196!  parameter 3   1 for optional store to [in0]
197!  parameter 4   1 for load input/output address to local5/7
198!
199!  The final permutation logic switches the halfes, meaning that
200!  left and right ends up the the registers originally used.
201
202
203
204
205! fp_ip_macro
206!
207! Does initial permutation for next block mixed with
208! final permutation for current block.
209!
210! parameter 1   original left
211! parameter 2   original right
212! parameter 3   left ip
213! parameter 4   right ip
214! parameter 5   1: load ks1/ks2 to in3/in4, add 120 to in4
215!                2: mov in4 to in3
216!
217! also adds -8 to length in2 and loads loop counter to out4
218
219
220
221
222
223! load_little_endian
224!
225! parameter 1  address
226! parameter 2  destination left
227! parameter 3  destination right
228! parameter 4  temporar
229! parameter 5  label
230
231
232
233
234! load_little_endian_inc
235!
236! parameter 1  address
237! parameter 2  destination left
238! parameter 3  destination right
239! parameter 4  temporar
240! parameter 4  label
241!
242! adds 8 to address
243
244
245
246
247! load_n_bytes
248!
249! Loads 1 to 7 bytes little endian
250! Remaining bytes are zeroed.
251!
252! parameter 1  address
253! parameter 2  length
254! parameter 3  destination register left
255! parameter 4  destination register right
256! parameter 5  temp
257! parameter 6  temp2
258! parameter 7  label
259! parameter 8  return label
260
261
262
263
264! store_little_endian
265!
266! parameter 1  address
267! parameter 2  source left
268! parameter 3  source right
269! parameter 4  temporar
270
271
272
273
274! store_n_bytes
275!
276! Stores 1 to 7 bytes little endian
277!
278! parameter 1  address
279! parameter 2  length
280! parameter 3  source register left
281! parameter 4  source register right
282! parameter 5  temp
283! parameter 6  temp2
284! parameter 7  label
285! parameter 8  return label
286
287
288
289
290
291
292
293
294.section	".text"
295
296	.align 32
297
298.des_enc:
299
300	! key address in3
301	! loads key next encryption/decryption first round from [in4]
302
303
304
305! rounds_macro
306! in5 out5 1 .des_enc.1 in3 in4 retl
307
308	xor	out5, out0, local1
309
310	ld	[out2+284], local5        ! 0x0000FC00
311	ba	.des_enc.1
312	and	local1, 252, local1
313
314	.align 32
315
316.des_enc.1:
317	! local6 is address sbox 6
318	! out3   is address sbox 8
319	! out4   is loop counter
320
321	ld	[global1+local1], local1
322	xor	out5, out1, out1            ! 8642
323	xor	out5, out0, out0            ! 7531
324	! fmovs	%f0, %f0                  ! fxor used for alignment
325
326	srl	out1, 4, local0           ! rotate 4 right
327	and	out0, local5, local3      ! 3
328	! fmovs	%f0, %f0
329
330	ld	[in3+1*8], local7         ! key 7531 next round
331	srl	local3, 8, local3         ! 3
332	and	local0, 252, local2       ! 2
333	! fmovs	%f0, %f0
334
335	ld	[global3+local3],local3   ! 3
336	sll	out1, 28, out1            ! rotate
337	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
338
339	ld	[global2+local2], local2  ! 2
340	srl	out0, 24, local1          ! 7
341	or	out1, local0, out1        ! rotate
342
343	ldub	[out2+local1], local1     ! 7 (and 0xFC)
344	srl	out1, 24, local0          ! 8
345	and	out1, local5, local4      ! 4
346
347	ldub	[out2+local0], local0     ! 8 (and 0xFC)
348	srl	local4, 8, local4         ! 4
349	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
350
351	ld	[global4+local4],local4   ! 4
352	srl	out1, 16, local2          ! 6
353	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
354
355	ld	[out3+local0],local0      ! 8
356	and	local2, 252, local2       ! 6
357	add	global1, 1536, local5     ! address sbox 7
358
359	ld	[local6+local2], local2   ! 6
360	srl	out0, 16, local3          ! 5
361	xor	in5, local4, in5            ! 4 finished
362
363	ld	[local5+local1],local1    ! 7
364	and	local3, 252, local3       ! 5
365	xor	in5, local0, in5            ! 8 finished
366
367	ld	[global5+local3],local3   ! 5
368	xor	in5, local2, in5            ! 6 finished
369	subcc	out4, 1, out4
370
371	ld	[in3+1*8+4], out0         ! key 8642 next round
372	xor	in5, local7, local2        ! sbox 5 next round
373	xor	in5, local1, in5            ! 7 finished
374
375	srl	local2, 16, local2        ! sbox 5 next round
376	xor	in5, local3, in5            ! 5 finished
377
378	ld	[in3+1*16+4], out1        ! key 8642 next round again
379	and	local2, 252, local2       ! sbox5 next round
380! next round
381	xor	in5, local7, local7        ! 7531
382
383	ld	[global5+local2], local2  ! 5
384	srl	local7, 24, local3        ! 7
385	xor	in5, out0, out0            ! 8642
386
387	ldub	[out2+local3], local3     ! 7 (and 0xFC)
388	srl	out0, 4, local0           ! rotate 4 right
389	and	local7, 252, local1       ! 1
390
391	sll	out0, 28, out0            ! rotate
392	xor	out5, local2, out5            ! 5 finished local2 used
393
394	srl	local0, 8, local4         ! 4
395	and	local0, 252, local2       ! 2
396	ld	[local5+local3], local3   ! 7
397
398	srl	local0, 16, local5        ! 6
399	or	out0, local0, out0        ! rotate
400	ld	[global2+local2], local2  ! 2
401
402	srl	out0, 24, local0
403	ld	[in3+1*16], out0          ! key 7531 next round
404	and	local4, 252, local4	  ! 4
405
406	and	local5, 252, local5       ! 6
407	ld	[global4+local4], local4  ! 4
408	xor	out5, local3, out5            ! 7 finished local3 used
409
410	and	local0, 252, local0       ! 8
411	ld	[local6+local5], local5   ! 6
412	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
413
414	srl	local7, 8, local2         ! 3 start
415	ld	[out3+local0], local0     ! 8
416	xor	out5, local4, out5            ! 4 finished
417
418	and	local2, 252, local2       ! 3
419	ld	[global1+local1], local1  ! 1
420	xor	out5, local5, out5            ! 6 finished local5 used
421
422	ld	[global3+local2], local2  ! 3
423	xor	out5, local0, out5            ! 8 finished
424	add	in3, 1*16, in3             ! enc add 8, dec add -8 to key pointer
425
426	ld	[out2+284], local5        ! 0x0000FC00
427	xor	out5, out0, local4          ! sbox 1 next round
428	xor	out5, local1, out5            ! 1 finished
429
430	xor	out5, local2, out5            ! 3 finished
431#ifdef __sparc_v9__
432	bne,pt	%icc, .des_enc.1
433#else
434	bne	.des_enc.1
435#endif
436	and	local4, 252, local1       ! sbox 1 next round
437
438! two rounds more:
439
440	ld	[global1+local1], local1
441	xor	out5, out1, out1
442	xor	out5, out0, out0
443
444	srl	out1, 4, local0           ! rotate
445	and	out0, local5, local3
446
447	ld	[in3+1*8], local7         ! key 7531
448	srl	local3, 8, local3
449	and	local0, 252, local2
450
451	ld	[global3+local3],local3
452	sll	out1, 28, out1            ! rotate
453	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
454
455	ld	[global2+local2], local2
456	srl	out0, 24, local1
457	or	out1, local0, out1        ! rotate
458
459	ldub	[out2+local1], local1
460	srl	out1, 24, local0
461	and	out1, local5, local4
462
463	ldub	[out2+local0], local0
464	srl	local4, 8, local4
465	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
466
467	ld	[global4+local4],local4
468	srl	out1, 16, local2
469	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
470
471	ld	[out3+local0],local0
472	and	local2, 252, local2
473	add	global1, 1536, local5     ! address sbox 7
474
475	ld	[local6+local2], local2
476	srl	out0, 16, local3
477	xor	in5, local4, in5            ! 4 finished
478
479	ld	[local5+local1],local1
480	and	local3, 252, local3
481	xor	in5, local0, in5
482
483	ld	[global5+local3],local3
484	xor	in5, local2, in5            ! 6 finished
485	cmp	in2, 8
486
487	ld	[out2+280], out4  ! loop counter
488	xor	in5, local7, local2        ! sbox 5 next round
489	xor	in5, local1, in5            ! 7 finished
490
491	ld	[in3+1*8+4], out0
492	srl	local2, 16, local2        ! sbox 5 next round
493	xor	in5, local3, in5            ! 5 finished
494
495	and	local2, 252, local2
496! next round (two rounds more)
497	xor	in5, local7, local7        ! 7531
498
499	ld	[global5+local2], local2
500	srl	local7, 24, local3
501	xor	in5, out0, out0            ! 8642
502
503	ldub	[out2+local3], local3
504	srl	out0, 4, local0           ! rotate
505	and	local7, 252, local1
506
507	sll	out0, 28, out0            ! rotate
508	xor	out5, local2, out5            ! 5 finished local2 used
509
510	srl	local0, 8, local4
511	and	local0, 252, local2
512	ld	[local5+local3], local3
513
514	srl	local0, 16, local5
515	or	out0, local0, out0        ! rotate
516	ld	[global2+local2], local2
517
518	srl	out0, 24, local0
519	ld	[in4], out0   ! key next encryption/decryption
520	and	local4, 252, local4
521
522	and	local5, 252, local5
523	ld	[global4+local4], local4
524	xor	out5, local3, out5            ! 7 finished local3 used
525
526	and	local0, 252, local0
527	ld	[local6+local5], local5
528	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
529
530	srl	local7, 8, local2         ! 3 start
531	ld	[out3+local0], local0
532	xor	out5, local4, out5
533
534	and	local2, 252, local2
535	ld	[global1+local1], local1
536	xor	out5, local5, out5            ! 6 finished local5 used
537
538	ld	[global3+local2], local2
539	srl	in5, 3, local3
540	xor	out5, local0, out5
541
542	ld	[in4+4], out1 ! key next encryption/decryption
543	sll	in5, 29, local4
544	xor	out5, local1, out5
545
546	retl
547	xor	out5, local2, out5
548
549
550
551	.align 32
552
553.des_dec:
554
555	! implemented with out5 as first parameter to avoid
556	! register exchange in ede modes
557
558	! key address in4
559	! loads key next encryption/decryption first round from [in3]
560
561
562
563! rounds_macro
564! out5 in5 -1 .des_dec.1 in4 in3 retl
565
566	xor	in5, out0, local1
567
568	ld	[out2+284], local5        ! 0x0000FC00
569	ba	.des_dec.1
570	and	local1, 252, local1
571
572	.align 32
573
574.des_dec.1:
575	! local6 is address sbox 6
576	! out3   is address sbox 8
577	! out4   is loop counter
578
579	ld	[global1+local1], local1
580	xor	in5, out1, out1            ! 8642
581	xor	in5, out0, out0            ! 7531
582	! fmovs	%f0, %f0                  ! fxor used for alignment
583
584	srl	out1, 4, local0           ! rotate 4 right
585	and	out0, local5, local3      ! 3
586	! fmovs	%f0, %f0
587
588	ld	[in4+-1*8], local7         ! key 7531 next round
589	srl	local3, 8, local3         ! 3
590	and	local0, 252, local2       ! 2
591	! fmovs	%f0, %f0
592
593	ld	[global3+local3],local3   ! 3
594	sll	out1, 28, out1            ! rotate
595	xor	out5, local1, out5            ! 1 finished, local1 now sbox 7
596
597	ld	[global2+local2], local2  ! 2
598	srl	out0, 24, local1          ! 7
599	or	out1, local0, out1        ! rotate
600
601	ldub	[out2+local1], local1     ! 7 (and 0xFC)
602	srl	out1, 24, local0          ! 8
603	and	out1, local5, local4      ! 4
604
605	ldub	[out2+local0], local0     ! 8 (and 0xFC)
606	srl	local4, 8, local4         ! 4
607	xor	out5, local2, out5            ! 2 finished local2 now sbox 6
608
609	ld	[global4+local4],local4   ! 4
610	srl	out1, 16, local2          ! 6
611	xor	out5, local3, out5            ! 3 finished local3 now sbox 5
612
613	ld	[out3+local0],local0      ! 8
614	and	local2, 252, local2       ! 6
615	add	global1, 1536, local5     ! address sbox 7
616
617	ld	[local6+local2], local2   ! 6
618	srl	out0, 16, local3          ! 5
619	xor	out5, local4, out5            ! 4 finished
620
621	ld	[local5+local1],local1    ! 7
622	and	local3, 252, local3       ! 5
623	xor	out5, local0, out5            ! 8 finished
624
625	ld	[global5+local3],local3   ! 5
626	xor	out5, local2, out5            ! 6 finished
627	subcc	out4, 1, out4
628
629	ld	[in4+-1*8+4], out0         ! key 8642 next round
630	xor	out5, local7, local2        ! sbox 5 next round
631	xor	out5, local1, out5            ! 7 finished
632
633	srl	local2, 16, local2        ! sbox 5 next round
634	xor	out5, local3, out5            ! 5 finished
635
636	ld	[in4+-1*16+4], out1        ! key 8642 next round again
637	and	local2, 252, local2       ! sbox5 next round
638! next round
639	xor	out5, local7, local7        ! 7531
640
641	ld	[global5+local2], local2  ! 5
642	srl	local7, 24, local3        ! 7
643	xor	out5, out0, out0            ! 8642
644
645	ldub	[out2+local3], local3     ! 7 (and 0xFC)
646	srl	out0, 4, local0           ! rotate 4 right
647	and	local7, 252, local1       ! 1
648
649	sll	out0, 28, out0            ! rotate
650	xor	in5, local2, in5            ! 5 finished local2 used
651
652	srl	local0, 8, local4         ! 4
653	and	local0, 252, local2       ! 2
654	ld	[local5+local3], local3   ! 7
655
656	srl	local0, 16, local5        ! 6
657	or	out0, local0, out0        ! rotate
658	ld	[global2+local2], local2  ! 2
659
660	srl	out0, 24, local0
661	ld	[in4+-1*16], out0          ! key 7531 next round
662	and	local4, 252, local4	  ! 4
663
664	and	local5, 252, local5       ! 6
665	ld	[global4+local4], local4  ! 4
666	xor	in5, local3, in5            ! 7 finished local3 used
667
668	and	local0, 252, local0       ! 8
669	ld	[local6+local5], local5   ! 6
670	xor	in5, local2, in5            ! 2 finished local2 now sbox 3
671
672	srl	local7, 8, local2         ! 3 start
673	ld	[out3+local0], local0     ! 8
674	xor	in5, local4, in5            ! 4 finished
675
676	and	local2, 252, local2       ! 3
677	ld	[global1+local1], local1  ! 1
678	xor	in5, local5, in5            ! 6 finished local5 used
679
680	ld	[global3+local2], local2  ! 3
681	xor	in5, local0, in5            ! 8 finished
682	add	in4, -1*16, in4             ! enc add 8, dec add -8 to key pointer
683
684	ld	[out2+284], local5        ! 0x0000FC00
685	xor	in5, out0, local4          ! sbox 1 next round
686	xor	in5, local1, in5            ! 1 finished
687
688	xor	in5, local2, in5            ! 3 finished
689#ifdef __sparc_v9__
690	bne,pt	%icc, .des_dec.1
691#else
692	bne	.des_dec.1
693#endif
694	and	local4, 252, local1       ! sbox 1 next round
695
696! two rounds more:
697
698	ld	[global1+local1], local1
699	xor	in5, out1, out1
700	xor	in5, out0, out0
701
702	srl	out1, 4, local0           ! rotate
703	and	out0, local5, local3
704
705	ld	[in4+-1*8], local7         ! key 7531
706	srl	local3, 8, local3
707	and	local0, 252, local2
708
709	ld	[global3+local3],local3
710	sll	out1, 28, out1            ! rotate
711	xor	out5, local1, out5            ! 1 finished, local1 now sbox 7
712
713	ld	[global2+local2], local2
714	srl	out0, 24, local1
715	or	out1, local0, out1        ! rotate
716
717	ldub	[out2+local1], local1
718	srl	out1, 24, local0
719	and	out1, local5, local4
720
721	ldub	[out2+local0], local0
722	srl	local4, 8, local4
723	xor	out5, local2, out5            ! 2 finished local2 now sbox 6
724
725	ld	[global4+local4],local4
726	srl	out1, 16, local2
727	xor	out5, local3, out5            ! 3 finished local3 now sbox 5
728
729	ld	[out3+local0],local0
730	and	local2, 252, local2
731	add	global1, 1536, local5     ! address sbox 7
732
733	ld	[local6+local2], local2
734	srl	out0, 16, local3
735	xor	out5, local4, out5            ! 4 finished
736
737	ld	[local5+local1],local1
738	and	local3, 252, local3
739	xor	out5, local0, out5
740
741	ld	[global5+local3],local3
742	xor	out5, local2, out5            ! 6 finished
743	cmp	in2, 8
744
745	ld	[out2+280], out4  ! loop counter
746	xor	out5, local7, local2        ! sbox 5 next round
747	xor	out5, local1, out5            ! 7 finished
748
749	ld	[in4+-1*8+4], out0
750	srl	local2, 16, local2        ! sbox 5 next round
751	xor	out5, local3, out5            ! 5 finished
752
753	and	local2, 252, local2
754! next round (two rounds more)
755	xor	out5, local7, local7        ! 7531
756
757	ld	[global5+local2], local2
758	srl	local7, 24, local3
759	xor	out5, out0, out0            ! 8642
760
761	ldub	[out2+local3], local3
762	srl	out0, 4, local0           ! rotate
763	and	local7, 252, local1
764
765	sll	out0, 28, out0            ! rotate
766	xor	in5, local2, in5            ! 5 finished local2 used
767
768	srl	local0, 8, local4
769	and	local0, 252, local2
770	ld	[local5+local3], local3
771
772	srl	local0, 16, local5
773	or	out0, local0, out0        ! rotate
774	ld	[global2+local2], local2
775
776	srl	out0, 24, local0
777	ld	[in3], out0   ! key next encryption/decryption
778	and	local4, 252, local4
779
780	and	local5, 252, local5
781	ld	[global4+local4], local4
782	xor	in5, local3, in5            ! 7 finished local3 used
783
784	and	local0, 252, local0
785	ld	[local6+local5], local5
786	xor	in5, local2, in5            ! 2 finished local2 now sbox 3
787
788	srl	local7, 8, local2         ! 3 start
789	ld	[out3+local0], local0
790	xor	in5, local4, in5
791
792	and	local2, 252, local2
793	ld	[global1+local1], local1
794	xor	in5, local5, in5            ! 6 finished local5 used
795
796	ld	[global3+local2], local2
797	srl	out5, 3, local3
798	xor	in5, local0, in5
799
800	ld	[in3+4], out1 ! key next encryption/decryption
801	sll	out5, 29, local4
802	xor	in5, local1, in5
803
804	retl
805	xor	in5, local2, in5
806
807
808
809
810! void DES_encrypt1(data, ks, enc)
811! *******************************
812
813	.align 32
814	.global DES_encrypt1
815	.type	 DES_encrypt1,#function
816
817DES_encrypt1:
818
819	save	%sp, FRAME, %sp
820
821	sethi	%hi(_PIC_DES_SPtrans-1f),global1
822	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
8231:	call	.+8
824	add	%o7,global1,global1
825	sub	global1,_PIC_DES_SPtrans-.des_and,out2
826
827	ld	[in0], in5                ! left
828	cmp	in2, 0                    ! enc
829
830#ifdef __sparc_v9__
831	be,pn	%icc, .encrypt.dec        ! enc/dec
832#else
833	be	.encrypt.dec
834#endif
835	ld	[in0+4], out5             ! right
836
837	! parameter 6  1/2 for include encryption/decryption
838	! parameter 7  1 for move in1 to in3
839	! parameter 8  1 for move in3 to in4, 2 for move in4 to in3
840
841
842
843! ip_macro
844! in5 out5 out5 in5 in3 0 1 1
845
846	ld	[out2+256], local1
847	srl	out5, 4, local4
848
849	xor	local4, in5, local4
850	mov in1, in3
851
852	ld	[out2+260], local2
853	and	local4, local1, local4
854	mov in3, in4
855
856
857	ld	[out2+280], out4          ! loop counter
858	sll	local4, 4, local1
859	xor	in5, local4, in5
860
861	ld	[out2+264], local3
862	srl	in5, 16, local4
863	xor	out5, local1, out5
864
865
866	xor	local4, out5, local4
867	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
868
869
870	and	local4, local2, local4
871	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
872
873	sll	local4, 16, local1
874	xor	out5, local4, out5
875
876	srl	out5, 2, local4
877	xor	in5, local1, in5
878
879	sethi	%hi(16711680), local5
880	xor	local4, in5, local4
881
882	and	local4, local3, local4
883	or	local5, 255, local5
884
885	sll	local4, 2, local2
886	xor	in5, local4, in5
887
888	srl	in5, 8, local4
889	xor	out5, local2, out5
890
891	xor	local4, out5, local4
892	add	global1, 768, global4
893
894	and	local4, local5, local4
895	add	global1, 1024, global5
896
897	ld	[out2+272], local7
898	sll	local4, 8, local1
899	xor	out5, local4, out5
900
901	srl	out5, 1, local4
902	xor	in5, local1, in5
903
904	ld	[in3], out0                ! key 7531
905	xor	local4, in5, local4
906	add	global1, 256, global2
907
908	ld	[in3+4], out1              ! key 8642
909	and	local4, local7, local4
910	add	global1, 512, global3
911
912	sll	local4, 1, local1
913	xor	in5, local4, in5
914
915	sll	in5, 3, local3
916	xor	out5, local1, out5
917
918	sll	out5, 3, local2
919	add	global1, 1280, local6     ! address sbox 8
920
921	srl	in5, 29, local4
922	add	global1, 1792, out3       ! address sbox 8
923
924	srl	out5, 29, local1
925	or	local4, local3, out5
926
927	or	local2, local1, in5
928
929
930
931
932
933
934
935
936! rounds_macro
937! in5 out5 1 .des_encrypt1.1 in3 in4
938
939	xor	out5, out0, local1
940
941	ld	[out2+284], local5        ! 0x0000FC00
942	ba	.des_encrypt1.1
943	and	local1, 252, local1
944
945	.align 32
946
947.des_encrypt1.1:
948	! local6 is address sbox 6
949	! out3   is address sbox 8
950	! out4   is loop counter
951
952	ld	[global1+local1], local1
953	xor	out5, out1, out1            ! 8642
954	xor	out5, out0, out0            ! 7531
955	! fmovs	%f0, %f0                  ! fxor used for alignment
956
957	srl	out1, 4, local0           ! rotate 4 right
958	and	out0, local5, local3      ! 3
959	! fmovs	%f0, %f0
960
961	ld	[in3+1*8], local7         ! key 7531 next round
962	srl	local3, 8, local3         ! 3
963	and	local0, 252, local2       ! 2
964	! fmovs	%f0, %f0
965
966	ld	[global3+local3],local3   ! 3
967	sll	out1, 28, out1            ! rotate
968	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
969
970	ld	[global2+local2], local2  ! 2
971	srl	out0, 24, local1          ! 7
972	or	out1, local0, out1        ! rotate
973
974	ldub	[out2+local1], local1     ! 7 (and 0xFC)
975	srl	out1, 24, local0          ! 8
976	and	out1, local5, local4      ! 4
977
978	ldub	[out2+local0], local0     ! 8 (and 0xFC)
979	srl	local4, 8, local4         ! 4
980	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
981
982	ld	[global4+local4],local4   ! 4
983	srl	out1, 16, local2          ! 6
984	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
985
986	ld	[out3+local0],local0      ! 8
987	and	local2, 252, local2       ! 6
988	add	global1, 1536, local5     ! address sbox 7
989
990	ld	[local6+local2], local2   ! 6
991	srl	out0, 16, local3          ! 5
992	xor	in5, local4, in5            ! 4 finished
993
994	ld	[local5+local1],local1    ! 7
995	and	local3, 252, local3       ! 5
996	xor	in5, local0, in5            ! 8 finished
997
998	ld	[global5+local3],local3   ! 5
999	xor	in5, local2, in5            ! 6 finished
1000	subcc	out4, 1, out4
1001
1002	ld	[in3+1*8+4], out0         ! key 8642 next round
1003	xor	in5, local7, local2        ! sbox 5 next round
1004	xor	in5, local1, in5            ! 7 finished
1005
1006	srl	local2, 16, local2        ! sbox 5 next round
1007	xor	in5, local3, in5            ! 5 finished
1008
1009	ld	[in3+1*16+4], out1        ! key 8642 next round again
1010	and	local2, 252, local2       ! sbox5 next round
1011! next round
1012	xor	in5, local7, local7        ! 7531
1013
1014	ld	[global5+local2], local2  ! 5
1015	srl	local7, 24, local3        ! 7
1016	xor	in5, out0, out0            ! 8642
1017
1018	ldub	[out2+local3], local3     ! 7 (and 0xFC)
1019	srl	out0, 4, local0           ! rotate 4 right
1020	and	local7, 252, local1       ! 1
1021
1022	sll	out0, 28, out0            ! rotate
1023	xor	out5, local2, out5            ! 5 finished local2 used
1024
1025	srl	local0, 8, local4         ! 4
1026	and	local0, 252, local2       ! 2
1027	ld	[local5+local3], local3   ! 7
1028
1029	srl	local0, 16, local5        ! 6
1030	or	out0, local0, out0        ! rotate
1031	ld	[global2+local2], local2  ! 2
1032
1033	srl	out0, 24, local0
1034	ld	[in3+1*16], out0          ! key 7531 next round
1035	and	local4, 252, local4	  ! 4
1036
1037	and	local5, 252, local5       ! 6
1038	ld	[global4+local4], local4  ! 4
1039	xor	out5, local3, out5            ! 7 finished local3 used
1040
1041	and	local0, 252, local0       ! 8
1042	ld	[local6+local5], local5   ! 6
1043	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
1044
1045	srl	local7, 8, local2         ! 3 start
1046	ld	[out3+local0], local0     ! 8
1047	xor	out5, local4, out5            ! 4 finished
1048
1049	and	local2, 252, local2       ! 3
1050	ld	[global1+local1], local1  ! 1
1051	xor	out5, local5, out5            ! 6 finished local5 used
1052
1053	ld	[global3+local2], local2  ! 3
1054	xor	out5, local0, out5            ! 8 finished
1055	add	in3, 1*16, in3             ! enc add 8, dec add -8 to key pointer
1056
1057	ld	[out2+284], local5        ! 0x0000FC00
1058	xor	out5, out0, local4          ! sbox 1 next round
1059	xor	out5, local1, out5            ! 1 finished
1060
1061	xor	out5, local2, out5            ! 3 finished
1062#ifdef __sparc_v9__
1063	bne,pt	%icc, .des_encrypt1.1
1064#else
1065	bne	.des_encrypt1.1
1066#endif
1067	and	local4, 252, local1       ! sbox 1 next round
1068
1069! two rounds more:
1070
1071	ld	[global1+local1], local1
1072	xor	out5, out1, out1
1073	xor	out5, out0, out0
1074
1075	srl	out1, 4, local0           ! rotate
1076	and	out0, local5, local3
1077
1078	ld	[in3+1*8], local7         ! key 7531
1079	srl	local3, 8, local3
1080	and	local0, 252, local2
1081
1082	ld	[global3+local3],local3
1083	sll	out1, 28, out1            ! rotate
1084	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
1085
1086	ld	[global2+local2], local2
1087	srl	out0, 24, local1
1088	or	out1, local0, out1        ! rotate
1089
1090	ldub	[out2+local1], local1
1091	srl	out1, 24, local0
1092	and	out1, local5, local4
1093
1094	ldub	[out2+local0], local0
1095	srl	local4, 8, local4
1096	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
1097
1098	ld	[global4+local4],local4
1099	srl	out1, 16, local2
1100	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
1101
1102	ld	[out3+local0],local0
1103	and	local2, 252, local2
1104	add	global1, 1536, local5     ! address sbox 7
1105
1106	ld	[local6+local2], local2
1107	srl	out0, 16, local3
1108	xor	in5, local4, in5            ! 4 finished
1109
1110	ld	[local5+local1],local1
1111	and	local3, 252, local3
1112	xor	in5, local0, in5
1113
1114	ld	[global5+local3],local3
1115	xor	in5, local2, in5            ! 6 finished
1116	cmp	in2, 8
1117
1118	ld	[out2+280], out4  ! loop counter
1119	xor	in5, local7, local2        ! sbox 5 next round
1120	xor	in5, local1, in5            ! 7 finished
1121
1122	ld	[in3+1*8+4], out0
1123	srl	local2, 16, local2        ! sbox 5 next round
1124	xor	in5, local3, in5            ! 5 finished
1125
1126	and	local2, 252, local2
1127! next round (two rounds more)
1128	xor	in5, local7, local7        ! 7531
1129
1130	ld	[global5+local2], local2
1131	srl	local7, 24, local3
1132	xor	in5, out0, out0            ! 8642
1133
1134	ldub	[out2+local3], local3
1135	srl	out0, 4, local0           ! rotate
1136	and	local7, 252, local1
1137
1138	sll	out0, 28, out0            ! rotate
1139	xor	out5, local2, out5            ! 5 finished local2 used
1140
1141	srl	local0, 8, local4
1142	and	local0, 252, local2
1143	ld	[local5+local3], local3
1144
1145	srl	local0, 16, local5
1146	or	out0, local0, out0        ! rotate
1147	ld	[global2+local2], local2
1148
1149	srl	out0, 24, local0
1150	ld	[in4], out0   ! key next encryption/decryption
1151	and	local4, 252, local4
1152
1153	and	local5, 252, local5
1154	ld	[global4+local4], local4
1155	xor	out5, local3, out5            ! 7 finished local3 used
1156
1157	and	local0, 252, local0
1158	ld	[local6+local5], local5
1159	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
1160
1161	srl	local7, 8, local2         ! 3 start
1162	ld	[out3+local0], local0
1163	xor	out5, local4, out5
1164
1165	and	local2, 252, local2
1166	ld	[global1+local1], local1
1167	xor	out5, local5, out5            ! 6 finished local5 used
1168
1169	ld	[global3+local2], local2
1170	srl	in5, 3, local3
1171	xor	out5, local0, out5
1172
1173	ld	[in4+4], out1 ! key next encryption/decryption
1174	sll	in5, 29, local4
1175	xor	out5, local1, out5
1176
1177
1178	xor	out5, local2, out5
1179 ! in4 not used
1180
1181
1182
1183! fp_macro
1184! in5 out5 1
1185
1186	! initially undo the rotate 3 left done after initial permutation
1187	! original left is received shifted 3 right and 29 left in local3/4
1188
1189	sll	out5, 29, local1
1190	or	local3, local4, in5
1191
1192	srl	out5, 3, out5
1193	sethi	%hi(0x55555555), local2
1194
1195	or	out5, local1, out5
1196	or	local2, %lo(0x55555555), local2
1197
1198	srl	out5, 1, local3
1199	sethi	%hi(0x00ff00ff), local1
1200	xor	local3, in5, local3
1201	or	local1, %lo(0x00ff00ff), local1
1202	and	local3, local2, local3
1203	sethi	%hi(0x33333333), local4
1204	sll	local3, 1, local2
1205
1206	xor	in5, local3, in5
1207
1208	srl	in5, 8, local3
1209	xor	out5, local2, out5
1210	xor	local3, out5, local3
1211	or	local4, %lo(0x33333333), local4
1212	and	local3, local1, local3
1213	sethi	%hi(0x0000ffff), local1
1214	sll	local3, 8, local2
1215
1216	xor	out5, local3, out5
1217
1218	srl	out5, 2, local3
1219	xor	in5, local2, in5
1220	xor	local3, in5, local3
1221	or	local1, %lo(0x0000ffff), local1
1222	and	local3, local4, local3
1223	sethi	%hi(0x0f0f0f0f), local4
1224	sll	local3, 2, local2
1225
1226
1227	xor	in5, local3, in5
1228
1229
1230	srl	in5, 16, local3
1231	xor	out5, local2, out5
1232	xor	local3, out5, local3
1233	or	local4, %lo(0x0f0f0f0f), local4
1234	and	local3, local1, local3
1235	sll	local3, 16, local2
1236
1237	xor	out5, local3, local1
1238
1239	srl	local1, 4, local3
1240	xor	in5, local2, in5
1241	xor	local3, in5, local3
1242	and	local3, local4, local3
1243	sll	local3, 4, local2
1244
1245	xor	in5, local3, in5
1246
1247	! optional store:
1248
1249	st in5, [in0]
1250
1251	xor	local1, local2, out5
1252
1253	st out5, [in0+4]
1254
1255            ! 1 for store to [in0]
1256
1257	ret
1258	restore
1259
1260.encrypt.dec:
1261
1262	add	in1, 120, in3             ! use last subkey for first round
1263
1264	! parameter 6  1/2 for include encryption/decryption
1265	! parameter 7  1 for move in1 to in3
1266	! parameter 8  1 for move in3 to in4, 2 for move in4 to in3
1267
1268
1269
1270! ip_macro
1271! in5 out5 in5 out5 in4 2 0 1
1272
1273	ld	[out2+256], local1
1274	srl	out5, 4, local4
1275
1276	xor	local4, in5, local4
1277	nop
1278
1279	ld	[out2+260], local2
1280	and	local4, local1, local4
1281	mov in3, in4
1282
1283
1284	ld	[out2+280], out4          ! loop counter
1285	sll	local4, 4, local1
1286	xor	in5, local4, in5
1287
1288	ld	[out2+264], local3
1289	srl	in5, 16, local4
1290	xor	out5, local1, out5
1291
1292
1293	xor	local4, out5, local4
1294	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
1295
1296
1297	and	local4, local2, local4
1298	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
1299
1300	sll	local4, 16, local1
1301	xor	out5, local4, out5
1302
1303	srl	out5, 2, local4
1304	xor	in5, local1, in5
1305
1306	sethi	%hi(16711680), local5
1307	xor	local4, in5, local4
1308
1309	and	local4, local3, local4
1310	or	local5, 255, local5
1311
1312	sll	local4, 2, local2
1313	xor	in5, local4, in5
1314
1315	srl	in5, 8, local4
1316	xor	out5, local2, out5
1317
1318	xor	local4, out5, local4
1319	add	global1, 768, global4
1320
1321	and	local4, local5, local4
1322	add	global1, 1024, global5
1323
1324	ld	[out2+272], local7
1325	sll	local4, 8, local1
1326	xor	out5, local4, out5
1327
1328	srl	out5, 1, local4
1329	xor	in5, local1, in5
1330
1331	ld	[in4], out0                ! key 7531
1332	xor	local4, in5, local4
1333	add	global1, 256, global2
1334
1335	ld	[in4+4], out1              ! key 8642
1336	and	local4, local7, local4
1337	add	global1, 512, global3
1338
1339	sll	local4, 1, local1
1340	xor	in5, local4, in5
1341
1342	sll	in5, 3, local3
1343	xor	out5, local1, out5
1344
1345	sll	out5, 3, local2
1346	add	global1, 1280, local6     ! address sbox 8
1347
1348	srl	in5, 29, local4
1349	add	global1, 1792, out3       ! address sbox 8
1350
1351	srl	out5, 29, local1
1352	or	local4, local3, in5
1353
1354	or	local2, local1, out5
1355
1356
1357
1358
1359
1360		ld	[out2+284], local5     ! 0x0000FC00 used in the rounds
1361		or	local2, local1, out5
1362		xor	in5, out0, local1
1363
1364		call .des_dec.1
1365		and	local1, 252, local1
1366
1367
1368 ! include dec,  ks in4
1369
1370
1371
1372! fp_macro
1373! out5 in5 1
1374
1375	! initially undo the rotate 3 left done after initial permutation
1376	! original left is received shifted 3 right and 29 left in local3/4
1377
1378	sll	in5, 29, local1
1379	or	local3, local4, out5
1380
1381	srl	in5, 3, in5
1382	sethi	%hi(0x55555555), local2
1383
1384	or	in5, local1, in5
1385	or	local2, %lo(0x55555555), local2
1386
1387	srl	in5, 1, local3
1388	sethi	%hi(0x00ff00ff), local1
1389	xor	local3, out5, local3
1390	or	local1, %lo(0x00ff00ff), local1
1391	and	local3, local2, local3
1392	sethi	%hi(0x33333333), local4
1393	sll	local3, 1, local2
1394
1395	xor	out5, local3, out5
1396
1397	srl	out5, 8, local3
1398	xor	in5, local2, in5
1399	xor	local3, in5, local3
1400	or	local4, %lo(0x33333333), local4
1401	and	local3, local1, local3
1402	sethi	%hi(0x0000ffff), local1
1403	sll	local3, 8, local2
1404
1405	xor	in5, local3, in5
1406
1407	srl	in5, 2, local3
1408	xor	out5, local2, out5
1409	xor	local3, out5, local3
1410	or	local1, %lo(0x0000ffff), local1
1411	and	local3, local4, local3
1412	sethi	%hi(0x0f0f0f0f), local4
1413	sll	local3, 2, local2
1414
1415
1416	xor	out5, local3, out5
1417
1418
1419	srl	out5, 16, local3
1420	xor	in5, local2, in5
1421	xor	local3, in5, local3
1422	or	local4, %lo(0x0f0f0f0f), local4
1423	and	local3, local1, local3
1424	sll	local3, 16, local2
1425
1426	xor	in5, local3, local1
1427
1428	srl	local1, 4, local3
1429	xor	out5, local2, out5
1430	xor	local3, out5, local3
1431	and	local3, local4, local3
1432	sll	local3, 4, local2
1433
1434	xor	out5, local3, out5
1435
1436	! optional store:
1437
1438	st out5, [in0]
1439
1440	xor	local1, local2, in5
1441
1442	st in5, [in0+4]
1443
1444            ! 1 for store to [in0]
1445
1446	ret
1447	restore
1448
1449.DES_encrypt1.end:
1450	.size	 DES_encrypt1,.DES_encrypt1.end-DES_encrypt1
1451
1452
1453! void DES_encrypt2(data, ks, enc)
1454!*********************************
1455
1456	! encrypts/decrypts without initial/final permutation
1457
1458	.align 32
1459	.global DES_encrypt2
1460	.type	 DES_encrypt2,#function
1461
1462DES_encrypt2:
1463
1464	save	%sp, FRAME, %sp
1465
1466	sethi	%hi(_PIC_DES_SPtrans-1f),global1
1467	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
14681:	call	.+8
1469	add	%o7,global1,global1
1470	sub	global1,_PIC_DES_SPtrans-.des_and,out2
1471
1472	! Set sbox address 1 to 6 and rotate halfs 3 left
1473	! Errors caught by destest? Yes. Still? *NO*
1474
1475	!sethi	%hi(DES_SPtrans), global1 ! address sbox 1
1476
1477	!or	global1, %lo(DES_SPtrans), global1  ! sbox 1
1478
1479	add	global1, 256, global2     ! sbox 2
1480	add	global1, 512, global3     ! sbox 3
1481
1482	ld	[in0], out5               ! right
1483	add	global1, 768, global4     ! sbox 4
1484	add	global1, 1024, global5    ! sbox 5
1485
1486	ld	[in0+4], in5              ! left
1487	add	global1, 1280, local6     ! sbox 6
1488	add	global1, 1792, out3       ! sbox 8
1489
1490	! rotate
1491
1492	sll	in5, 3, local5
1493	mov	in1, in3                  ! key address to in3
1494
1495	sll	out5, 3, local7
1496	srl	in5, 29, in5
1497
1498	srl	out5, 29, out5
1499	add	in5, local5, in5
1500
1501	add	out5, local7, out5
1502	cmp	in2, 0
1503
1504	! we use our own stackframe
1505
1506#ifdef __sparc_v9__
1507	be,pn	%icc, .encrypt2.dec       ! decryption
1508#else
1509	be	.encrypt2.dec
1510#endif
1511	STPTR	in0, [%sp+BIAS+ARG0+0*ARGSZ]
1512
1513	ld	[in3], out0               ! key 7531 first round
1514	mov	LOOPS, out4               ! loop counter
1515
1516	ld	[in3+4], out1             ! key 8642 first round
1517	sethi	%hi(0x0000FC00), local5
1518
1519	call .des_enc
1520	mov	in3, in4
1521
1522	! rotate
1523	sll	in5, 29, in0
1524	srl	in5, 3, in5
1525	sll	out5, 29, in1
1526	add	in5, in0, in5
1527	srl	out5, 3, out5
1528	LDPTR	[%sp+BIAS+ARG0+0*ARGSZ], in0
1529	add	out5, in1, out5
1530	st	in5, [in0]
1531	st	out5, [in0+4]
1532
1533	ret
1534	restore
1535
1536
1537.encrypt2.dec:
1538
1539	add in3, 120, in4
1540
1541	ld	[in4], out0               ! key 7531 first round
1542	mov	LOOPS, out4               ! loop counter
1543
1544	ld	[in4+4], out1             ! key 8642 first round
1545	sethi	%hi(0x0000FC00), local5
1546
1547	mov	in5, local1               ! left expected in out5
1548	mov	out5, in5
1549
1550	call .des_dec
1551	mov	local1, out5
1552
1553.encrypt2.finish:
1554
1555	! rotate
1556	sll	in5, 29, in0
1557	srl	in5, 3, in5
1558	sll	out5, 29, in1
1559	add	in5, in0, in5
1560	srl	out5, 3, out5
1561	LDPTR	[%sp+BIAS+ARG0+0*ARGSZ], in0
1562	add	out5, in1, out5
1563	st	out5, [in0]
1564	st	in5, [in0+4]
1565
1566	ret
1567	restore
1568
1569.DES_encrypt2.end:
1570	.size	 DES_encrypt2, .DES_encrypt2.end-DES_encrypt2
1571
1572
1573! void DES_encrypt3(data, ks1, ks2, ks3)
1574! **************************************
1575
1576	.align 32
1577	.global DES_encrypt3
1578	.type	 DES_encrypt3,#function
1579
1580DES_encrypt3:
1581
1582	save	%sp, FRAME, %sp
1583
1584	sethi	%hi(_PIC_DES_SPtrans-1f),global1
1585	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
15861:	call	.+8
1587	add	%o7,global1,global1
1588	sub	global1,_PIC_DES_SPtrans-.des_and,out2
1589
1590	ld	[in0], in5                ! left
1591	add	in2, 120, in4             ! ks2
1592
1593	ld	[in0+4], out5             ! right
1594	mov	in3, in2                  ! save ks3
1595
1596	! parameter 6  1/2 for include encryption/decryption
1597	! parameter 7  1 for mov in1 to in3
1598	! parameter 8  1 for mov in3 to in4
1599	! parameter 9  1 for load ks3 and ks2 to in4 and in3
1600
1601
1602
1603! ip_macro
1604! in5 out5 out5 in5 in3 1 1 0 0
1605
1606	ld	[out2+256], local1
1607	srl	out5, 4, local4
1608
1609	xor	local4, in5, local4
1610	mov in1, in3
1611
1612	ld	[out2+260], local2
1613	and	local4, local1, local4
1614
1615
1616
1617	ld	[out2+280], out4          ! loop counter
1618	sll	local4, 4, local1
1619	xor	in5, local4, in5
1620
1621	ld	[out2+264], local3
1622	srl	in5, 16, local4
1623	xor	out5, local1, out5
1624
1625
1626	xor	local4, out5, local4
1627	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
1628
1629
1630	and	local4, local2, local4
1631	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
1632
1633	sll	local4, 16, local1
1634	xor	out5, local4, out5
1635
1636	srl	out5, 2, local4
1637	xor	in5, local1, in5
1638
1639	sethi	%hi(16711680), local5
1640	xor	local4, in5, local4
1641
1642	and	local4, local3, local4
1643	or	local5, 255, local5
1644
1645	sll	local4, 2, local2
1646	xor	in5, local4, in5
1647
1648	srl	in5, 8, local4
1649	xor	out5, local2, out5
1650
1651	xor	local4, out5, local4
1652	add	global1, 768, global4
1653
1654	and	local4, local5, local4
1655	add	global1, 1024, global5
1656
1657	ld	[out2+272], local7
1658	sll	local4, 8, local1
1659	xor	out5, local4, out5
1660
1661	srl	out5, 1, local4
1662	xor	in5, local1, in5
1663
1664	ld	[in3], out0                ! key 7531
1665	xor	local4, in5, local4
1666	add	global1, 256, global2
1667
1668	ld	[in3+4], out1              ! key 8642
1669	and	local4, local7, local4
1670	add	global1, 512, global3
1671
1672	sll	local4, 1, local1
1673	xor	in5, local4, in5
1674
1675	sll	in5, 3, local3
1676	xor	out5, local1, out5
1677
1678	sll	out5, 3, local2
1679	add	global1, 1280, local6     ! address sbox 8
1680
1681	srl	in5, 29, local4
1682	add	global1, 1792, out3       ! address sbox 8
1683
1684	srl	out5, 29, local1
1685	or	local4, local3, out5
1686
1687	or	local2, local1, in5
1688
1689
1690
1691		ld	[out2+284], local5     ! 0x0000FC00 used in the rounds
1692		or	local2, local1, in5
1693		xor	out5, out0, local1
1694
1695		call .des_enc.1
1696		and	local1, 252, local1
1697
1698
1699
1700
1701
1702
1703	call	.des_dec
1704	mov	in2, in3                  ! preload ks3
1705
1706	call	.des_enc
1707	nop
1708
1709
1710
1711! fp_macro
1712! in5 out5 1
1713
1714	! initially undo the rotate 3 left done after initial permutation
1715	! original left is received shifted 3 right and 29 left in local3/4
1716
1717	sll	out5, 29, local1
1718	or	local3, local4, in5
1719
1720	srl	out5, 3, out5
1721	sethi	%hi(0x55555555), local2
1722
1723	or	out5, local1, out5
1724	or	local2, %lo(0x55555555), local2
1725
1726	srl	out5, 1, local3
1727	sethi	%hi(0x00ff00ff), local1
1728	xor	local3, in5, local3
1729	or	local1, %lo(0x00ff00ff), local1
1730	and	local3, local2, local3
1731	sethi	%hi(0x33333333), local4
1732	sll	local3, 1, local2
1733
1734	xor	in5, local3, in5
1735
1736	srl	in5, 8, local3
1737	xor	out5, local2, out5
1738	xor	local3, out5, local3
1739	or	local4, %lo(0x33333333), local4
1740	and	local3, local1, local3
1741	sethi	%hi(0x0000ffff), local1
1742	sll	local3, 8, local2
1743
1744	xor	out5, local3, out5
1745
1746	srl	out5, 2, local3
1747	xor	in5, local2, in5
1748	xor	local3, in5, local3
1749	or	local1, %lo(0x0000ffff), local1
1750	and	local3, local4, local3
1751	sethi	%hi(0x0f0f0f0f), local4
1752	sll	local3, 2, local2
1753
1754
1755	xor	in5, local3, in5
1756
1757
1758	srl	in5, 16, local3
1759	xor	out5, local2, out5
1760	xor	local3, out5, local3
1761	or	local4, %lo(0x0f0f0f0f), local4
1762	and	local3, local1, local3
1763	sll	local3, 16, local2
1764
1765	xor	out5, local3, local1
1766
1767	srl	local1, 4, local3
1768	xor	in5, local2, in5
1769	xor	local3, in5, local3
1770	and	local3, local4, local3
1771	sll	local3, 4, local2
1772
1773	xor	in5, local3, in5
1774
1775	! optional store:
1776
1777	st in5, [in0]
1778
1779	xor	local1, local2, out5
1780
1781	st out5, [in0+4]
1782
1783
1784
1785	ret
1786	restore
1787
1788.DES_encrypt3.end:
1789	.size	 DES_encrypt3,.DES_encrypt3.end-DES_encrypt3
1790
1791
1792! void DES_decrypt3(data, ks1, ks2, ks3)
1793! **************************************
1794
1795	.align 32
1796	.global DES_decrypt3
1797	.type	 DES_decrypt3,#function
1798
1799DES_decrypt3:
1800
1801	save	%sp, FRAME, %sp
1802
1803	sethi	%hi(_PIC_DES_SPtrans-1f),global1
1804	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
18051:	call	.+8
1806	add	%o7,global1,global1
1807	sub	global1,_PIC_DES_SPtrans-.des_and,out2
1808
1809	ld	[in0], in5                ! left
1810	add	in3, 120, in4             ! ks3
1811
1812	ld	[in0+4], out5             ! right
1813	mov	in2, in3                  ! ks2
1814
1815	! parameter 6  1/2 for include encryption/decryption
1816	! parameter 7  1 for mov in1 to in3
1817	! parameter 8  1 for mov in3 to in4
1818	! parameter 9  1 for load ks3 and ks2 to in4 and in3
1819
1820
1821
1822! ip_macro
1823! in5 out5 in5 out5 in4 2 0 0 0
1824
1825	ld	[out2+256], local1
1826	srl	out5, 4, local4
1827
1828	xor	local4, in5, local4
1829	nop
1830
1831	ld	[out2+260], local2
1832	and	local4, local1, local4
1833
1834
1835
1836	ld	[out2+280], out4          ! loop counter
1837	sll	local4, 4, local1
1838	xor	in5, local4, in5
1839
1840	ld	[out2+264], local3
1841	srl	in5, 16, local4
1842	xor	out5, local1, out5
1843
1844
1845	xor	local4, out5, local4
1846	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
1847
1848
1849	and	local4, local2, local4
1850	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
1851
1852	sll	local4, 16, local1
1853	xor	out5, local4, out5
1854
1855	srl	out5, 2, local4
1856	xor	in5, local1, in5
1857
1858	sethi	%hi(16711680), local5
1859	xor	local4, in5, local4
1860
1861	and	local4, local3, local4
1862	or	local5, 255, local5
1863
1864	sll	local4, 2, local2
1865	xor	in5, local4, in5
1866
1867	srl	in5, 8, local4
1868	xor	out5, local2, out5
1869
1870	xor	local4, out5, local4
1871	add	global1, 768, global4
1872
1873	and	local4, local5, local4
1874	add	global1, 1024, global5
1875
1876	ld	[out2+272], local7
1877	sll	local4, 8, local1
1878	xor	out5, local4, out5
1879
1880	srl	out5, 1, local4
1881	xor	in5, local1, in5
1882
1883	ld	[in4], out0                ! key 7531
1884	xor	local4, in5, local4
1885	add	global1, 256, global2
1886
1887	ld	[in4+4], out1              ! key 8642
1888	and	local4, local7, local4
1889	add	global1, 512, global3
1890
1891	sll	local4, 1, local1
1892	xor	in5, local4, in5
1893
1894	sll	in5, 3, local3
1895	xor	out5, local1, out5
1896
1897	sll	out5, 3, local2
1898	add	global1, 1280, local6     ! address sbox 8
1899
1900	srl	in5, 29, local4
1901	add	global1, 1792, out3       ! address sbox 8
1902
1903	srl	out5, 29, local1
1904	or	local4, local3, in5
1905
1906	or	local2, local1, out5
1907
1908
1909
1910
1911
1912		ld	[out2+284], local5     ! 0x0000FC00 used in the rounds
1913		or	local2, local1, out5
1914		xor	in5, out0, local1
1915
1916		call .des_dec.1
1917		and	local1, 252, local1
1918
1919
1920
1921
1922	call	.des_enc
1923	add	in1, 120, in4             ! preload ks1
1924
1925	call	.des_dec
1926	nop
1927
1928
1929
1930! fp_macro
1931! out5 in5 1
1932
1933	! initially undo the rotate 3 left done after initial permutation
1934	! original left is received shifted 3 right and 29 left in local3/4
1935
1936	sll	in5, 29, local1
1937	or	local3, local4, out5
1938
1939	srl	in5, 3, in5
1940	sethi	%hi(0x55555555), local2
1941
1942	or	in5, local1, in5
1943	or	local2, %lo(0x55555555), local2
1944
1945	srl	in5, 1, local3
1946	sethi	%hi(0x00ff00ff), local1
1947	xor	local3, out5, local3
1948	or	local1, %lo(0x00ff00ff), local1
1949	and	local3, local2, local3
1950	sethi	%hi(0x33333333), local4
1951	sll	local3, 1, local2
1952
1953	xor	out5, local3, out5
1954
1955	srl	out5, 8, local3
1956	xor	in5, local2, in5
1957	xor	local3, in5, local3
1958	or	local4, %lo(0x33333333), local4
1959	and	local3, local1, local3
1960	sethi	%hi(0x0000ffff), local1
1961	sll	local3, 8, local2
1962
1963	xor	in5, local3, in5
1964
1965	srl	in5, 2, local3
1966	xor	out5, local2, out5
1967	xor	local3, out5, local3
1968	or	local1, %lo(0x0000ffff), local1
1969	and	local3, local4, local3
1970	sethi	%hi(0x0f0f0f0f), local4
1971	sll	local3, 2, local2
1972
1973
1974	xor	out5, local3, out5
1975
1976
1977	srl	out5, 16, local3
1978	xor	in5, local2, in5
1979	xor	local3, in5, local3
1980	or	local4, %lo(0x0f0f0f0f), local4
1981	and	local3, local1, local3
1982	sll	local3, 16, local2
1983
1984	xor	in5, local3, local1
1985
1986	srl	local1, 4, local3
1987	xor	out5, local2, out5
1988	xor	local3, out5, local3
1989	and	local3, local4, local3
1990	sll	local3, 4, local2
1991
1992	xor	out5, local3, out5
1993
1994	! optional store:
1995
1996	st out5, [in0]
1997
1998	xor	local1, local2, in5
1999
2000	st in5, [in0+4]
2001
2002
2003
2004	ret
2005	restore
2006
2007.DES_decrypt3.end:
2008	.size	 DES_decrypt3,.DES_decrypt3.end-DES_decrypt3
2009
2010! void DES_ncbc_encrypt(input, output, length, schedule, ivec, enc)
2011! *****************************************************************
2012
2013
2014	.align 32
2015	.global DES_ncbc_encrypt
2016	.type	 DES_ncbc_encrypt,#function
2017
2018DES_ncbc_encrypt:
2019
2020	save	%sp, FRAME, %sp
2021
2022
2023
2024
2025
2026	sethi	%hi(_PIC_DES_SPtrans-1f),global1
2027	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
20281:	call	.+8
2029	add	%o7,global1,global1
2030	sub	global1,_PIC_DES_SPtrans-.des_and,out2
2031
2032	cmp	in5, 0                    ! enc
2033
2034#ifdef __sparc_v9__
2035	be,pn	%icc, .ncbc.dec
2036#else
2037	be	.ncbc.dec
2038#endif
2039	STPTR	in4,  [%sp+BIAS+ARG0+4*ARGSZ]
2040
2041	! addr  left  right  temp  label
2042
2043
2044! load_little_endian
2045! in4 in5 out5 local3 .LLE1
2046
2047	! first in memory to rightmost in register
2048
2049#ifdef __sparc_v9__
2050	andcc	in4, 3, global0
2051	bne,pn	%icc, .LLE1
2052	nop
2053
2054	lda	[in4] 0x88, in5
2055	add	in4, 4, local3
2056
2057	ba,pt	%icc, .LLE1a
2058	lda	[local3] 0x88, out5
2059#endif
2060
2061.LLE1:
2062	ldub	[in4+3], in5
2063
2064	ldub	[in4+2], local3
2065	sll	in5, 8, in5
2066	or	in5, local3, in5
2067
2068	ldub	[in4+1], local3
2069	sll	in5, 8, in5
2070	or	in5, local3, in5
2071
2072	ldub	[in4+0], local3
2073	sll	in5, 8, in5
2074	or	in5, local3, in5
2075
2076
2077	ldub	[in4+3+4], out5
2078
2079	ldub	[in4+2+4], local3
2080	sll	out5, 8, out5
2081	or	out5, local3, out5
2082
2083	ldub	[in4+1+4], local3
2084	sll	out5, 8, out5
2085	or	out5, local3, out5
2086
2087	ldub	[in4+0+4], local3
2088	sll	out5, 8, out5
2089	or	out5, local3, out5
2090.LLE1a:
2091
2092  ! iv
2093
2094	addcc	in2, -8, in2              ! bytes missing when first block done
2095
2096#ifdef __sparc_v9__
2097	bl,pn	%icc, .ncbc.enc.seven.or.less
2098#else
2099	bl	.ncbc.enc.seven.or.less
2100#endif
2101	mov	in3, in4                  ! schedule
2102
2103.ncbc.enc.next.block:
2104
2105
2106
2107! load_little_endian
2108! in0 out4 global4 local3 .LLE2
2109
2110	! first in memory to rightmost in register
2111
2112#ifdef __sparc_v9__
2113	andcc	in0, 3, global0
2114	bne,pn	%icc, .LLE2
2115	nop
2116
2117	lda	[in0] 0x88, out4
2118	add	in0, 4, local3
2119
2120	ba,pt	%icc, .LLE2a
2121	lda	[local3] 0x88, global4
2122#endif
2123
2124.LLE2:
2125	ldub	[in0+3], out4
2126
2127	ldub	[in0+2], local3
2128	sll	out4, 8, out4
2129	or	out4, local3, out4
2130
2131	ldub	[in0+1], local3
2132	sll	out4, 8, out4
2133	or	out4, local3, out4
2134
2135	ldub	[in0+0], local3
2136	sll	out4, 8, out4
2137	or	out4, local3, out4
2138
2139
2140	ldub	[in0+3+4], global4
2141
2142	ldub	[in0+2+4], local3
2143	sll	global4, 8, global4
2144	or	global4, local3, global4
2145
2146	ldub	[in0+1+4], local3
2147	sll	global4, 8, global4
2148	or	global4, local3, global4
2149
2150	ldub	[in0+0+4], local3
2151	sll	global4, 8, global4
2152	or	global4, local3, global4
2153.LLE2a:
2154
2155  ! block
2156
2157.ncbc.enc.next.block_1:
2158
2159	xor	in5, out4, in5            ! iv xor
2160	xor	out5, global4, out5       ! iv xor
2161
2162	! parameter 8  1 for move in3 to in4, 2 for move in4 to in3
2163
2164
2165! ip_macro
2166! in5 out5 out5 in5 in3 0 0 2
2167
2168	ld	[out2+256], local1
2169	srl	out5, 4, local4
2170
2171	xor	local4, in5, local4
2172	nop
2173
2174	ld	[out2+260], local2
2175	and	local4, local1, local4
2176
2177	mov in4, in3
2178
2179	ld	[out2+280], out4          ! loop counter
2180	sll	local4, 4, local1
2181	xor	in5, local4, in5
2182
2183	ld	[out2+264], local3
2184	srl	in5, 16, local4
2185	xor	out5, local1, out5
2186
2187
2188	xor	local4, out5, local4
2189	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
2190
2191
2192	and	local4, local2, local4
2193	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
2194
2195	sll	local4, 16, local1
2196	xor	out5, local4, out5
2197
2198	srl	out5, 2, local4
2199	xor	in5, local1, in5
2200
2201	sethi	%hi(16711680), local5
2202	xor	local4, in5, local4
2203
2204	and	local4, local3, local4
2205	or	local5, 255, local5
2206
2207	sll	local4, 2, local2
2208	xor	in5, local4, in5
2209
2210	srl	in5, 8, local4
2211	xor	out5, local2, out5
2212
2213	xor	local4, out5, local4
2214	add	global1, 768, global4
2215
2216	and	local4, local5, local4
2217	add	global1, 1024, global5
2218
2219	ld	[out2+272], local7
2220	sll	local4, 8, local1
2221	xor	out5, local4, out5
2222
2223	srl	out5, 1, local4
2224	xor	in5, local1, in5
2225
2226	ld	[in3], out0                ! key 7531
2227	xor	local4, in5, local4
2228	add	global1, 256, global2
2229
2230	ld	[in3+4], out1              ! key 8642
2231	and	local4, local7, local4
2232	add	global1, 512, global3
2233
2234	sll	local4, 1, local1
2235	xor	in5, local4, in5
2236
2237	sll	in5, 3, local3
2238	xor	out5, local1, out5
2239
2240	sll	out5, 3, local2
2241	add	global1, 1280, local6     ! address sbox 8
2242
2243	srl	in5, 29, local4
2244	add	global1, 1792, out3       ! address sbox 8
2245
2246	srl	out5, 29, local1
2247	or	local4, local3, out5
2248
2249	or	local2, local1, in5
2250
2251
2252
2253
2254
2255
2256.ncbc.enc.next.block_2:
2257
2258!//	call .des_enc                     ! compares in2 to 8
2259!	rounds inlined for alignment purposes
2260
2261	add	global1, 768, global4     ! address sbox 4 since register used below
2262
2263
2264
2265! rounds_macro
2266! in5 out5 1 .ncbc.enc.1 in3 in4
2267
2268	xor	out5, out0, local1
2269
2270	ld	[out2+284], local5        ! 0x0000FC00
2271	ba	.ncbc.enc.1
2272	and	local1, 252, local1
2273
2274	.align 32
2275
2276.ncbc.enc.1:
2277	! local6 is address sbox 6
2278	! out3   is address sbox 8
2279	! out4   is loop counter
2280
2281	ld	[global1+local1], local1
2282	xor	out5, out1, out1            ! 8642
2283	xor	out5, out0, out0            ! 7531
2284	! fmovs	%f0, %f0                  ! fxor used for alignment
2285
2286	srl	out1, 4, local0           ! rotate 4 right
2287	and	out0, local5, local3      ! 3
2288	! fmovs	%f0, %f0
2289
2290	ld	[in3+1*8], local7         ! key 7531 next round
2291	srl	local3, 8, local3         ! 3
2292	and	local0, 252, local2       ! 2
2293	! fmovs	%f0, %f0
2294
2295	ld	[global3+local3],local3   ! 3
2296	sll	out1, 28, out1            ! rotate
2297	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
2298
2299	ld	[global2+local2], local2  ! 2
2300	srl	out0, 24, local1          ! 7
2301	or	out1, local0, out1        ! rotate
2302
2303	ldub	[out2+local1], local1     ! 7 (and 0xFC)
2304	srl	out1, 24, local0          ! 8
2305	and	out1, local5, local4      ! 4
2306
2307	ldub	[out2+local0], local0     ! 8 (and 0xFC)
2308	srl	local4, 8, local4         ! 4
2309	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
2310
2311	ld	[global4+local4],local4   ! 4
2312	srl	out1, 16, local2          ! 6
2313	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
2314
2315	ld	[out3+local0],local0      ! 8
2316	and	local2, 252, local2       ! 6
2317	add	global1, 1536, local5     ! address sbox 7
2318
2319	ld	[local6+local2], local2   ! 6
2320	srl	out0, 16, local3          ! 5
2321	xor	in5, local4, in5            ! 4 finished
2322
2323	ld	[local5+local1],local1    ! 7
2324	and	local3, 252, local3       ! 5
2325	xor	in5, local0, in5            ! 8 finished
2326
2327	ld	[global5+local3],local3   ! 5
2328	xor	in5, local2, in5            ! 6 finished
2329	subcc	out4, 1, out4
2330
2331	ld	[in3+1*8+4], out0         ! key 8642 next round
2332	xor	in5, local7, local2        ! sbox 5 next round
2333	xor	in5, local1, in5            ! 7 finished
2334
2335	srl	local2, 16, local2        ! sbox 5 next round
2336	xor	in5, local3, in5            ! 5 finished
2337
2338	ld	[in3+1*16+4], out1        ! key 8642 next round again
2339	and	local2, 252, local2       ! sbox5 next round
2340! next round
2341	xor	in5, local7, local7        ! 7531
2342
2343	ld	[global5+local2], local2  ! 5
2344	srl	local7, 24, local3        ! 7
2345	xor	in5, out0, out0            ! 8642
2346
2347	ldub	[out2+local3], local3     ! 7 (and 0xFC)
2348	srl	out0, 4, local0           ! rotate 4 right
2349	and	local7, 252, local1       ! 1
2350
2351	sll	out0, 28, out0            ! rotate
2352	xor	out5, local2, out5            ! 5 finished local2 used
2353
2354	srl	local0, 8, local4         ! 4
2355	and	local0, 252, local2       ! 2
2356	ld	[local5+local3], local3   ! 7
2357
2358	srl	local0, 16, local5        ! 6
2359	or	out0, local0, out0        ! rotate
2360	ld	[global2+local2], local2  ! 2
2361
2362	srl	out0, 24, local0
2363	ld	[in3+1*16], out0          ! key 7531 next round
2364	and	local4, 252, local4	  ! 4
2365
2366	and	local5, 252, local5       ! 6
2367	ld	[global4+local4], local4  ! 4
2368	xor	out5, local3, out5            ! 7 finished local3 used
2369
2370	and	local0, 252, local0       ! 8
2371	ld	[local6+local5], local5   ! 6
2372	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
2373
2374	srl	local7, 8, local2         ! 3 start
2375	ld	[out3+local0], local0     ! 8
2376	xor	out5, local4, out5            ! 4 finished
2377
2378	and	local2, 252, local2       ! 3
2379	ld	[global1+local1], local1  ! 1
2380	xor	out5, local5, out5            ! 6 finished local5 used
2381
2382	ld	[global3+local2], local2  ! 3
2383	xor	out5, local0, out5            ! 8 finished
2384	add	in3, 1*16, in3             ! enc add 8, dec add -8 to key pointer
2385
2386	ld	[out2+284], local5        ! 0x0000FC00
2387	xor	out5, out0, local4          ! sbox 1 next round
2388	xor	out5, local1, out5            ! 1 finished
2389
2390	xor	out5, local2, out5            ! 3 finished
2391#ifdef __sparc_v9__
2392	bne,pt	%icc, .ncbc.enc.1
2393#else
2394	bne	.ncbc.enc.1
2395#endif
2396	and	local4, 252, local1       ! sbox 1 next round
2397
2398! two rounds more:
2399
2400	ld	[global1+local1], local1
2401	xor	out5, out1, out1
2402	xor	out5, out0, out0
2403
2404	srl	out1, 4, local0           ! rotate
2405	and	out0, local5, local3
2406
2407	ld	[in3+1*8], local7         ! key 7531
2408	srl	local3, 8, local3
2409	and	local0, 252, local2
2410
2411	ld	[global3+local3],local3
2412	sll	out1, 28, out1            ! rotate
2413	xor	in5, local1, in5            ! 1 finished, local1 now sbox 7
2414
2415	ld	[global2+local2], local2
2416	srl	out0, 24, local1
2417	or	out1, local0, out1        ! rotate
2418
2419	ldub	[out2+local1], local1
2420	srl	out1, 24, local0
2421	and	out1, local5, local4
2422
2423	ldub	[out2+local0], local0
2424	srl	local4, 8, local4
2425	xor	in5, local2, in5            ! 2 finished local2 now sbox 6
2426
2427	ld	[global4+local4],local4
2428	srl	out1, 16, local2
2429	xor	in5, local3, in5            ! 3 finished local3 now sbox 5
2430
2431	ld	[out3+local0],local0
2432	and	local2, 252, local2
2433	add	global1, 1536, local5     ! address sbox 7
2434
2435	ld	[local6+local2], local2
2436	srl	out0, 16, local3
2437	xor	in5, local4, in5            ! 4 finished
2438
2439	ld	[local5+local1],local1
2440	and	local3, 252, local3
2441	xor	in5, local0, in5
2442
2443	ld	[global5+local3],local3
2444	xor	in5, local2, in5            ! 6 finished
2445	cmp	in2, 8
2446
2447	ld	[out2+280], out4  ! loop counter
2448	xor	in5, local7, local2        ! sbox 5 next round
2449	xor	in5, local1, in5            ! 7 finished
2450
2451	ld	[in3+1*8+4], out0
2452	srl	local2, 16, local2        ! sbox 5 next round
2453	xor	in5, local3, in5            ! 5 finished
2454
2455	and	local2, 252, local2
2456! next round (two rounds more)
2457	xor	in5, local7, local7        ! 7531
2458
2459	ld	[global5+local2], local2
2460	srl	local7, 24, local3
2461	xor	in5, out0, out0            ! 8642
2462
2463	ldub	[out2+local3], local3
2464	srl	out0, 4, local0           ! rotate
2465	and	local7, 252, local1
2466
2467	sll	out0, 28, out0            ! rotate
2468	xor	out5, local2, out5            ! 5 finished local2 used
2469
2470	srl	local0, 8, local4
2471	and	local0, 252, local2
2472	ld	[local5+local3], local3
2473
2474	srl	local0, 16, local5
2475	or	out0, local0, out0        ! rotate
2476	ld	[global2+local2], local2
2477
2478	srl	out0, 24, local0
2479	ld	[in4], out0   ! key next encryption/decryption
2480	and	local4, 252, local4
2481
2482	and	local5, 252, local5
2483	ld	[global4+local4], local4
2484	xor	out5, local3, out5            ! 7 finished local3 used
2485
2486	and	local0, 252, local0
2487	ld	[local6+local5], local5
2488	xor	out5, local2, out5            ! 2 finished local2 now sbox 3
2489
2490	srl	local7, 8, local2         ! 3 start
2491	ld	[out3+local0], local0
2492	xor	out5, local4, out5
2493
2494	and	local2, 252, local2
2495	ld	[global1+local1], local1
2496	xor	out5, local5, out5            ! 6 finished local5 used
2497
2498	ld	[global3+local2], local2
2499	srl	in5, 3, local3
2500	xor	out5, local0, out5
2501
2502	ld	[in4+4], out1 ! key next encryption/decryption
2503	sll	in5, 29, local4
2504	xor	out5, local1, out5
2505
2506
2507	xor	out5, local2, out5
2508 ! include encryption  ks in3
2509
2510#ifdef __sparc_v9__
2511	bl,pn	%icc, .ncbc.enc.next.block_fp
2512#else
2513	bl	.ncbc.enc.next.block_fp
2514#endif
2515	add	in0, 8, in0               ! input address
2516
2517	! If 8 or more bytes are to be encrypted after this block,
2518	! we combine final permutation for this block with initial
2519	! permutation for next block. Load next block:
2520
2521
2522
2523! load_little_endian
2524! in0 global3 global4 local5 .LLE12
2525
2526	! first in memory to rightmost in register
2527
2528#ifdef __sparc_v9__
2529	andcc	in0, 3, global0
2530	bne,pn	%icc, .LLE12
2531	nop
2532
2533	lda	[in0] 0x88, global3
2534	add	in0, 4, local5
2535
2536	ba,pt	%icc, .LLE12a
2537	lda	[local5] 0x88, global4
2538#endif
2539
2540.LLE12:
2541	ldub	[in0+3], global3
2542
2543	ldub	[in0+2], local5
2544	sll	global3, 8, global3
2545	or	global3, local5, global3
2546
2547	ldub	[in0+1], local5
2548	sll	global3, 8, global3
2549	or	global3, local5, global3
2550
2551	ldub	[in0+0], local5
2552	sll	global3, 8, global3
2553	or	global3, local5, global3
2554
2555
2556	ldub	[in0+3+4], global4
2557
2558	ldub	[in0+2+4], local5
2559	sll	global4, 8, global4
2560	or	global4, local5, global4
2561
2562	ldub	[in0+1+4], local5
2563	sll	global4, 8, global4
2564	or	global4, local5, global4
2565
2566	ldub	[in0+0+4], local5
2567	sll	global4, 8, global4
2568	or	global4, local5, global4
2569.LLE12a:
2570
2571
2572
2573	!  parameter 1   original left
2574	!  parameter 2   original right
2575	!  parameter 3   left ip
2576	!  parameter 4   right ip
2577	!  parameter 5   1: load ks1/ks2 to in3/in4, add 120 to in4
2578	!                2: mov in4 to in3
2579	!
2580	! also adds -8 to length in2 and loads loop counter to out4
2581
2582
2583
2584! fp_ip_macro
2585! out0 out1 global3 global4 2
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595	! out0 in local3, local4
2596
2597	ld	[out2+256], local1
2598	sll	out5, 29, out4
2599	or	local3, local4, out0
2600
2601	srl	out5, 3, out1
2602	mov in4, in3
2603
2604	ld	[out2+272], local5
2605	srl	global4, 4, local0
2606	or	out1, out4, out1
2607
2608	srl	out1, 1, out4
2609	xor	out4, out0, out4
2610
2611	and	out4, local5, out4
2612	xor	local0, global3, local0
2613
2614	sll	out4, 1, local3
2615	xor	out0, out4, out0
2616
2617	and	local0, local1, local0
2618	add	in2, -8, in2
2619
2620	sll	local0, 4, local7
2621	xor	global3, local0, global3
2622
2623	ld	[out2+268], local4
2624	srl	out0, 8, out4
2625	xor	out1, local3, out1
2626	ld	[out2+260], local2
2627	srl	global3, 16, local0
2628	xor	global4, local7, global4
2629	xor	out4, out1, out4
2630	xor	local0, global4, local0
2631	and	out4, local4, out4
2632	and	local0, local2, local0
2633	sll	out4, 8, local3
2634	xor	out1, out4, out1
2635	sll	local0, 16, local7
2636	xor	global4, local0, global4
2637
2638	srl	out1, 2, out4
2639	xor	out0, local3, out0
2640
2641	ld	[out2+264], local3         ! ip3
2642	srl	global4, 2, local0
2643	xor	global3, local7, global3
2644	xor	out4, out0, out4
2645	xor	local0, global3, local0
2646	and	out4, local3, out4
2647	and	local0, local3, local0
2648	sll	out4, 2, local3
2649	xor	out0, out4, out0
2650	sll	local0, 2, local7
2651	xor	global3, local0, global3
2652
2653	srl	out0, 16, out4
2654	xor	out1, local3, out1
2655	srl	global3, 8, local0
2656	xor	global4, local7, global4
2657	xor	out4, out1, out4
2658	xor	local0, global4, local0
2659	and	out4, local2, out4
2660	and	local0, local4, local0
2661	sll	out4, 16, local3
2662	xor	out1, out4, local4
2663	sll	local0, 8, local7
2664	xor	global4, local0, global4
2665
2666	srl	global4, 1, local0
2667	xor	global3, local7, global3
2668
2669	srl	local4, 4, out4
2670	xor	local0, global3, local0
2671
2672	xor	out0, local3, out0
2673	and	local0, local5, local0
2674
2675	sll	local0, 1, local7
2676	xor	out4, out0, out4
2677
2678	xor	global3, local0, global3
2679	xor	global4, local7, global4
2680
2681	sll	global3, 3, local5
2682	and	out4, local1, out4
2683
2684	sll	out4, 4, local3
2685	xor	out0, out4, out0
2686
2687
2688	sll	global4, 3, local2
2689	xor	local4, local3, out1
2690
2691	! reload since used as temporar:
2692
2693	ld	[out2+280], out4          ! loop counter
2694
2695	srl	global3, 29, local0
2696
2697
2698
2699	srl	global4, 29, local7
2700
2701	or	local0, local5, global4
2702	or	local2, local7, global3
2703
2704
2705
2706
2707
2708! store_little_endian
2709! in1 out0 out1 local3 .SLE10
2710
2711	! rightmost in register to first in memory
2712
2713#ifdef __sparc_v9__
2714	andcc	in1, 3, global0
2715	bne,pn	%icc, .SLE10
2716	nop
2717
2718	sta	out0, [in1] 0x88
2719	add	in1, 4, local3
2720
2721	ba,pt	%icc, .SLE10a
2722	sta	out1, [local3] 0x88
2723#endif
2724
2725.SLE10:
2726	and	out0, 255, local3
2727	stub	local3, [in1+0]
2728
2729	srl	out0, 8, local3
2730	and	local3, 255, local3
2731	stub	local3, [in1+1]
2732
2733	srl	out0, 16, local3
2734	and	local3, 255, local3
2735	stub	local3, [in1+2]
2736
2737	srl	out0, 24, local3
2738	stub	local3, [in1+3]
2739
2740
2741	and	out1, 255, local3
2742	stub	local3, [in1+0+4]
2743
2744	srl	out1, 8, local3
2745	and	local3, 255, local3
2746	stub	local3, [in1+1+4]
2747
2748	srl	out1, 16, local3
2749	and	local3, 255, local3
2750	stub	local3, [in1+2+4]
2751
2752	srl	out1, 24, local3
2753	stub	local3, [in1+3+4]
2754
2755.SLE10a:
2756
2757  ! block
2758
2759	ld	[in3], out0               ! key 7531 first round next block
2760	mov 	in5, local1
2761	xor	global3, out5, in5        ! iv xor next block
2762
2763	ld	[in3+4], out1             ! key 8642
2764	add	global1, 512, global3     ! address sbox 3 since register used
2765	xor	global4, local1, out5     ! iv xor next block
2766
2767	ba	.ncbc.enc.next.block_2
2768	add	in1, 8, in1               ! output adress
2769
2770.ncbc.enc.next.block_fp:
2771
2772
2773
2774! fp_macro
2775! in5 out5
2776
2777	! initially undo the rotate 3 left done after initial permutation
2778	! original left is received shifted 3 right and 29 left in local3/4
2779
2780	sll	out5, 29, local1
2781	or	local3, local4, in5
2782
2783	srl	out5, 3, out5
2784	sethi	%hi(0x55555555), local2
2785
2786	or	out5, local1, out5
2787	or	local2, %lo(0x55555555), local2
2788
2789	srl	out5, 1, local3
2790	sethi	%hi(0x00ff00ff), local1
2791	xor	local3, in5, local3
2792	or	local1, %lo(0x00ff00ff), local1
2793	and	local3, local2, local3
2794	sethi	%hi(0x33333333), local4
2795	sll	local3, 1, local2
2796
2797	xor	in5, local3, in5
2798
2799	srl	in5, 8, local3
2800	xor	out5, local2, out5
2801	xor	local3, out5, local3
2802	or	local4, %lo(0x33333333), local4
2803	and	local3, local1, local3
2804	sethi	%hi(0x0000ffff), local1
2805	sll	local3, 8, local2
2806
2807	xor	out5, local3, out5
2808
2809	srl	out5, 2, local3
2810	xor	in5, local2, in5
2811	xor	local3, in5, local3
2812	or	local1, %lo(0x0000ffff), local1
2813	and	local3, local4, local3
2814	sethi	%hi(0x0f0f0f0f), local4
2815	sll	local3, 2, local2
2816
2817
2818	xor	in5, local3, in5
2819
2820
2821	srl	in5, 16, local3
2822	xor	out5, local2, out5
2823	xor	local3, out5, local3
2824	or	local4, %lo(0x0f0f0f0f), local4
2825	and	local3, local1, local3
2826	sll	local3, 16, local2
2827
2828	xor	out5, local3, local1
2829
2830	srl	local1, 4, local3
2831	xor	in5, local2, in5
2832	xor	local3, in5, local3
2833	and	local3, local4, local3
2834	sll	local3, 4, local2
2835
2836	xor	in5, local3, in5
2837
2838	! optional store:
2839
2840
2841
2842	xor	local1, local2, out5
2843
2844
2845
2846
2847
2848
2849
2850! store_little_endian
2851! in1 in5 out5 local3 .SLE1
2852
2853	! rightmost in register to first in memory
2854
2855#ifdef __sparc_v9__
2856	andcc	in1, 3, global0
2857	bne,pn	%icc, .SLE1
2858	nop
2859
2860	sta	in5, [in1] 0x88
2861	add	in1, 4, local3
2862
2863	ba,pt	%icc, .SLE1a
2864	sta	out5, [local3] 0x88
2865#endif
2866
2867.SLE1:
2868	and	in5, 255, local3
2869	stub	local3, [in1+0]
2870
2871	srl	in5, 8, local3
2872	and	local3, 255, local3
2873	stub	local3, [in1+1]
2874
2875	srl	in5, 16, local3
2876	and	local3, 255, local3
2877	stub	local3, [in1+2]
2878
2879	srl	in5, 24, local3
2880	stub	local3, [in1+3]
2881
2882
2883	and	out5, 255, local3
2884	stub	local3, [in1+0+4]
2885
2886	srl	out5, 8, local3
2887	and	local3, 255, local3
2888	stub	local3, [in1+1+4]
2889
2890	srl	out5, 16, local3
2891	and	local3, 255, local3
2892	stub	local3, [in1+2+4]
2893
2894	srl	out5, 24, local3
2895	stub	local3, [in1+3+4]
2896
2897.SLE1a:
2898
2899  ! block
2900
2901	addcc   in2, -8, in2              ! bytes missing when next block done
2902
2903#ifdef __sparc_v9__
2904	bpos,pt	%icc, .ncbc.enc.next.block  ! also jumps if 0
2905#else
2906	bpos	.ncbc.enc.next.block
2907#endif
2908	add	in1, 8, in1
2909
2910.ncbc.enc.seven.or.less:
2911
2912	cmp	in2, -8
2913
2914#ifdef __sparc_v9__
2915	ble,pt	%icc, .ncbc.enc.finish
2916#else
2917	ble	.ncbc.enc.finish
2918#endif
2919	nop
2920
2921	add	in2, 8, local1            ! bytes to load
2922
2923	! addr, length, dest left, dest right, temp, local3, label, ret label
2924
2925
2926! load_n_bytes
2927! in0 local1 local2 local3 .LNB1 .ncbc.enc.next.block_1 .LNB1 .ncbc.enc.next.block_1
2928
2929.LNB1.0:	call	.+8
2930	sll	local1, 2, local3
2931
2932	add	%o7,.LNB1.jmp.table-.LNB1.0,local2
2933
2934	add	local2, local3, local2
2935	mov	0, out4
2936
2937	ld	[local2], local2
2938
2939	jmp	%o7+local2
2940	mov	0, global4
2941
2942.LNB1.7:
2943	ldub	[in0+6], local2
2944	sll	local2, 16, local2
2945	or	global4, local2, global4
2946.LNB1.6:
2947	ldub	[in0+5], local2
2948	sll	local2, 8, local2
2949	or	global4, local2, global4
2950.LNB1.5:
2951	ldub	[in0+4], local2
2952	or	global4, local2, global4
2953.LNB1.4:
2954	ldub	[in0+3], local2
2955	sll	local2, 24, local2
2956	or	out4, local2, out4
2957.LNB1.3:
2958	ldub	[in0+2], local2
2959	sll	local2, 16, local2
2960	or	out4, local2, out4
2961.LNB1.2:
2962	ldub	[in0+1], local2
2963	sll	local2, 8, local2
2964	or	out4, local2, out4
2965.LNB1.1:
2966	ldub	[in0+0], local2
2967	ba	.ncbc.enc.next.block_1
2968	or	out4, local2, out4
2969
2970	.align 4
2971
2972.LNB1.jmp.table:
2973	.word	0
2974	.word	.LNB1.1-.LNB1.0
2975	.word	.LNB1.2-.LNB1.0
2976	.word	.LNB1.3-.LNB1.0
2977	.word	.LNB1.4-.LNB1.0
2978	.word	.LNB1.5-.LNB1.0
2979	.word	.LNB1.6-.LNB1.0
2980	.word	.LNB1.7-.LNB1.0
2981
2982
2983	! Loads 1 to 7 bytes little endian to global4, out4
2984
2985
2986.ncbc.enc.finish:
2987
2988	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , local4
2989
2990
2991! store_little_endian
2992! local4 in5 out5 local5 .SLE2
2993
2994	! rightmost in register to first in memory
2995
2996#ifdef __sparc_v9__
2997	andcc	local4, 3, global0
2998	bne,pn	%icc, .SLE2
2999	nop
3000
3001	sta	in5, [local4] 0x88
3002	add	local4, 4, local5
3003
3004	ba,pt	%icc, .SLE2a
3005	sta	out5, [local5] 0x88
3006#endif
3007
3008.SLE2:
3009	and	in5, 255, local5
3010	stub	local5, [local4+0]
3011
3012	srl	in5, 8, local5
3013	and	local5, 255, local5
3014	stub	local5, [local4+1]
3015
3016	srl	in5, 16, local5
3017	and	local5, 255, local5
3018	stub	local5, [local4+2]
3019
3020	srl	in5, 24, local5
3021	stub	local5, [local4+3]
3022
3023
3024	and	out5, 255, local5
3025	stub	local5, [local4+0+4]
3026
3027	srl	out5, 8, local5
3028	and	local5, 255, local5
3029	stub	local5, [local4+1+4]
3030
3031	srl	out5, 16, local5
3032	and	local5, 255, local5
3033	stub	local5, [local4+2+4]
3034
3035	srl	out5, 24, local5
3036	stub	local5, [local4+3+4]
3037
3038.SLE2a:
3039
3040  ! ivec
3041
3042	ret
3043	restore
3044
3045
3046.ncbc.dec:
3047
3048	STPTR	in0,  [%sp+BIAS+ARG0+0*ARGSZ]
3049	cmp	in2, 0                    ! length
3050	add	in3, 120, in3
3051
3052	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , local7              ! ivec
3053#ifdef __sparc_v9__
3054	ble,pn	%icc, .ncbc.dec.finish
3055#else
3056	ble	.ncbc.dec.finish
3057#endif
3058	mov	in3, in4                  ! schedule
3059
3060	STPTR	in1,  [%sp+BIAS+ARG0+1*ARGSZ]
3061	mov	in0, local5               ! input
3062
3063
3064
3065! load_little_endian
3066! local7 in0 in1 local3 .LLE3
3067
3068	! first in memory to rightmost in register
3069
3070#ifdef __sparc_v9__
3071	andcc	local7, 3, global0
3072	bne,pn	%icc, .LLE3
3073	nop
3074
3075	lda	[local7] 0x88, in0
3076	add	local7, 4, local3
3077
3078	ba,pt	%icc, .LLE3a
3079	lda	[local3] 0x88, in1
3080#endif
3081
3082.LLE3:
3083	ldub	[local7+3], in0
3084
3085	ldub	[local7+2], local3
3086	sll	in0, 8, in0
3087	or	in0, local3, in0
3088
3089	ldub	[local7+1], local3
3090	sll	in0, 8, in0
3091	or	in0, local3, in0
3092
3093	ldub	[local7+0], local3
3094	sll	in0, 8, in0
3095	or	in0, local3, in0
3096
3097
3098	ldub	[local7+3+4], in1
3099
3100	ldub	[local7+2+4], local3
3101	sll	in1, 8, in1
3102	or	in1, local3, in1
3103
3104	ldub	[local7+1+4], local3
3105	sll	in1, 8, in1
3106	or	in1, local3, in1
3107
3108	ldub	[local7+0+4], local3
3109	sll	in1, 8, in1
3110	or	in1, local3, in1
3111.LLE3a:
3112
3113   ! ivec
3114
3115.ncbc.dec.next.block:
3116
3117
3118
3119! load_little_endian
3120! local5 in5 out5 local3 .LLE4
3121
3122	! first in memory to rightmost in register
3123
3124#ifdef __sparc_v9__
3125	andcc	local5, 3, global0
3126	bne,pn	%icc, .LLE4
3127	nop
3128
3129	lda	[local5] 0x88, in5
3130	add	local5, 4, local3
3131
3132	ba,pt	%icc, .LLE4a
3133	lda	[local3] 0x88, out5
3134#endif
3135
3136.LLE4:
3137	ldub	[local5+3], in5
3138
3139	ldub	[local5+2], local3
3140	sll	in5, 8, in5
3141	or	in5, local3, in5
3142
3143	ldub	[local5+1], local3
3144	sll	in5, 8, in5
3145	or	in5, local3, in5
3146
3147	ldub	[local5+0], local3
3148	sll	in5, 8, in5
3149	or	in5, local3, in5
3150
3151
3152	ldub	[local5+3+4], out5
3153
3154	ldub	[local5+2+4], local3
3155	sll	out5, 8, out5
3156	or	out5, local3, out5
3157
3158	ldub	[local5+1+4], local3
3159	sll	out5, 8, out5
3160	or	out5, local3, out5
3161
3162	ldub	[local5+0+4], local3
3163	sll	out5, 8, out5
3164	or	out5, local3, out5
3165.LLE4a:
3166
3167  ! block
3168
3169	! parameter 6  1/2 for include encryption/decryption
3170	! parameter 7  1 for mov in1 to in3
3171	! parameter 8  1 for mov in3 to in4
3172
3173
3174
3175! ip_macro
3176! in5 out5 in5 out5 in4 2 0 1
3177
3178	ld	[out2+256], local1
3179	srl	out5, 4, local4
3180
3181	xor	local4, in5, local4
3182	nop
3183
3184	ld	[out2+260], local2
3185	and	local4, local1, local4
3186	mov in3, in4
3187
3188
3189	ld	[out2+280], out4          ! loop counter
3190	sll	local4, 4, local1
3191	xor	in5, local4, in5
3192
3193	ld	[out2+264], local3
3194	srl	in5, 16, local4
3195	xor	out5, local1, out5
3196
3197
3198	xor	local4, out5, local4
3199	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
3200
3201
3202	and	local4, local2, local4
3203	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
3204
3205	sll	local4, 16, local1
3206	xor	out5, local4, out5
3207
3208	srl	out5, 2, local4
3209	xor	in5, local1, in5
3210
3211	sethi	%hi(16711680), local5
3212	xor	local4, in5, local4
3213
3214	and	local4, local3, local4
3215	or	local5, 255, local5
3216
3217	sll	local4, 2, local2
3218	xor	in5, local4, in5
3219
3220	srl	in5, 8, local4
3221	xor	out5, local2, out5
3222
3223	xor	local4, out5, local4
3224	add	global1, 768, global4
3225
3226	and	local4, local5, local4
3227	add	global1, 1024, global5
3228
3229	ld	[out2+272], local7
3230	sll	local4, 8, local1
3231	xor	out5, local4, out5
3232
3233	srl	out5, 1, local4
3234	xor	in5, local1, in5
3235
3236	ld	[in4], out0                ! key 7531
3237	xor	local4, in5, local4
3238	add	global1, 256, global2
3239
3240	ld	[in4+4], out1              ! key 8642
3241	and	local4, local7, local4
3242	add	global1, 512, global3
3243
3244	sll	local4, 1, local1
3245	xor	in5, local4, in5
3246
3247	sll	in5, 3, local3
3248	xor	out5, local1, out5
3249
3250	sll	out5, 3, local2
3251	add	global1, 1280, local6     ! address sbox 8
3252
3253	srl	in5, 29, local4
3254	add	global1, 1792, out3       ! address sbox 8
3255
3256	srl	out5, 29, local1
3257	or	local4, local3, in5
3258
3259	or	local2, local1, out5
3260
3261
3262
3263
3264
3265		ld	[out2+284], local5     ! 0x0000FC00 used in the rounds
3266		or	local2, local1, out5
3267		xor	in5, out0, local1
3268
3269		call .des_dec.1
3270		and	local1, 252, local1
3271
3272
3273 ! include decryprion  ks in4
3274
3275
3276
3277! fp_macro
3278! out5 in5 0 1
3279
3280	! initially undo the rotate 3 left done after initial permutation
3281	! original left is received shifted 3 right and 29 left in local3/4
3282
3283	sll	in5, 29, local1
3284	or	local3, local4, out5
3285
3286	srl	in5, 3, in5
3287	sethi	%hi(0x55555555), local2
3288
3289	or	in5, local1, in5
3290	or	local2, %lo(0x55555555), local2
3291
3292	srl	in5, 1, local3
3293	sethi	%hi(0x00ff00ff), local1
3294	xor	local3, out5, local3
3295	or	local1, %lo(0x00ff00ff), local1
3296	and	local3, local2, local3
3297	sethi	%hi(0x33333333), local4
3298	sll	local3, 1, local2
3299
3300	xor	out5, local3, out5
3301
3302	srl	out5, 8, local3
3303	xor	in5, local2, in5
3304	xor	local3, in5, local3
3305	or	local4, %lo(0x33333333), local4
3306	and	local3, local1, local3
3307	sethi	%hi(0x0000ffff), local1
3308	sll	local3, 8, local2
3309
3310	xor	in5, local3, in5
3311
3312	srl	in5, 2, local3
3313	xor	out5, local2, out5
3314	xor	local3, out5, local3
3315	or	local1, %lo(0x0000ffff), local1
3316	and	local3, local4, local3
3317	sethi	%hi(0x0f0f0f0f), local4
3318	sll	local3, 2, local2
3319
3320	LDPTR  [%sp+BIAS+ARG0+0*ARGSZ] , local5
3321	xor	out5, local3, out5
3322
3323	LDPTR  [%sp+BIAS+ARG0+1*ARGSZ] , local7
3324	srl	out5, 16, local3
3325	xor	in5, local2, in5
3326	xor	local3, in5, local3
3327	or	local4, %lo(0x0f0f0f0f), local4
3328	and	local3, local1, local3
3329	sll	local3, 16, local2
3330
3331	xor	in5, local3, local1
3332
3333	srl	local1, 4, local3
3334	xor	out5, local2, out5
3335	xor	local3, out5, local3
3336	and	local3, local4, local3
3337	sll	local3, 4, local2
3338
3339	xor	out5, local3, out5
3340
3341	! optional store:
3342
3343
3344
3345	xor	local1, local2, in5
3346
3347
3348
3349 ! 1 for input and output address to local5/7
3350
3351	! in2 is bytes left to be stored
3352	! in2 is compared to 8 in the rounds
3353
3354	xor	out5, in0, out4           ! iv xor
3355#ifdef __sparc_v9__
3356	bl,pn	%icc, .ncbc.dec.seven.or.less
3357#else
3358	bl	.ncbc.dec.seven.or.less
3359#endif
3360	xor	in5, in1, global4         ! iv xor
3361
3362	! Load ivec next block now, since input and output address might be the same.
3363
3364
3365
3366! load_little_endian_inc
3367! local5 in0 in1 local3 .LLE5
3368
3369	! first in memory to rightmost in register
3370
3371#ifdef __sparc_v9__
3372	andcc	local5, 3, global0
3373	bne,pn	%icc, .LLE5
3374	nop
3375
3376	lda	[local5] 0x88, in0
3377	add	local5, 4, local5
3378
3379	lda	[local5] 0x88, in1
3380	ba,pt	%icc, .LLE5a
3381	add	local5, 4, local5
3382#endif
3383
3384.LLE5:
3385	ldub	[local5+3], in0
3386
3387	ldub	[local5+2], local3
3388	sll	in0, 8, in0
3389	or	in0, local3, in0
3390
3391	ldub	[local5+1], local3
3392	sll	in0, 8, in0
3393	or	in0, local3, in0
3394
3395	ldub	[local5+0], local3
3396	sll	in0, 8, in0
3397	or	in0, local3, in0
3398
3399	ldub	[local5+3+4], in1
3400	add	local5, 8, local5
3401
3402	ldub	[local5+2+4-8], local3
3403	sll	in1, 8, in1
3404	or	in1, local3, in1
3405
3406	ldub	[local5+1+4-8], local3
3407	sll	in1, 8, in1
3408	or	in1, local3, in1
3409
3410	ldub	[local5+0+4-8], local3
3411	sll	in1, 8, in1
3412	or	in1, local3, in1
3413.LLE5a:
3414
3415  ! iv
3416
3417
3418
3419! store_little_endian
3420! local7 out4 global4 local3 .SLE3
3421
3422	! rightmost in register to first in memory
3423
3424#ifdef __sparc_v9__
3425	andcc	local7, 3, global0
3426	bne,pn	%icc, .SLE3
3427	nop
3428
3429	sta	out4, [local7] 0x88
3430	add	local7, 4, local3
3431
3432	ba,pt	%icc, .SLE3a
3433	sta	global4, [local3] 0x88
3434#endif
3435
3436.SLE3:
3437	and	out4, 255, local3
3438	stub	local3, [local7+0]
3439
3440	srl	out4, 8, local3
3441	and	local3, 255, local3
3442	stub	local3, [local7+1]
3443
3444	srl	out4, 16, local3
3445	and	local3, 255, local3
3446	stub	local3, [local7+2]
3447
3448	srl	out4, 24, local3
3449	stub	local3, [local7+3]
3450
3451
3452	and	global4, 255, local3
3453	stub	local3, [local7+0+4]
3454
3455	srl	global4, 8, local3
3456	and	local3, 255, local3
3457	stub	local3, [local7+1+4]
3458
3459	srl	global4, 16, local3
3460	and	local3, 255, local3
3461	stub	local3, [local7+2+4]
3462
3463	srl	global4, 24, local3
3464	stub	local3, [local7+3+4]
3465
3466.SLE3a:
3467
3468
3469
3470	STPTR	local5,  [%sp+BIAS+ARG0+0*ARGSZ]
3471	add	local7, 8, local7
3472	addcc   in2, -8, in2
3473
3474#ifdef __sparc_v9__
3475	bg,pt	%icc, .ncbc.dec.next.block
3476#else
3477	bg	.ncbc.dec.next.block
3478#endif
3479	STPTR	local7,  [%sp+BIAS+ARG0+1*ARGSZ]
3480
3481
3482.ncbc.dec.store.iv:
3483
3484	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , local4              ! ivec
3485
3486
3487! store_little_endian
3488! local4 in0 in1 local5 .SLE4
3489
3490	! rightmost in register to first in memory
3491
3492#ifdef __sparc_v9__
3493	andcc	local4, 3, global0
3494	bne,pn	%icc, .SLE4
3495	nop
3496
3497	sta	in0, [local4] 0x88
3498	add	local4, 4, local5
3499
3500	ba,pt	%icc, .SLE4a
3501	sta	in1, [local5] 0x88
3502#endif
3503
3504.SLE4:
3505	and	in0, 255, local5
3506	stub	local5, [local4+0]
3507
3508	srl	in0, 8, local5
3509	and	local5, 255, local5
3510	stub	local5, [local4+1]
3511
3512	srl	in0, 16, local5
3513	and	local5, 255, local5
3514	stub	local5, [local4+2]
3515
3516	srl	in0, 24, local5
3517	stub	local5, [local4+3]
3518
3519
3520	and	in1, 255, local5
3521	stub	local5, [local4+0+4]
3522
3523	srl	in1, 8, local5
3524	and	local5, 255, local5
3525	stub	local5, [local4+1+4]
3526
3527	srl	in1, 16, local5
3528	and	local5, 255, local5
3529	stub	local5, [local4+2+4]
3530
3531	srl	in1, 24, local5
3532	stub	local5, [local4+3+4]
3533
3534.SLE4a:
3535
3536
3537
3538.ncbc.dec.finish:
3539
3540	ret
3541	restore
3542
3543.ncbc.dec.seven.or.less:
3544
3545
3546
3547! load_little_endian_inc
3548! local5 in0 in1 local3 .LLE13
3549
3550	! first in memory to rightmost in register
3551
3552#ifdef __sparc_v9__
3553	andcc	local5, 3, global0
3554	bne,pn	%icc, .LLE13
3555	nop
3556
3557	lda	[local5] 0x88, in0
3558	add	local5, 4, local5
3559
3560	lda	[local5] 0x88, in1
3561	ba,pt	%icc, .LLE13a
3562	add	local5, 4, local5
3563#endif
3564
3565.LLE13:
3566	ldub	[local5+3], in0
3567
3568	ldub	[local5+2], local3
3569	sll	in0, 8, in0
3570	or	in0, local3, in0
3571
3572	ldub	[local5+1], local3
3573	sll	in0, 8, in0
3574	or	in0, local3, in0
3575
3576	ldub	[local5+0], local3
3577	sll	in0, 8, in0
3578	or	in0, local3, in0
3579
3580	ldub	[local5+3+4], in1
3581	add	local5, 8, local5
3582
3583	ldub	[local5+2+4-8], local3
3584	sll	in1, 8, in1
3585	or	in1, local3, in1
3586
3587	ldub	[local5+1+4-8], local3
3588	sll	in1, 8, in1
3589	or	in1, local3, in1
3590
3591	ldub	[local5+0+4-8], local3
3592	sll	in1, 8, in1
3593	or	in1, local3, in1
3594.LLE13a:
3595
3596     ! ivec
3597
3598
3599
3600! store_n_bytes
3601! local7 in2 local3 local4 .SNB1 .ncbc.dec.store.iv .SNB1 .ncbc.dec.store.iv
3602
3603.SNB1.0:	call	.+8
3604	sll	in2, 2, local4
3605
3606	add	%o7,.SNB1.jmp.table-.SNB1.0,local3
3607
3608	add	local3, local4, local3
3609
3610	ld	[local3], local3
3611
3612	jmp	%o7+local3
3613	nop
3614
3615.SNB1.7:
3616	srl	global4, 16, local3
3617	and	local3, 0xff, local3
3618	stub	local3, [local7+6]
3619.SNB1.6:
3620	srl	global4, 8, local3
3621	and	local3, 0xff, local3
3622	stub	local3, [local7+5]
3623.SNB1.5:
3624	and	global4, 0xff, local3
3625	stub	local3, [local7+4]
3626.SNB1.4:
3627	srl	out4, 24, local3
3628	stub	local3, [local7+3]
3629.SNB1.3:
3630	srl	out4, 16, local3
3631	and	local3, 0xff, local3
3632	stub	local3, [local7+2]
3633.SNB1.2:
3634	srl	out4, 8, local3
3635	and	local3, 0xff, local3
3636	stub	local3, [local7+1]
3637.SNB1.1:
3638	and	out4, 0xff, local3
3639
3640
3641	ba	.ncbc.dec.store.iv
3642	stub	local3, [local7]
3643
3644	.align 4
3645
3646.SNB1.jmp.table:
3647
3648	.word	0
3649	.word	.SNB1.1-.SNB1.0
3650	.word	.SNB1.2-.SNB1.0
3651	.word	.SNB1.3-.SNB1.0
3652	.word	.SNB1.4-.SNB1.0
3653	.word	.SNB1.5-.SNB1.0
3654	.word	.SNB1.6-.SNB1.0
3655	.word	.SNB1.7-.SNB1.0
3656
3657
3658
3659.DES_ncbc_encrypt.end:
3660	.size	 DES_ncbc_encrypt, .DES_ncbc_encrypt.end-DES_ncbc_encrypt
3661
3662
3663! void DES_ede3_cbc_encrypt(input, output, lenght, ks1, ks2, ks3, ivec, enc)
3664! **************************************************************************
3665
3666
3667	.align 32
3668	.global DES_ede3_cbc_encrypt
3669	.type	 DES_ede3_cbc_encrypt,#function
3670
3671DES_ede3_cbc_encrypt:
3672
3673	save	%sp, FRAME, %sp
3674
3675
3676
3677
3678
3679	sethi	%hi(_PIC_DES_SPtrans-1f),global1
3680	or	global1,%lo(_PIC_DES_SPtrans-1f),global1
36811:	call	.+8
3682	add	%o7,global1,global1
3683	sub	global1,_PIC_DES_SPtrans-.des_and,out2
3684
3685	LDPTR	[%fp+BIAS+ARG0+7*ARGSZ], local3          ! enc
3686	LDPTR	[%fp+BIAS+ARG0+6*ARGSZ], local4          ! ivec
3687	cmp	local3, 0                 ! enc
3688
3689#ifdef __sparc_v9__
3690	be,pn	%icc, .ede3.dec
3691#else
3692	be	.ede3.dec
3693#endif
3694	STPTR	in4,  [%sp+BIAS+ARG0+4*ARGSZ]
3695
3696	STPTR	in5,  [%sp+BIAS+ARG0+5*ARGSZ]
3697
3698
3699
3700! load_little_endian
3701! local4 in5 out5 local3 .LLE6
3702
3703	! first in memory to rightmost in register
3704
3705#ifdef __sparc_v9__
3706	andcc	local4, 3, global0
3707	bne,pn	%icc, .LLE6
3708	nop
3709
3710	lda	[local4] 0x88, in5
3711	add	local4, 4, local3
3712
3713	ba,pt	%icc, .LLE6a
3714	lda	[local3] 0x88, out5
3715#endif
3716
3717.LLE6:
3718	ldub	[local4+3], in5
3719
3720	ldub	[local4+2], local3
3721	sll	in5, 8, in5
3722	or	in5, local3, in5
3723
3724	ldub	[local4+1], local3
3725	sll	in5, 8, in5
3726	or	in5, local3, in5
3727
3728	ldub	[local4+0], local3
3729	sll	in5, 8, in5
3730	or	in5, local3, in5
3731
3732
3733	ldub	[local4+3+4], out5
3734
3735	ldub	[local4+2+4], local3
3736	sll	out5, 8, out5
3737	or	out5, local3, out5
3738
3739	ldub	[local4+1+4], local3
3740	sll	out5, 8, out5
3741	or	out5, local3, out5
3742
3743	ldub	[local4+0+4], local3
3744	sll	out5, 8, out5
3745	or	out5, local3, out5
3746.LLE6a:
3747
3748  ! ivec
3749
3750	addcc	in2, -8, in2              ! bytes missing after next block
3751
3752#ifdef __sparc_v9__
3753	bl,pn	%icc,  .ede3.enc.seven.or.less
3754#else
3755	bl	.ede3.enc.seven.or.less
3756#endif
3757	STPTR	in3,  [%sp+BIAS+ARG0+3*ARGSZ]
3758
3759.ede3.enc.next.block:
3760
3761
3762
3763! load_little_endian
3764! in0 out4 global4 local3 .LLE7
3765
3766	! first in memory to rightmost in register
3767
3768#ifdef __sparc_v9__
3769	andcc	in0, 3, global0
3770	bne,pn	%icc, .LLE7
3771	nop
3772
3773	lda	[in0] 0x88, out4
3774	add	in0, 4, local3
3775
3776	ba,pt	%icc, .LLE7a
3777	lda	[local3] 0x88, global4
3778#endif
3779
3780.LLE7:
3781	ldub	[in0+3], out4
3782
3783	ldub	[in0+2], local3
3784	sll	out4, 8, out4
3785	or	out4, local3, out4
3786
3787	ldub	[in0+1], local3
3788	sll	out4, 8, out4
3789	or	out4, local3, out4
3790
3791	ldub	[in0+0], local3
3792	sll	out4, 8, out4
3793	or	out4, local3, out4
3794
3795
3796	ldub	[in0+3+4], global4
3797
3798	ldub	[in0+2+4], local3
3799	sll	global4, 8, global4
3800	or	global4, local3, global4
3801
3802	ldub	[in0+1+4], local3
3803	sll	global4, 8, global4
3804	or	global4, local3, global4
3805
3806	ldub	[in0+0+4], local3
3807	sll	global4, 8, global4
3808	or	global4, local3, global4
3809.LLE7a:
3810
3811
3812
3813.ede3.enc.next.block_1:
3814
3815	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , in4
3816	xor	in5, out4, in5            ! iv xor
3817	xor	out5, global4, out5       ! iv xor
3818
3819	LDPTR	 [%sp+BIAS+ARG0+3*ARGSZ] , in3
3820	add	in4, 120, in4             ! for decryption we use last subkey first
3821	nop
3822
3823
3824
3825! ip_macro
3826! in5 out5 out5 in5 in3
3827
3828	ld	[out2+256], local1
3829	srl	out5, 4, local4
3830
3831	xor	local4, in5, local4
3832	nop
3833
3834	ld	[out2+260], local2
3835	and	local4, local1, local4
3836
3837
3838
3839	ld	[out2+280], out4          ! loop counter
3840	sll	local4, 4, local1
3841	xor	in5, local4, in5
3842
3843	ld	[out2+264], local3
3844	srl	in5, 16, local4
3845	xor	out5, local1, out5
3846
3847
3848	xor	local4, out5, local4
3849	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
3850
3851
3852	and	local4, local2, local4
3853	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
3854
3855	sll	local4, 16, local1
3856	xor	out5, local4, out5
3857
3858	srl	out5, 2, local4
3859	xor	in5, local1, in5
3860
3861	sethi	%hi(16711680), local5
3862	xor	local4, in5, local4
3863
3864	and	local4, local3, local4
3865	or	local5, 255, local5
3866
3867	sll	local4, 2, local2
3868	xor	in5, local4, in5
3869
3870	srl	in5, 8, local4
3871	xor	out5, local2, out5
3872
3873	xor	local4, out5, local4
3874	add	global1, 768, global4
3875
3876	and	local4, local5, local4
3877	add	global1, 1024, global5
3878
3879	ld	[out2+272], local7
3880	sll	local4, 8, local1
3881	xor	out5, local4, out5
3882
3883	srl	out5, 1, local4
3884	xor	in5, local1, in5
3885
3886	ld	[in3], out0                ! key 7531
3887	xor	local4, in5, local4
3888	add	global1, 256, global2
3889
3890	ld	[in3+4], out1              ! key 8642
3891	and	local4, local7, local4
3892	add	global1, 512, global3
3893
3894	sll	local4, 1, local1
3895	xor	in5, local4, in5
3896
3897	sll	in5, 3, local3
3898	xor	out5, local1, out5
3899
3900	sll	out5, 3, local2
3901	add	global1, 1280, local6     ! address sbox 8
3902
3903	srl	in5, 29, local4
3904	add	global1, 1792, out3       ! address sbox 8
3905
3906	srl	out5, 29, local1
3907	or	local4, local3, out5
3908
3909	or	local2, local1, in5
3910
3911
3912
3913
3914
3915
3916.ede3.enc.next.block_2:
3917
3918	call .des_enc                     ! ks1 in3
3919	nop
3920
3921	call .des_dec                     ! ks2 in4
3922	LDPTR	 [%sp+BIAS+ARG0+5*ARGSZ] , in3
3923
3924	call .des_enc                     ! ks3 in3  compares in2 to 8
3925	nop
3926
3927#ifdef __sparc_v9__
3928	bl,pn	%icc, .ede3.enc.next.block_fp
3929#else
3930	bl	.ede3.enc.next.block_fp
3931#endif
3932	add	in0, 8, in0
3933
3934	! If 8 or more bytes are to be encrypted after this block,
3935	! we combine final permutation for this block with initial
3936	! permutation for next block. Load next block:
3937
3938
3939
3940! load_little_endian
3941! in0 global3 global4 local5 .LLE11
3942
3943	! first in memory to rightmost in register
3944
3945#ifdef __sparc_v9__
3946	andcc	in0, 3, global0
3947	bne,pn	%icc, .LLE11
3948	nop
3949
3950	lda	[in0] 0x88, global3
3951	add	in0, 4, local5
3952
3953	ba,pt	%icc, .LLE11a
3954	lda	[local5] 0x88, global4
3955#endif
3956
3957.LLE11:
3958	ldub	[in0+3], global3
3959
3960	ldub	[in0+2], local5
3961	sll	global3, 8, global3
3962	or	global3, local5, global3
3963
3964	ldub	[in0+1], local5
3965	sll	global3, 8, global3
3966	or	global3, local5, global3
3967
3968	ldub	[in0+0], local5
3969	sll	global3, 8, global3
3970	or	global3, local5, global3
3971
3972
3973	ldub	[in0+3+4], global4
3974
3975	ldub	[in0+2+4], local5
3976	sll	global4, 8, global4
3977	or	global4, local5, global4
3978
3979	ldub	[in0+1+4], local5
3980	sll	global4, 8, global4
3981	or	global4, local5, global4
3982
3983	ldub	[in0+0+4], local5
3984	sll	global4, 8, global4
3985	or	global4, local5, global4
3986.LLE11a:
3987
3988
3989
3990	!  parameter 1   original left
3991	!  parameter 2   original right
3992	!  parameter 3   left ip
3993	!  parameter 4   right ip
3994	!  parameter 5   1: load ks1/ks2 to in3/in4, add 120 to in4
3995	!                2: mov in4 to in3
3996	!
3997	! also adds -8 to length in2 and loads loop counter to out4
3998
3999
4000
4001! fp_ip_macro
4002! out0 out1 global3 global4 1
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012	! out0 in local3, local4
4013
4014	ld	[out2+256], local1
4015	sll	out5, 29, out4
4016	or	local3, local4, out0
4017
4018	srl	out5, 3, out1
4019
4020
4021	ld	[out2+272], local5
4022	srl	global4, 4, local0
4023	or	out1, out4, out1
4024
4025	srl	out1, 1, out4
4026	xor	out4, out0, out4
4027
4028	and	out4, local5, out4
4029	xor	local0, global3, local0
4030
4031	sll	out4, 1, local3
4032	xor	out0, out4, out0
4033
4034	and	local0, local1, local0
4035	add	in2, -8, in2
4036
4037	sll	local0, 4, local7
4038	xor	global3, local0, global3
4039
4040	ld	[out2+268], local4
4041	srl	out0, 8, out4
4042	xor	out1, local3, out1
4043	ld	[out2+260], local2
4044	srl	global3, 16, local0
4045	xor	global4, local7, global4
4046	xor	out4, out1, out4
4047	xor	local0, global4, local0
4048	and	out4, local4, out4
4049	and	local0, local2, local0
4050	sll	out4, 8, local3
4051	xor	out1, out4, out1
4052	sll	local0, 16, local7
4053	xor	global4, local0, global4
4054
4055	srl	out1, 2, out4
4056	xor	out0, local3, out0
4057
4058	ld	[out2+264], local3         ! ip3
4059	srl	global4, 2, local0
4060	xor	global3, local7, global3
4061	xor	out4, out0, out4
4062	xor	local0, global3, local0
4063	and	out4, local3, out4
4064	and	local0, local3, local0
4065	sll	out4, 2, local3
4066	xor	out0, out4, out0
4067	sll	local0, 2, local7
4068	xor	global3, local0, global3
4069
4070	srl	out0, 16, out4
4071	xor	out1, local3, out1
4072	srl	global3, 8, local0
4073	xor	global4, local7, global4
4074	xor	out4, out1, out4
4075	xor	local0, global4, local0
4076	and	out4, local2, out4
4077	and	local0, local4, local0
4078	sll	out4, 16, local3
4079	xor	out1, out4, local4
4080	sll	local0, 8, local7
4081	xor	global4, local0, global4
4082
4083	srl	global4, 1, local0
4084	xor	global3, local7, global3
4085
4086	srl	local4, 4, out4
4087	xor	local0, global3, local0
4088
4089	xor	out0, local3, out0
4090	and	local0, local5, local0
4091
4092	sll	local0, 1, local7
4093	xor	out4, out0, out4
4094
4095	xor	global3, local0, global3
4096	xor	global4, local7, global4
4097
4098	sll	global3, 3, local5
4099	and	out4, local1, out4
4100
4101	sll	out4, 4, local3
4102	xor	out0, out4, out0
4103
4104	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , in4
4105	sll	global4, 3, local2
4106	xor	local4, local3, out1
4107
4108	! reload since used as temporar:
4109
4110	ld	[out2+280], out4          ! loop counter
4111
4112	srl	global3, 29, local0
4113	add in4, 120, in4
4114
4115	LDPTR	 [%sp+BIAS+ARG0+3*ARGSZ] , in3
4116	srl	global4, 29, local7
4117
4118	or	local0, local5, global4
4119	or	local2, local7, global3
4120
4121
4122
4123
4124
4125! store_little_endian
4126! in1 out0 out1 local3 .SLE9
4127
4128	! rightmost in register to first in memory
4129
4130#ifdef __sparc_v9__
4131	andcc	in1, 3, global0
4132	bne,pn	%icc, .SLE9
4133	nop
4134
4135	sta	out0, [in1] 0x88
4136	add	in1, 4, local3
4137
4138	ba,pt	%icc, .SLE9a
4139	sta	out1, [local3] 0x88
4140#endif
4141
4142.SLE9:
4143	and	out0, 255, local3
4144	stub	local3, [in1+0]
4145
4146	srl	out0, 8, local3
4147	and	local3, 255, local3
4148	stub	local3, [in1+1]
4149
4150	srl	out0, 16, local3
4151	and	local3, 255, local3
4152	stub	local3, [in1+2]
4153
4154	srl	out0, 24, local3
4155	stub	local3, [in1+3]
4156
4157
4158	and	out1, 255, local3
4159	stub	local3, [in1+0+4]
4160
4161	srl	out1, 8, local3
4162	and	local3, 255, local3
4163	stub	local3, [in1+1+4]
4164
4165	srl	out1, 16, local3
4166	and	local3, 255, local3
4167	stub	local3, [in1+2+4]
4168
4169	srl	out1, 24, local3
4170	stub	local3, [in1+3+4]
4171
4172.SLE9a:
4173
4174  ! block
4175
4176	mov 	in5, local1
4177	xor	global3, out5, in5        ! iv xor next block
4178
4179	ld	[in3], out0               ! key 7531
4180	add	global1, 512, global3     ! address sbox 3
4181	xor	global4, local1, out5     ! iv xor next block
4182
4183	ld	[in3+4], out1             ! key 8642
4184	add	global1, 768, global4     ! address sbox 4
4185	ba	.ede3.enc.next.block_2
4186	add	in1, 8, in1
4187
4188.ede3.enc.next.block_fp:
4189
4190
4191
4192! fp_macro
4193! in5 out5
4194
4195	! initially undo the rotate 3 left done after initial permutation
4196	! original left is received shifted 3 right and 29 left in local3/4
4197
4198	sll	out5, 29, local1
4199	or	local3, local4, in5
4200
4201	srl	out5, 3, out5
4202	sethi	%hi(0x55555555), local2
4203
4204	or	out5, local1, out5
4205	or	local2, %lo(0x55555555), local2
4206
4207	srl	out5, 1, local3
4208	sethi	%hi(0x00ff00ff), local1
4209	xor	local3, in5, local3
4210	or	local1, %lo(0x00ff00ff), local1
4211	and	local3, local2, local3
4212	sethi	%hi(0x33333333), local4
4213	sll	local3, 1, local2
4214
4215	xor	in5, local3, in5
4216
4217	srl	in5, 8, local3
4218	xor	out5, local2, out5
4219	xor	local3, out5, local3
4220	or	local4, %lo(0x33333333), local4
4221	and	local3, local1, local3
4222	sethi	%hi(0x0000ffff), local1
4223	sll	local3, 8, local2
4224
4225	xor	out5, local3, out5
4226
4227	srl	out5, 2, local3
4228	xor	in5, local2, in5
4229	xor	local3, in5, local3
4230	or	local1, %lo(0x0000ffff), local1
4231	and	local3, local4, local3
4232	sethi	%hi(0x0f0f0f0f), local4
4233	sll	local3, 2, local2
4234
4235
4236	xor	in5, local3, in5
4237
4238
4239	srl	in5, 16, local3
4240	xor	out5, local2, out5
4241	xor	local3, out5, local3
4242	or	local4, %lo(0x0f0f0f0f), local4
4243	and	local3, local1, local3
4244	sll	local3, 16, local2
4245
4246	xor	out5, local3, local1
4247
4248	srl	local1, 4, local3
4249	xor	in5, local2, in5
4250	xor	local3, in5, local3
4251	and	local3, local4, local3
4252	sll	local3, 4, local2
4253
4254	xor	in5, local3, in5
4255
4256	! optional store:
4257
4258
4259
4260	xor	local1, local2, out5
4261
4262
4263
4264
4265
4266
4267
4268! store_little_endian
4269! in1 in5 out5 local3 .SLE5
4270
4271	! rightmost in register to first in memory
4272
4273#ifdef __sparc_v9__
4274	andcc	in1, 3, global0
4275	bne,pn	%icc, .SLE5
4276	nop
4277
4278	sta	in5, [in1] 0x88
4279	add	in1, 4, local3
4280
4281	ba,pt	%icc, .SLE5a
4282	sta	out5, [local3] 0x88
4283#endif
4284
4285.SLE5:
4286	and	in5, 255, local3
4287	stub	local3, [in1+0]
4288
4289	srl	in5, 8, local3
4290	and	local3, 255, local3
4291	stub	local3, [in1+1]
4292
4293	srl	in5, 16, local3
4294	and	local3, 255, local3
4295	stub	local3, [in1+2]
4296
4297	srl	in5, 24, local3
4298	stub	local3, [in1+3]
4299
4300
4301	and	out5, 255, local3
4302	stub	local3, [in1+0+4]
4303
4304	srl	out5, 8, local3
4305	and	local3, 255, local3
4306	stub	local3, [in1+1+4]
4307
4308	srl	out5, 16, local3
4309	and	local3, 255, local3
4310	stub	local3, [in1+2+4]
4311
4312	srl	out5, 24, local3
4313	stub	local3, [in1+3+4]
4314
4315.SLE5a:
4316
4317  ! block
4318
4319	addcc   in2, -8, in2              ! bytes missing when next block done
4320
4321#ifdef __sparc_v9__
4322	bpos,pt	%icc, .ede3.enc.next.block
4323#else
4324	bpos	.ede3.enc.next.block
4325#endif
4326	add	in1, 8, in1
4327
4328.ede3.enc.seven.or.less:
4329
4330	cmp	in2, -8
4331
4332#ifdef __sparc_v9__
4333	ble,pt	%icc, .ede3.enc.finish
4334#else
4335	ble	.ede3.enc.finish
4336#endif
4337	nop
4338
4339	add	in2, 8, local1            ! bytes to load
4340
4341	! addr, length, dest left, dest right, temp, local3, label, ret label
4342
4343
4344! load_n_bytes
4345! in0 local1 local2 local3 .LNB2 .ede3.enc.next.block_1 .LNB2 .ede3.enc.next.block_1
4346
4347.LNB2.0:	call	.+8
4348	sll	local1, 2, local3
4349
4350	add	%o7,.LNB2.jmp.table-.LNB2.0,local2
4351
4352	add	local2, local3, local2
4353	mov	0, out4
4354
4355	ld	[local2], local2
4356
4357	jmp	%o7+local2
4358	mov	0, global4
4359
4360.LNB2.7:
4361	ldub	[in0+6], local2
4362	sll	local2, 16, local2
4363	or	global4, local2, global4
4364.LNB2.6:
4365	ldub	[in0+5], local2
4366	sll	local2, 8, local2
4367	or	global4, local2, global4
4368.LNB2.5:
4369	ldub	[in0+4], local2
4370	or	global4, local2, global4
4371.LNB2.4:
4372	ldub	[in0+3], local2
4373	sll	local2, 24, local2
4374	or	out4, local2, out4
4375.LNB2.3:
4376	ldub	[in0+2], local2
4377	sll	local2, 16, local2
4378	or	out4, local2, out4
4379.LNB2.2:
4380	ldub	[in0+1], local2
4381	sll	local2, 8, local2
4382	or	out4, local2, out4
4383.LNB2.1:
4384	ldub	[in0+0], local2
4385	ba	.ede3.enc.next.block_1
4386	or	out4, local2, out4
4387
4388	.align 4
4389
4390.LNB2.jmp.table:
4391	.word	0
4392	.word	.LNB2.1-.LNB2.0
4393	.word	.LNB2.2-.LNB2.0
4394	.word	.LNB2.3-.LNB2.0
4395	.word	.LNB2.4-.LNB2.0
4396	.word	.LNB2.5-.LNB2.0
4397	.word	.LNB2.6-.LNB2.0
4398	.word	.LNB2.7-.LNB2.0
4399
4400
4401.ede3.enc.finish:
4402
4403	LDPTR	[%fp+BIAS+ARG0+6*ARGSZ], local4          ! ivec
4404
4405
4406! store_little_endian
4407! local4 in5 out5 local5 .SLE6
4408
4409	! rightmost in register to first in memory
4410
4411#ifdef __sparc_v9__
4412	andcc	local4, 3, global0
4413	bne,pn	%icc, .SLE6
4414	nop
4415
4416	sta	in5, [local4] 0x88
4417	add	local4, 4, local5
4418
4419	ba,pt	%icc, .SLE6a
4420	sta	out5, [local5] 0x88
4421#endif
4422
4423.SLE6:
4424	and	in5, 255, local5
4425	stub	local5, [local4+0]
4426
4427	srl	in5, 8, local5
4428	and	local5, 255, local5
4429	stub	local5, [local4+1]
4430
4431	srl	in5, 16, local5
4432	and	local5, 255, local5
4433	stub	local5, [local4+2]
4434
4435	srl	in5, 24, local5
4436	stub	local5, [local4+3]
4437
4438
4439	and	out5, 255, local5
4440	stub	local5, [local4+0+4]
4441
4442	srl	out5, 8, local5
4443	and	local5, 255, local5
4444	stub	local5, [local4+1+4]
4445
4446	srl	out5, 16, local5
4447	and	local5, 255, local5
4448	stub	local5, [local4+2+4]
4449
4450	srl	out5, 24, local5
4451	stub	local5, [local4+3+4]
4452
4453.SLE6a:
4454
4455  ! ivec
4456
4457	ret
4458	restore
4459
4460.ede3.dec:
4461
4462	STPTR	in0,  [%sp+BIAS+ARG0+0*ARGSZ]
4463	add	in5, 120, in5
4464
4465	STPTR	in1,  [%sp+BIAS+ARG0+1*ARGSZ]
4466	mov	in0, local5
4467	add	in3, 120, in3
4468
4469	STPTR	in3,  [%sp+BIAS+ARG0+3*ARGSZ]
4470	cmp	in2, 0
4471
4472#ifdef __sparc_v9__
4473	ble	%icc, .ede3.dec.finish
4474#else
4475	ble	.ede3.dec.finish
4476#endif
4477	STPTR	in5,  [%sp+BIAS+ARG0+5*ARGSZ]
4478
4479	LDPTR	[%fp+BIAS+ARG0+6*ARGSZ], local7          ! iv
4480
4481
4482! load_little_endian
4483! local7 in0 in1 local3 .LLE8
4484
4485	! first in memory to rightmost in register
4486
4487#ifdef __sparc_v9__
4488	andcc	local7, 3, global0
4489	bne,pn	%icc, .LLE8
4490	nop
4491
4492	lda	[local7] 0x88, in0
4493	add	local7, 4, local3
4494
4495	ba,pt	%icc, .LLE8a
4496	lda	[local3] 0x88, in1
4497#endif
4498
4499.LLE8:
4500	ldub	[local7+3], in0
4501
4502	ldub	[local7+2], local3
4503	sll	in0, 8, in0
4504	or	in0, local3, in0
4505
4506	ldub	[local7+1], local3
4507	sll	in0, 8, in0
4508	or	in0, local3, in0
4509
4510	ldub	[local7+0], local3
4511	sll	in0, 8, in0
4512	or	in0, local3, in0
4513
4514
4515	ldub	[local7+3+4], in1
4516
4517	ldub	[local7+2+4], local3
4518	sll	in1, 8, in1
4519	or	in1, local3, in1
4520
4521	ldub	[local7+1+4], local3
4522	sll	in1, 8, in1
4523	or	in1, local3, in1
4524
4525	ldub	[local7+0+4], local3
4526	sll	in1, 8, in1
4527	or	in1, local3, in1
4528.LLE8a:
4529
4530
4531
4532.ede3.dec.next.block:
4533
4534
4535
4536! load_little_endian
4537! local5 in5 out5 local3 .LLE9
4538
4539	! first in memory to rightmost in register
4540
4541#ifdef __sparc_v9__
4542	andcc	local5, 3, global0
4543	bne,pn	%icc, .LLE9
4544	nop
4545
4546	lda	[local5] 0x88, in5
4547	add	local5, 4, local3
4548
4549	ba,pt	%icc, .LLE9a
4550	lda	[local3] 0x88, out5
4551#endif
4552
4553.LLE9:
4554	ldub	[local5+3], in5
4555
4556	ldub	[local5+2], local3
4557	sll	in5, 8, in5
4558	or	in5, local3, in5
4559
4560	ldub	[local5+1], local3
4561	sll	in5, 8, in5
4562	or	in5, local3, in5
4563
4564	ldub	[local5+0], local3
4565	sll	in5, 8, in5
4566	or	in5, local3, in5
4567
4568
4569	ldub	[local5+3+4], out5
4570
4571	ldub	[local5+2+4], local3
4572	sll	out5, 8, out5
4573	or	out5, local3, out5
4574
4575	ldub	[local5+1+4], local3
4576	sll	out5, 8, out5
4577	or	out5, local3, out5
4578
4579	ldub	[local5+0+4], local3
4580	sll	out5, 8, out5
4581	or	out5, local3, out5
4582.LLE9a:
4583
4584
4585
4586	! parameter 6  1/2 for include encryption/decryption
4587	! parameter 7  1 for mov in1 to in3
4588	! parameter 8  1 for mov in3 to in4
4589	! parameter 9  1 for load ks3 and ks2 to in4 and in3
4590
4591
4592
4593! ip_macro
4594! in5 out5 in5 out5 in4 2 0 0 1
4595
4596	ld	[out2+256], local1
4597	srl	out5, 4, local4
4598
4599	xor	local4, in5, local4
4600	nop
4601
4602	ld	[out2+260], local2
4603	and	local4, local1, local4
4604
4605
4606
4607	ld	[out2+280], out4          ! loop counter
4608	sll	local4, 4, local1
4609	xor	in5, local4, in5
4610
4611	ld	[out2+264], local3
4612	srl	in5, 16, local4
4613	xor	out5, local1, out5
4614
4615	LDPTR	 [%sp+BIAS+ARG0+5*ARGSZ] , in4
4616	xor	local4, out5, local4
4617	nop	!sethi	%hi(DES_SPtrans), global1 ! sbox addr
4618
4619	LDPTR	 [%sp+BIAS+ARG0+4*ARGSZ] , in3
4620	and	local4, local2, local4
4621	nop	!or	global1, %lo(DES_SPtrans), global1   ! sbox addr
4622
4623	sll	local4, 16, local1
4624	xor	out5, local4, out5
4625
4626	srl	out5, 2, local4
4627	xor	in5, local1, in5
4628
4629	sethi	%hi(16711680), local5
4630	xor	local4, in5, local4
4631
4632	and	local4, local3, local4
4633	or	local5, 255, local5
4634
4635	sll	local4, 2, local2
4636	xor	in5, local4, in5
4637
4638	srl	in5, 8, local4
4639	xor	out5, local2, out5
4640
4641	xor	local4, out5, local4
4642	add	global1, 768, global4
4643
4644	and	local4, local5, local4
4645	add	global1, 1024, global5
4646
4647	ld	[out2+272], local7
4648	sll	local4, 8, local1
4649	xor	out5, local4, out5
4650
4651	srl	out5, 1, local4
4652	xor	in5, local1, in5
4653
4654	ld	[in4], out0                ! key 7531
4655	xor	local4, in5, local4
4656	add	global1, 256, global2
4657
4658	ld	[in4+4], out1              ! key 8642
4659	and	local4, local7, local4
4660	add	global1, 512, global3
4661
4662	sll	local4, 1, local1
4663	xor	in5, local4, in5
4664
4665	sll	in5, 3, local3
4666	xor	out5, local1, out5
4667
4668	sll	out5, 3, local2
4669	add	global1, 1280, local6     ! address sbox 8
4670
4671	srl	in5, 29, local4
4672	add	global1, 1792, out3       ! address sbox 8
4673
4674	srl	out5, 29, local1
4675	or	local4, local3, in5
4676
4677	or	local2, local1, out5
4678
4679
4680
4681
4682
4683		ld	[out2+284], local5     ! 0x0000FC00 used in the rounds
4684		or	local2, local1, out5
4685		xor	in5, out0, local1
4686
4687		call .des_dec.1
4688		and	local1, 252, local1
4689
4690
4691 ! inc .des_dec ks3 in4
4692
4693	call .des_enc                     ! ks2 in3
4694	LDPTR	 [%sp+BIAS+ARG0+3*ARGSZ] , in4
4695
4696	call .des_dec                     ! ks1 in4
4697	nop
4698
4699
4700
4701! fp_macro
4702! out5 in5 0 1
4703
4704	! initially undo the rotate 3 left done after initial permutation
4705	! original left is received shifted 3 right and 29 left in local3/4
4706
4707	sll	in5, 29, local1
4708	or	local3, local4, out5
4709
4710	srl	in5, 3, in5
4711	sethi	%hi(0x55555555), local2
4712
4713	or	in5, local1, in5
4714	or	local2, %lo(0x55555555), local2
4715
4716	srl	in5, 1, local3
4717	sethi	%hi(0x00ff00ff), local1
4718	xor	local3, out5, local3
4719	or	local1, %lo(0x00ff00ff), local1
4720	and	local3, local2, local3
4721	sethi	%hi(0x33333333), local4
4722	sll	local3, 1, local2
4723
4724	xor	out5, local3, out5
4725
4726	srl	out5, 8, local3
4727	xor	in5, local2, in5
4728	xor	local3, in5, local3
4729	or	local4, %lo(0x33333333), local4
4730	and	local3, local1, local3
4731	sethi	%hi(0x0000ffff), local1
4732	sll	local3, 8, local2
4733
4734	xor	in5, local3, in5
4735
4736	srl	in5, 2, local3
4737	xor	out5, local2, out5
4738	xor	local3, out5, local3
4739	or	local1, %lo(0x0000ffff), local1
4740	and	local3, local4, local3
4741	sethi	%hi(0x0f0f0f0f), local4
4742	sll	local3, 2, local2
4743
4744	LDPTR  [%sp+BIAS+ARG0+0*ARGSZ] , local5
4745	xor	out5, local3, out5
4746
4747	LDPTR  [%sp+BIAS+ARG0+1*ARGSZ] , local7
4748	srl	out5, 16, local3
4749	xor	in5, local2, in5
4750	xor	local3, in5, local3
4751	or	local4, %lo(0x0f0f0f0f), local4
4752	and	local3, local1, local3
4753	sll	local3, 16, local2
4754
4755	xor	in5, local3, local1
4756
4757	srl	local1, 4, local3
4758	xor	out5, local2, out5
4759	xor	local3, out5, local3
4760	and	local3, local4, local3
4761	sll	local3, 4, local2
4762
4763	xor	out5, local3, out5
4764
4765	! optional store:
4766
4767
4768
4769	xor	local1, local2, in5
4770
4771
4772
4773   ! 1 for input and output address local5/7
4774
4775	! in2 is bytes left to be stored
4776	! in2 is compared to 8 in the rounds
4777
4778	xor	out5, in0, out4
4779#ifdef __sparc_v9__
4780	bl,pn	%icc, .ede3.dec.seven.or.less
4781#else
4782	bl	.ede3.dec.seven.or.less
4783#endif
4784	xor	in5, in1, global4
4785
4786
4787
4788! load_little_endian_inc
4789! local5 in0 in1 local3 .LLE10
4790
4791	! first in memory to rightmost in register
4792
4793#ifdef __sparc_v9__
4794	andcc	local5, 3, global0
4795	bne,pn	%icc, .LLE10
4796	nop
4797
4798	lda	[local5] 0x88, in0
4799	add	local5, 4, local5
4800
4801	lda	[local5] 0x88, in1
4802	ba,pt	%icc, .LLE10a
4803	add	local5, 4, local5
4804#endif
4805
4806.LLE10:
4807	ldub	[local5+3], in0
4808
4809	ldub	[local5+2], local3
4810	sll	in0, 8, in0
4811	or	in0, local3, in0
4812
4813	ldub	[local5+1], local3
4814	sll	in0, 8, in0
4815	or	in0, local3, in0
4816
4817	ldub	[local5+0], local3
4818	sll	in0, 8, in0
4819	or	in0, local3, in0
4820
4821	ldub	[local5+3+4], in1
4822	add	local5, 8, local5
4823
4824	ldub	[local5+2+4-8], local3
4825	sll	in1, 8, in1
4826	or	in1, local3, in1
4827
4828	ldub	[local5+1+4-8], local3
4829	sll	in1, 8, in1
4830	or	in1, local3, in1
4831
4832	ldub	[local5+0+4-8], local3
4833	sll	in1, 8, in1
4834	or	in1, local3, in1
4835.LLE10a:
4836
4837   ! iv next block
4838
4839
4840
4841! store_little_endian
4842! local7 out4 global4 local3 .SLE7
4843
4844	! rightmost in register to first in memory
4845
4846#ifdef __sparc_v9__
4847	andcc	local7, 3, global0
4848	bne,pn	%icc, .SLE7
4849	nop
4850
4851	sta	out4, [local7] 0x88
4852	add	local7, 4, local3
4853
4854	ba,pt	%icc, .SLE7a
4855	sta	global4, [local3] 0x88
4856#endif
4857
4858.SLE7:
4859	and	out4, 255, local3
4860	stub	local3, [local7+0]
4861
4862	srl	out4, 8, local3
4863	and	local3, 255, local3
4864	stub	local3, [local7+1]
4865
4866	srl	out4, 16, local3
4867	and	local3, 255, local3
4868	stub	local3, [local7+2]
4869
4870	srl	out4, 24, local3
4871	stub	local3, [local7+3]
4872
4873
4874	and	global4, 255, local3
4875	stub	local3, [local7+0+4]
4876
4877	srl	global4, 8, local3
4878	and	local3, 255, local3
4879	stub	local3, [local7+1+4]
4880
4881	srl	global4, 16, local3
4882	and	local3, 255, local3
4883	stub	local3, [local7+2+4]
4884
4885	srl	global4, 24, local3
4886	stub	local3, [local7+3+4]
4887
4888.SLE7a:
4889
4890  ! block
4891
4892	STPTR	local5,  [%sp+BIAS+ARG0+0*ARGSZ]
4893	addcc   in2, -8, in2
4894	add	local7, 8, local7
4895
4896#ifdef __sparc_v9__
4897	bg,pt	%icc, .ede3.dec.next.block
4898#else
4899	bg	.ede3.dec.next.block
4900#endif
4901	STPTR	local7,  [%sp+BIAS+ARG0+1*ARGSZ]
4902
4903.ede3.dec.store.iv:
4904
4905	LDPTR	[%fp+BIAS+ARG0+6*ARGSZ], local4          ! ivec
4906
4907
4908! store_little_endian
4909! local4 in0 in1 local5 .SLE8
4910
4911	! rightmost in register to first in memory
4912
4913#ifdef __sparc_v9__
4914	andcc	local4, 3, global0
4915	bne,pn	%icc, .SLE8
4916	nop
4917
4918	sta	in0, [local4] 0x88
4919	add	local4, 4, local5
4920
4921	ba,pt	%icc, .SLE8a
4922	sta	in1, [local5] 0x88
4923#endif
4924
4925.SLE8:
4926	and	in0, 255, local5
4927	stub	local5, [local4+0]
4928
4929	srl	in0, 8, local5
4930	and	local5, 255, local5
4931	stub	local5, [local4+1]
4932
4933	srl	in0, 16, local5
4934	and	local5, 255, local5
4935	stub	local5, [local4+2]
4936
4937	srl	in0, 24, local5
4938	stub	local5, [local4+3]
4939
4940
4941	and	in1, 255, local5
4942	stub	local5, [local4+0+4]
4943
4944	srl	in1, 8, local5
4945	and	local5, 255, local5
4946	stub	local5, [local4+1+4]
4947
4948	srl	in1, 16, local5
4949	and	local5, 255, local5
4950	stub	local5, [local4+2+4]
4951
4952	srl	in1, 24, local5
4953	stub	local5, [local4+3+4]
4954
4955.SLE8a:
4956
4957  ! ivec
4958
4959.ede3.dec.finish:
4960
4961	ret
4962	restore
4963
4964.ede3.dec.seven.or.less:
4965
4966
4967
4968! load_little_endian_inc
4969! local5 in0 in1 local3 .LLE14
4970
4971	! first in memory to rightmost in register
4972
4973#ifdef __sparc_v9__
4974	andcc	local5, 3, global0
4975	bne,pn	%icc, .LLE14
4976	nop
4977
4978	lda	[local5] 0x88, in0
4979	add	local5, 4, local5
4980
4981	lda	[local5] 0x88, in1
4982	ba,pt	%icc, .LLE14a
4983	add	local5, 4, local5
4984#endif
4985
4986.LLE14:
4987	ldub	[local5+3], in0
4988
4989	ldub	[local5+2], local3
4990	sll	in0, 8, in0
4991	or	in0, local3, in0
4992
4993	ldub	[local5+1], local3
4994	sll	in0, 8, in0
4995	or	in0, local3, in0
4996
4997	ldub	[local5+0], local3
4998	sll	in0, 8, in0
4999	or	in0, local3, in0
5000
5001	ldub	[local5+3+4], in1
5002	add	local5, 8, local5
5003
5004	ldub	[local5+2+4-8], local3
5005	sll	in1, 8, in1
5006	or	in1, local3, in1
5007
5008	ldub	[local5+1+4-8], local3
5009	sll	in1, 8, in1
5010	or	in1, local3, in1
5011
5012	ldub	[local5+0+4-8], local3
5013	sll	in1, 8, in1
5014	or	in1, local3, in1
5015.LLE14a:
5016
5017     ! iv
5018
5019
5020
5021! store_n_bytes
5022! local7 in2 local3 local4 .SNB2 .ede3.dec.store.iv .SNB2 .ede3.dec.store.iv
5023
5024.SNB2.0:	call	.+8
5025	sll	in2, 2, local4
5026
5027	add	%o7,.SNB2.jmp.table-.SNB2.0,local3
5028
5029	add	local3, local4, local3
5030
5031	ld	[local3], local3
5032
5033	jmp	%o7+local3
5034	nop
5035
5036.SNB2.7:
5037	srl	global4, 16, local3
5038	and	local3, 0xff, local3
5039	stub	local3, [local7+6]
5040.SNB2.6:
5041	srl	global4, 8, local3
5042	and	local3, 0xff, local3
5043	stub	local3, [local7+5]
5044.SNB2.5:
5045	and	global4, 0xff, local3
5046	stub	local3, [local7+4]
5047.SNB2.4:
5048	srl	out4, 24, local3
5049	stub	local3, [local7+3]
5050.SNB2.3:
5051	srl	out4, 16, local3
5052	and	local3, 0xff, local3
5053	stub	local3, [local7+2]
5054.SNB2.2:
5055	srl	out4, 8, local3
5056	and	local3, 0xff, local3
5057	stub	local3, [local7+1]
5058.SNB2.1:
5059	and	out4, 0xff, local3
5060
5061
5062	ba	.ede3.dec.store.iv
5063	stub	local3, [local7]
5064
5065	.align 4
5066
5067.SNB2.jmp.table:
5068
5069	.word	0
5070	.word	.SNB2.1-.SNB2.0
5071	.word	.SNB2.2-.SNB2.0
5072	.word	.SNB2.3-.SNB2.0
5073	.word	.SNB2.4-.SNB2.0
5074	.word	.SNB2.5-.SNB2.0
5075	.word	.SNB2.6-.SNB2.0
5076	.word	.SNB2.7-.SNB2.0
5077
5078
5079
5080.DES_ede3_cbc_encrypt.end:
5081	.size	 DES_ede3_cbc_encrypt,.DES_ede3_cbc_encrypt.end-DES_ede3_cbc_encrypt
5082
5083	.align	256
5084	.type	 .des_and,#object
5085	.size	 .des_and,284
5086
5087.des_and:
5088
5089! This table is used for AND 0xFC when it is known that register
5090! bits 8-31 are zero. Makes it possible to do three arithmetic
5091! operations in one cycle.
5092
5093	.byte  0, 0, 0, 0, 4, 4, 4, 4
5094	.byte  8, 8, 8, 8, 12, 12, 12, 12
5095	.byte  16, 16, 16, 16, 20, 20, 20, 20
5096	.byte  24, 24, 24, 24, 28, 28, 28, 28
5097	.byte  32, 32, 32, 32, 36, 36, 36, 36
5098	.byte  40, 40, 40, 40, 44, 44, 44, 44
5099	.byte  48, 48, 48, 48, 52, 52, 52, 52
5100	.byte  56, 56, 56, 56, 60, 60, 60, 60
5101	.byte  64, 64, 64, 64, 68, 68, 68, 68
5102	.byte  72, 72, 72, 72, 76, 76, 76, 76
5103	.byte  80, 80, 80, 80, 84, 84, 84, 84
5104	.byte  88, 88, 88, 88, 92, 92, 92, 92
5105	.byte  96, 96, 96, 96, 100, 100, 100, 100
5106	.byte  104, 104, 104, 104, 108, 108, 108, 108
5107	.byte  112, 112, 112, 112, 116, 116, 116, 116
5108	.byte  120, 120, 120, 120, 124, 124, 124, 124
5109	.byte  128, 128, 128, 128, 132, 132, 132, 132
5110	.byte  136, 136, 136, 136, 140, 140, 140, 140
5111	.byte  144, 144, 144, 144, 148, 148, 148, 148
5112	.byte  152, 152, 152, 152, 156, 156, 156, 156
5113	.byte  160, 160, 160, 160, 164, 164, 164, 164
5114	.byte  168, 168, 168, 168, 172, 172, 172, 172
5115	.byte  176, 176, 176, 176, 180, 180, 180, 180
5116	.byte  184, 184, 184, 184, 188, 188, 188, 188
5117	.byte  192, 192, 192, 192, 196, 196, 196, 196
5118	.byte  200, 200, 200, 200, 204, 204, 204, 204
5119	.byte  208, 208, 208, 208, 212, 212, 212, 212
5120	.byte  216, 216, 216, 216, 220, 220, 220, 220
5121	.byte  224, 224, 224, 224, 228, 228, 228, 228
5122	.byte  232, 232, 232, 232, 236, 236, 236, 236
5123	.byte  240, 240, 240, 240, 244, 244, 244, 244
5124	.byte  248, 248, 248, 248, 252, 252, 252, 252
5125
5126	! 5 numbers for initil/final permutation
5127
5128	.word   0x0f0f0f0f                ! offset 256
5129	.word	0x0000ffff                ! 260
5130	.word	0x33333333                ! 264
5131	.word	0x00ff00ff                ! 268
5132	.word	0x55555555                ! 272
5133
5134	.word	0                         ! 276
5135	.word	LOOPS                     ! 280
5136	.word	0x0000FC00                ! 284
5137
5138	.global	DES_SPtrans
5139	.type	DES_SPtrans,#object
5140	.size	DES_SPtrans,2048
5141.align	64
5142DES_SPtrans:
5143_PIC_DES_SPtrans:
5144	! nibble 0
5145	.word	0x02080800, 0x00080000, 0x02000002, 0x02080802
5146	.word	0x02000000, 0x00080802, 0x00080002, 0x02000002
5147	.word	0x00080802, 0x02080800, 0x02080000, 0x00000802
5148	.word	0x02000802, 0x02000000, 0x00000000, 0x00080002
5149	.word	0x00080000, 0x00000002, 0x02000800, 0x00080800
5150	.word	0x02080802, 0x02080000, 0x00000802, 0x02000800
5151	.word	0x00000002, 0x00000800, 0x00080800, 0x02080002
5152	.word	0x00000800, 0x02000802, 0x02080002, 0x00000000
5153	.word	0x00000000, 0x02080802, 0x02000800, 0x00080002
5154	.word	0x02080800, 0x00080000, 0x00000802, 0x02000800
5155	.word	0x02080002, 0x00000800, 0x00080800, 0x02000002
5156	.word	0x00080802, 0x00000002, 0x02000002, 0x02080000
5157	.word	0x02080802, 0x00080800, 0x02080000, 0x02000802
5158	.word	0x02000000, 0x00000802, 0x00080002, 0x00000000
5159	.word	0x00080000, 0x02000000, 0x02000802, 0x02080800
5160	.word	0x00000002, 0x02080002, 0x00000800, 0x00080802
5161	! nibble 1
5162	.word	0x40108010, 0x00000000, 0x00108000, 0x40100000
5163	.word	0x40000010, 0x00008010, 0x40008000, 0x00108000
5164	.word	0x00008000, 0x40100010, 0x00000010, 0x40008000
5165	.word	0x00100010, 0x40108000, 0x40100000, 0x00000010
5166	.word	0x00100000, 0x40008010, 0x40100010, 0x00008000
5167	.word	0x00108010, 0x40000000, 0x00000000, 0x00100010
5168	.word	0x40008010, 0x00108010, 0x40108000, 0x40000010
5169	.word	0x40000000, 0x00100000, 0x00008010, 0x40108010
5170	.word	0x00100010, 0x40108000, 0x40008000, 0x00108010
5171	.word	0x40108010, 0x00100010, 0x40000010, 0x00000000
5172	.word	0x40000000, 0x00008010, 0x00100000, 0x40100010
5173	.word	0x00008000, 0x40000000, 0x00108010, 0x40008010
5174	.word	0x40108000, 0x00008000, 0x00000000, 0x40000010
5175	.word	0x00000010, 0x40108010, 0x00108000, 0x40100000
5176	.word	0x40100010, 0x00100000, 0x00008010, 0x40008000
5177	.word	0x40008010, 0x00000010, 0x40100000, 0x00108000
5178	! nibble 2
5179	.word	0x04000001, 0x04040100, 0x00000100, 0x04000101
5180	.word	0x00040001, 0x04000000, 0x04000101, 0x00040100
5181	.word	0x04000100, 0x00040000, 0x04040000, 0x00000001
5182	.word	0x04040101, 0x00000101, 0x00000001, 0x04040001
5183	.word	0x00000000, 0x00040001, 0x04040100, 0x00000100
5184	.word	0x00000101, 0x04040101, 0x00040000, 0x04000001
5185	.word	0x04040001, 0x04000100, 0x00040101, 0x04040000
5186	.word	0x00040100, 0x00000000, 0x04000000, 0x00040101
5187	.word	0x04040100, 0x00000100, 0x00000001, 0x00040000
5188	.word	0x00000101, 0x00040001, 0x04040000, 0x04000101
5189	.word	0x00000000, 0x04040100, 0x00040100, 0x04040001
5190	.word	0x00040001, 0x04000000, 0x04040101, 0x00000001
5191	.word	0x00040101, 0x04000001, 0x04000000, 0x04040101
5192	.word	0x00040000, 0x04000100, 0x04000101, 0x00040100
5193	.word	0x04000100, 0x00000000, 0x04040001, 0x00000101
5194	.word	0x04000001, 0x00040101, 0x00000100, 0x04040000
5195	! nibble 3
5196	.word	0x00401008, 0x10001000, 0x00000008, 0x10401008
5197	.word	0x00000000, 0x10400000, 0x10001008, 0x00400008
5198	.word	0x10401000, 0x10000008, 0x10000000, 0x00001008
5199	.word	0x10000008, 0x00401008, 0x00400000, 0x10000000
5200	.word	0x10400008, 0x00401000, 0x00001000, 0x00000008
5201	.word	0x00401000, 0x10001008, 0x10400000, 0x00001000
5202	.word	0x00001008, 0x00000000, 0x00400008, 0x10401000
5203	.word	0x10001000, 0x10400008, 0x10401008, 0x00400000
5204	.word	0x10400008, 0x00001008, 0x00400000, 0x10000008
5205	.word	0x00401000, 0x10001000, 0x00000008, 0x10400000
5206	.word	0x10001008, 0x00000000, 0x00001000, 0x00400008
5207	.word	0x00000000, 0x10400008, 0x10401000, 0x00001000
5208	.word	0x10000000, 0x10401008, 0x00401008, 0x00400000
5209	.word	0x10401008, 0x00000008, 0x10001000, 0x00401008
5210	.word	0x00400008, 0x00401000, 0x10400000, 0x10001008
5211	.word	0x00001008, 0x10000000, 0x10000008, 0x10401000
5212	! nibble 4
5213	.word	0x08000000, 0x00010000, 0x00000400, 0x08010420
5214	.word	0x08010020, 0x08000400, 0x00010420, 0x08010000
5215	.word	0x00010000, 0x00000020, 0x08000020, 0x00010400
5216	.word	0x08000420, 0x08010020, 0x08010400, 0x00000000
5217	.word	0x00010400, 0x08000000, 0x00010020, 0x00000420
5218	.word	0x08000400, 0x00010420, 0x00000000, 0x08000020
5219	.word	0x00000020, 0x08000420, 0x08010420, 0x00010020
5220	.word	0x08010000, 0x00000400, 0x00000420, 0x08010400
5221	.word	0x08010400, 0x08000420, 0x00010020, 0x08010000
5222	.word	0x00010000, 0x00000020, 0x08000020, 0x08000400
5223	.word	0x08000000, 0x00010400, 0x08010420, 0x00000000
5224	.word	0x00010420, 0x08000000, 0x00000400, 0x00010020
5225	.word	0x08000420, 0x00000400, 0x00000000, 0x08010420
5226	.word	0x08010020, 0x08010400, 0x00000420, 0x00010000
5227	.word	0x00010400, 0x08010020, 0x08000400, 0x00000420
5228	.word	0x00000020, 0x00010420, 0x08010000, 0x08000020
5229	! nibble 5
5230	.word	0x80000040, 0x00200040, 0x00000000, 0x80202000
5231	.word	0x00200040, 0x00002000, 0x80002040, 0x00200000
5232	.word	0x00002040, 0x80202040, 0x00202000, 0x80000000
5233	.word	0x80002000, 0x80000040, 0x80200000, 0x00202040
5234	.word	0x00200000, 0x80002040, 0x80200040, 0x00000000
5235	.word	0x00002000, 0x00000040, 0x80202000, 0x80200040
5236	.word	0x80202040, 0x80200000, 0x80000000, 0x00002040
5237	.word	0x00000040, 0x00202000, 0x00202040, 0x80002000
5238	.word	0x00002040, 0x80000000, 0x80002000, 0x00202040
5239	.word	0x80202000, 0x00200040, 0x00000000, 0x80002000
5240	.word	0x80000000, 0x00002000, 0x80200040, 0x00200000
5241	.word	0x00200040, 0x80202040, 0x00202000, 0x00000040
5242	.word	0x80202040, 0x00202000, 0x00200000, 0x80002040
5243	.word	0x80000040, 0x80200000, 0x00202040, 0x00000000
5244	.word	0x00002000, 0x80000040, 0x80002040, 0x80202000
5245	.word	0x80200000, 0x00002040, 0x00000040, 0x80200040
5246	! nibble 6
5247	.word	0x00004000, 0x00000200, 0x01000200, 0x01000004
5248	.word	0x01004204, 0x00004004, 0x00004200, 0x00000000
5249	.word	0x01000000, 0x01000204, 0x00000204, 0x01004000
5250	.word	0x00000004, 0x01004200, 0x01004000, 0x00000204
5251	.word	0x01000204, 0x00004000, 0x00004004, 0x01004204
5252	.word	0x00000000, 0x01000200, 0x01000004, 0x00004200
5253	.word	0x01004004, 0x00004204, 0x01004200, 0x00000004
5254	.word	0x00004204, 0x01004004, 0x00000200, 0x01000000
5255	.word	0x00004204, 0x01004000, 0x01004004, 0x00000204
5256	.word	0x00004000, 0x00000200, 0x01000000, 0x01004004
5257	.word	0x01000204, 0x00004204, 0x00004200, 0x00000000
5258	.word	0x00000200, 0x01000004, 0x00000004, 0x01000200
5259	.word	0x00000000, 0x01000204, 0x01000200, 0x00004200
5260	.word	0x00000204, 0x00004000, 0x01004204, 0x01000000
5261	.word	0x01004200, 0x00000004, 0x00004004, 0x01004204
5262	.word	0x01000004, 0x01004200, 0x01004000, 0x00004004
5263	! nibble 7
5264	.word	0x20800080, 0x20820000, 0x00020080, 0x00000000
5265	.word	0x20020000, 0x00800080, 0x20800000, 0x20820080
5266	.word	0x00000080, 0x20000000, 0x00820000, 0x00020080
5267	.word	0x00820080, 0x20020080, 0x20000080, 0x20800000
5268	.word	0x00020000, 0x00820080, 0x00800080, 0x20020000
5269	.word	0x20820080, 0x20000080, 0x00000000, 0x00820000
5270	.word	0x20000000, 0x00800000, 0x20020080, 0x20800080
5271	.word	0x00800000, 0x00020000, 0x20820000, 0x00000080
5272	.word	0x00800000, 0x00020000, 0x20000080, 0x20820080
5273	.word	0x00020080, 0x20000000, 0x00000000, 0x00820000
5274	.word	0x20800080, 0x20020080, 0x20020000, 0x00800080
5275	.word	0x20820000, 0x00000080, 0x00800080, 0x20020000
5276	.word	0x20820080, 0x00800000, 0x20800000, 0x20000080
5277	.word	0x00820000, 0x00020080, 0x20020080, 0x20800000
5278	.word	0x00000080, 0x20820000, 0x00820080, 0x00000000
5279	.word	0x20000000, 0x20800080, 0x00020000, 0x00820080
5280
5281