aesencdec_amd64.S revision 267654
1/*-
2 * Copyright (c) 2010 Konstantin Belousov <kib@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <machine/asmacros.h>
28
29	.text
30
31ENTRY(aesni_enc)
32	.cfi_startproc
33	movdqu	(%rdx),%xmm0
34	cmpq	$0,%r8
35	je	1f
36	movdqu	(%r8),%xmm1	/* unaligned load into reg */
37	pxor	%xmm1,%xmm0	/* pxor otherwise can fault on iv */
381:
39	pxor	(%rsi),%xmm0
402:
41	addq	$0x10,%rsi
42//	aesenc	(%rsi),%xmm0
43	.byte	0x66,0x0f,0x38,0xdc,0x06
44	decl	%edi
45	jne	2b
46	addq	$0x10,%rsi
47//	aesenclast (%rsi),%xmm0
48	.byte	0x66,0x0f,0x38,0xdd,0x06
49	movdqu	%xmm0,(%rcx)
50	retq
51	.cfi_endproc
52END(aesni_enc)
53
54ENTRY(aesni_dec)
55	.cfi_startproc
56	movdqu	(%rdx),%xmm0
57	pxor	(%rsi),%xmm0
581:
59	addq	$0x10,%rsi
60//	aesdec	(%rsi),%xmm0
61	.byte	0x66,0x0f,0x38,0xde,0x06
62	decl	%edi
63	jne	1b
64	addq	$0x10,%rsi
65//	aesdeclast (%rsi),%xmm0
66	.byte	0x66,0x0f,0x38,0xdf,0x06
67	cmpq	$0,%r8
68	je	2f
69	movdqu	(%r8),%xmm1
70	pxor	%xmm1,%xmm0
712:
72	movdqu	%xmm0,(%rcx)
73	retq
74	.cfi_endproc
75END(aesni_dec)
76
77ENTRY(aesni_decrypt_cbc)
78	.cfi_startproc
79	shrq	$4,%rdx
80	movdqu	(%r8),%xmm1
811:
82	movdqu	(%rcx),%xmm0
83	movdqa	%xmm0,%xmm2
84	pxor	(%rsi),%xmm0
85	cmpl	$12,%edi
86//	aesdec	0x10(%rsi),%xmm0
87	.byte	0x66,0x0f,0x38,0xde,0x46,0x10
88//	aesdec	0x20(%rsi),%xmm0
89	.byte	0x66,0x0f,0x38,0xde,0x46,0x20
90//	aesdec	0x30(%rsi),%xmm0
91	.byte	0x66,0x0f,0x38,0xde,0x46,0x30
92//	aesdec	0x40(%rsi),%xmm0
93	.byte	0x66,0x0f,0x38,0xde,0x46,0x40
94//	aesdec	0x50(%rsi),%xmm0
95	.byte	0x66,0x0f,0x38,0xde,0x46,0x50
96//	aesdec	0x60(%rsi),%xmm0
97	.byte	0x66,0x0f,0x38,0xde,0x46,0x60
98//	aesdec	0x70(%rsi),%xmm0
99	.byte	0x66,0x0f,0x38,0xde,0x46,0x70
100//	aesdec	0x80(%rsi),%xmm0
101	.byte	0x66,0x0f,0x38,0xde,0x86,0x80,0x00,0x00,0x00
102//	aesdec	0x90(%rsi),%xmm0
103	.byte	0x66,0x0f,0x38,0xde,0x86,0x90,0x00,0x00,0x00
104	jge	2f
105//	aesdeclast 0xa0(%rsi),%xmm0
106	.byte	0x66,0x0f,0x38,0xdf,0x86,0xa0,0x00,0x00,0x00
107	jmp	4f
1082:
109//	aesdec	0xa0(%rsi),%xmm0
110	.byte	0x66,0x0f,0x38,0xde,0x86,0xa0,0x00,0x00,0x00
111//	aesdec	0xb0(%rsi),%xmm0
112	.byte	0x66,0x0f,0x38,0xde,0x86,0xb0,0x00,0x00,0x00
113	jg	3f
114//	aesdeclast 0xc0(%rsi),%xmm0
115	.byte	0x66,0x0f,0x38,0xdf,0x86,0xc0,0x00,0x00,0x00
116	jmp	4f
1173:
118//	aesdec	0xc0(%rsi),%xmm0
119	.byte	0x66,0x0f,0x38,0xde,0x86,0xc0,0x00,0x00,0x00
120//	aesdec	0xd0(%rsi),%xmm0
121	.byte	0x66,0x0f,0x38,0xde,0x86,0xd0,0x00,0x00,0x00
122//	aesdeclast 0xe0(%rsi),%xmm0
123	.byte	0x66,0x0f,0x38,0xdf,0x86,0xe0,0x00,0x00,0x00
1244:
125	pxor	%xmm1,%xmm0
126	movdqu	%xmm0,(%rcx)
127	movdqa	%xmm2,%xmm1	// iv
128	addq	$0x10,%rcx
129	decq	%rdx
130	jne	1b
131	retq
132	.cfi_endproc
133END(aesni_decrypt_cbc)
134
135	.ident	"$FreeBSD: releng/9.3/sys/crypto/aesni/aesencdec_amd64.S 210409 2010-07-23 11:00:46Z kib $"
136