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