xref: /illumos-gate/usr/src/common/crypto/arcfour/sun4u/arcfour_crypt_asm.S (revision b210e77709da8e42dfe621e10ccf4be504206058)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#if defined(lint) || defined(__lint)
27
28#include "arcfour.h"
29
30/* ARGSUSED */
31void
32arcfour_crypt_aligned(ARCFour_key *key, size_t len, uchar_t *in, uchar_t *out)
33{}
34
35#else	/* lint || __lint */
36
37	.register	%g2,#scratch
38	.register	%g3,#scratch
39
40	.section	".text",#alloc,#execinstr
41	.file	"arcfour_crypt_asm.s"
42
43	.section	".text",#alloc
44	.align	32
45
46	.section	".text",#alloc,#execinstr
47	.align	32
48	.skip	32
49
50/*
51 * SUBROUTINE arcfour_crypt_aligned
52 *
53 * void arcfour_crypt_aligned(ARCFour_key *key, size_t len,
54 *			uchar_t *in, uchar_t *out);
55 *
56 * in and out should be aligned on an 8-byte boundary, but len can be anything
57 */
58	.global arcfour_crypt_aligned
59
60
61arcfour_crypt_aligned:
62	save	%sp,-144,%sp
63
64	srl	%i1, 3, %l7
65	ldub	[%i0+256], %g1
66
67	orcc	%l7, %g0, %g0
68	ldub	[%i0+257], %g2
69
70	add	%g1, 1, %o1
71	bz	%icc, .Loop2
72	add	%i0, 0, %i5
73
74	add	%o1, 1, %g1
75	and	%o1, 255, %o1
76
77	and	%g1, 255, %g1
78	ldub	[%i5 + %o1], %o3
79
80	ldub	[%i5 + %g1], %g3
81
82	add	%g2, %o3, %o2
83
84	add	%o2, %g3, %g2
85	and	%o2, 255, %o2
86
87	and	%g2, 255, %g2
88	ldub	[%i5 + %o2], %o4
89
90	stb	%o3, [%i5+%o2]
91	subcc	%o2, %g1, %g0
92
93	stb	%o4, [%i5 + %o1]
94	bz	%icc, .L1A
95	add	%o3,%o4,%o5
96.L1B:
97	and	%o5, 255, %o5
98	ldub	[%i5 + %g2], %g4
99
100	ldub	[%i5 + %o5], %o5
101	add	%g1, 1, %o1
102
103	and	%o1, 255, %o1
104	stb	%g3, [%i5 + %g2]
105	add	%g3, %g4, %g5
106
107	and	%g5, 255, %g5
108	stb	%g4, [%i5 + %g1]
109	add	%o1, 1, %g1
110
111
112	sllx	%o5, 56, %o0
113	ldub	[%i5 + %o1], %o3
114	and	%g1, 255, %g1
115
116	ldub	[%i5 + %g1], %g3
117
118	add	%g2, %o3, %o2
119	ldub	[%i5 + %g5], %g5
120
121	add	%o2, %g3, %g2
122	and	%o2, 255, %o2
123
124	sllx	%g5, 48, %g5
125	ldub	[%i5 + %o2], %o4
126	and	%g2, 255, %g2
127
128	or	%o0, %g5, %o0
129	stb	%o3, [%i5+%o2]
130	subcc	%o2, %g1, %g0
131
132	stb	%o4, [%i5 + %o1]
133	bz	%icc, .L2A
134	add	%o3,%o4,%o5
135.L2B:
136	and	%o5, 255, %o5
137	ldub	[%i5 + %g2], %g4
138
139	ldub	[%i5 + %o5], %o5
140	add	%g1, 1, %o1
141
142	and	%o1, 255, %o1
143	stb	%g3, [%i5 + %g2]
144	add	%g3, %g4, %g5
145
146	and	%g5, 255, %g5
147	stb	%g4, [%i5 + %g1]
148	add	%o1, 1, %g1
149
150
151	sllx	%o5, 40, %o5
152	ldub	[%i5 + %o1], %o3
153	and	%g1, 255, %g1
154
155	ldub	[%i5 + %g1], %g3
156	or	%o0, %o5, %o0
157
158	add	%g2, %o3, %o2
159	ldub	[%i5 + %g5], %g5
160
161	add	%o2, %g3, %g2
162	and	%o2, 255, %o2
163
164	sllx	%g5, 32, %g5
165	ldub	[%i5 + %o2], %o4
166	and	%g2, 255, %g2
167
168	or	%o0, %g5, %o0
169	stb	%o3, [%i5+%o2]
170	subcc	%o2, %g1, %g0
171
172	stb	%o4, [%i5 + %o1]
173	bz	%icc, .L3A
174	add	%o3,%o4,%o5
175.L3B:
176	and	%o5, 255, %o5
177	ldub	[%i5 + %g2], %g4
178
179	ldub	[%i5 + %o5], %o5
180	add	%g1, 1, %o1
181
182	and	%o1, 255, %o1
183	stb	%g3, [%i5 + %g2]
184	add	%g3, %g4, %g5
185
186	and	%g5, 255, %g5
187	stb	%g4, [%i5 + %g1]
188	add	%o1, 1, %g1
189
190
191	sll	%o5, 24, %o5
192	ldub	[%i5 + %o1], %o3
193	and	%g1, 255, %g1
194
195	sub	%i1, 8, %i1
196	ldub	[%i5 + %g1], %g3
197	or	%o0, %o5, %o0
198
199	srl	%i1, 3, %l7
200	ldub	[%i5 + %g5], %g5
201	add	%g2, %o3, %o2
202
203	add	%o2, %g3, %g2
204	and	%o2, 255, %o2
205
206	sll	%g5, 16, %g5
207	ldub	[%i5 + %o2], %o4
208	and	%g2, 255, %g2
209
210	or	%o0, %g5, %o0
211	stb	%o3, [%i5+%o2]
212	subcc	%o2, %g1, %g0
213
214	stb	%o4, [%i5 + %o1]
215	bz	%icc, .L4A
216	add	%o3,%o4,%o5
217.L4B:
218	and	%o5, 255, %o5
219	ldub	[%i5 + %g2], %g4
220	add	%g1, 1, %o1
221
222	orcc	%l7, %g0, %g0
223	ldub	[%i5 + %o5], %o5
224	and	%o1, 255, %o1
225
226	add	%g3, %g4, %g5
227	stb	%g4, [%i5 + %g1]
228	add	%o1, 1, %g1
229
230	stb	%g3, [%i5 + %g2]
231	bz	%icc, .EndLoop1
232	and	%g5, 255, %g5
233
234
235.Loop1:
236	sll	%o5, 8, %o5
237	ldub	[%i5 + %o1], %o3
238	and	%g1, 255, %g1
239
240	ldub	[%i5 + %g1], %g3
241	or	%o0, %o5, %o0
242
243	ldub	[%i5 + %g5], %g5
244	add	%g2, %o3, %o2
245
246	add	%o2, %g3, %g2
247	ldx	[%i2], %o7
248	and	%o2, 255, %o2
249
250	and	%g2, 255, %g2
251	ldub	[%i5 + %o2], %o4
252
253	or	%o0, %g5, %o0
254	stb	%o3, [%i5+%o2]
255	subcc	%o2, %g1, %g0
256
257	stb	%o4, [%i5 + %o1]
258	bz	%icc, .L5A
259	add	%o3,%o4,%o5
260.L5B:
261	and	%o5, 255, %o5
262	ldub	[%i5 + %g2], %g4
263
264	ldub	[%i5 + %o5], %o5
265	add	%g1, 1, %o1
266
267	and	%o1, 255, %o1
268	stb	%g3, [%i5 + %g2]
269	add	%g3, %g4, %g5
270
271	and	%g5, 255, %g5
272	stb	%g4, [%i5 + %g1]
273	add	%o1, 1, %g1
274
275
276	xor	%o0, %o7, %o7
277	ldub	[%i5 + %o1], %o3
278	and	%g1, 255, %g1
279
280	sllx	%o5, 56, %o0
281	ldub	[%i5 + %g1], %g3
282
283	add	%g2, %o3, %o2
284	ldub	[%i5 + %g5], %g5
285
286	add	%o2, %g3, %g2
287	stx	%o7, [%i3]
288	and	%o2, 255, %o2
289
290	sllx	%g5, 48, %g5
291	ldub	[%i5 + %o2], %o4
292	and	%g2, 255, %g2
293
294	or	%o0, %g5, %o0
295	stb	%o3, [%i5+%o2]
296	subcc	%o2, %g1, %g0
297
298	stb	%o4, [%i5 + %o1]
299	bz	%icc, .L6A
300	add	%o3,%o4,%o5
301.L6B:
302	and	%o5, 255, %o5
303	ldub	[%i5 + %g2], %g4
304	add	%i3, 8, %i3
305
306	add	%i2, 8, %i2
307	ldub	[%i5 + %o5], %o5
308	add	%g1, 1, %o1
309
310	and	%o1, 255, %o1
311	stb	%g3, [%i5 + %g2]
312	add	%g3, %g4, %g5
313
314	and	%g5, 255, %g5
315	stb	%g4, [%i5 + %g1]
316	add	%o1, 1, %g1
317
318
319	sllx	%o5, 40, %o5
320	ldub	[%i5 + %o1], %o3
321	and	%g1, 255, %g1
322
323	ldub	[%i5 + %g1], %g3
324	or	%o0, %o5, %o0
325
326	add	%g2, %o3, %o2
327	ldub	[%i5 + %g5], %g5
328
329	add	%o2, %g3, %g2
330	and	%o2, 255, %o2
331
332	sllx	%g5, 32, %g5
333	ldub	[%i5 + %o2], %o4
334	and	%g2, 255, %g2
335
336	or	%o0, %g5, %o0
337	stb	%o3, [%i5 + %o2]
338	subcc	%o2, %g1, %g0
339
340	stb	%o4, [%i5 + %o1]
341	bz	%icc, .L7A
342	add	%o3,%o4,%o5
343.L7B:
344	and	%o5, 255, %o5
345	ldub	[%i5 + %g2], %g4
346
347	ldub	[%i5 + %o5], %o5
348	add	%g1, 1, %o1
349
350	and	%o1, 255, %o1
351	stb	%g3, [%i5 + %g2]
352	add	%g3, %g4, %g5
353
354	and	%g5, 255, %g5
355	stb	%g4, [%i5 + %g1]
356	add	%o1, 1, %g1
357
358
359	sll	%o5, 24, %o5
360	ldub	[%i5 + %o1], %o3
361	and	%g1, 255, %g1
362
363	sub	%i1, 8, %i1
364	ldub	[%i5 + %g1], %g3
365	or	%o0, %o5, %o0
366
367	srl	%i1, 3, %l7
368	ldub	[%i5 + %g5], %g5
369	add	%g2, %o3, %o2
370
371	add	%o2, %g3, %g2
372	and	%o2, 255, %o2
373
374	sll	%g5, 16, %g5
375	ldub	[%i5 + %o2], %o4
376	and	%g2, 255, %g2
377
378	or	%o0, %g5, %o0
379	stb	%o3, [%i5 + %o2]
380	subcc	%o2, %g1, %g0
381
382	stb	%o4, [%i5 + %o1]
383	bz	%icc, .L8A
384	add	%o3,%o4,%o5
385.L8B:
386	and	%o5, 255, %o5
387	ldub	[%i5 + %g2], %g4
388	add	%g1, 1, %o1
389
390	orcc	%l7, %g0, %g0
391	ldub	[%i5 + %o5], %o5
392	and	%o1, 255, %o1
393
394	add	%g3, %g4, %g5
395	stb	%g4, [%i5 + %g1]
396	add	%o1, 1, %g1
397
398	stb	%g3, [%i5 + %g2]
399	bnz	%icc, .Loop1
400	and	%g5, 255, %g5
401
402
403.EndLoop1:
404	sll	%o5, 8, %o5
405	ldub	[%i5 + %g5], %g5
406	orcc	%i1, %g0, %g0
407
408	or	%o0, %o5, %o0
409	ldx	[%i2], %o7
410	sub	%g1, 2, %g1
411
412	and	%g1, 255, %g1
413	stb	%g1, [%i0 + 256]
414	or	%o0, %g5, %o0
415
416	xor	%o0, %o7, %o7
417	stx	%o7, [%i3]
418	add	%i2, 8, %i2
419
420	add	%i3, 8, %i3
421	bnz	%icc, .Loop2_1
422	stb	%g2, [%i0 + 257]
423
424	ret
425	restore	%g0,%g0,%g0
426
427
428.Loop2:
429	orcc	%i1, %g0, %g0
430	bnz	.Loop2_1
431	nop
432	ret
433	restore	%g0,%g0,%g0
434
435.Loop2_1:
436	and	%o1, 255, %g1
437	ldub	[%i5 + %g1], %g3
438
439	add	%g2, %g3, %g2
440
441	and	%g2, 255, %g2
442
443	ldub	[%i5 + %g2], %g4
444
445	stb	%g3, [%i5 + %g2]
446
447	add	%g3, %g4, %g5
448	stb	%g4, [%i5 + %g1]
449
450	and	%g5, 255, %g5
451	ldub	[%i2], %o0
452
453	add	%g1, 1, %o1
454	ldub	[%i5 + %g5], %g5
455	subcc	%i1, 1, %i1
456
457	add	%i2, 1, %i2
458	add	%i3, 1, %i3
459
460	xor	%o0, %g5, %o0
461	bnz	%icc, .Loop2_1
462	stb	%o0, [%i3 - 1]
463
464	stb	%g1, [%i0 + 256]
465
466	stb	%g2, [%i0 + 257]
467
468	ret
469	restore	%g0,%g0,%g0
470
471.L1A:
472	add	%o2, %o3, %g2
473	or	%o3, %g0, %g3
474	ba	.L1B
475	and	%g2, 255, %g2
476
477.L2A:
478	add	%o2, %o3, %g2
479	or	%o3, %g0, %g3
480	ba	.L2B
481	and	%g2, 255, %g2
482
483.L3A:
484	add	%o2, %o3, %g2
485	or	%o3, %g0, %g3
486	ba	.L3B
487	and	%g2, 255, %g2
488
489.L4A:
490	add	%o2, %o3, %g2
491	or	%o3, %g0, %g3
492	ba	.L4B
493	and	%g2, 255, %g2
494
495.L5A:
496	add	%o2, %o3, %g2
497	or	%o3, %g0, %g3
498	ba	.L5B
499	and	%g2, 255, %g2
500
501.L6A:
502	add	%o2, %o3, %g2
503	or	%o3, %g0, %g3
504	ba	.L6B
505	and	%g2, 255, %g2
506
507.L7A:
508	add	%o2, %o3, %g2
509	or	%o3, %g0, %g3
510	ba	.L7B
511	and	%g2, 255, %g2
512
513.L8A:
514	add	%o2, %o3, %g2
515	or	%o3, %g0, %g3
516	ba	.L8B
517	and	%g2, 255, %g2
518
519	.type	arcfour_crypt_aligned,2
520	.size	arcfour_crypt_aligned,(. - arcfour_crypt_aligned)
521
522#endif	/* lint || __lint */
523