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