]> git.proxmox.com Git - ceph.git/blame - ceph/src/crypto/isa-l/isa-l_crypto/aes/cbc_enc_128_x8_sb.asm
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / aes / cbc_enc_128_x8_sb.asm
CommitLineData
7c673cae
FG
1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3;
4; Redistribution and use in source and binary forms, with or without
1e59de90 5; modification, are permitted provided that the following conditions
7c673cae
FG
6; are met:
7; * Redistributions of source code must retain the above copyright
8; notice, this list of conditions and the following disclaimer.
9; * Redistributions in binary form must reproduce the above copyright
10; notice, this list of conditions and the following disclaimer in
11; the documentation and/or other materials provided with the
12; distribution.
13; * Neither the name of Intel Corporation nor the names of its
14; contributors may be used to endorse or promote products derived
15; from this software without specific prior written permission.
16;
17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
30;;; routine to do a 128 bit CBC AES encrypt
31;; clobbers all registers except for ARG1 and rbp
32
33;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34;;; Updates In and Out pointers at end
35;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36;;void aes_cbc_enc_256_x8(void *in,
37;; uint8_t *IV,
38;; uint8_t keys,
39;; void *out,
40;; uint64_t len_bytes);
41; arg 1: IN: pointer to input (cipher text)
42; arg 2: IV: pointer to IV
43; arg 3: KEYS: pointer to keys
44; arg 4: OUT: pointer to output (plain text)
45; arg 5: LEN: length in bytes (multiple of 16)
46;; clobbers all registers except for ARG1 and rbp
47
48%include "reg_sizes.asm"
49
50%ifidn __OUTPUT_FORMAT__, elf64
51%define IN0 rdi
52%define IN rdi
53%define IV rsi
54%define KEYS rdx
55%define OUT rcx
56%define LEN r8
57%define KEYS0 rdx
58%define OUT0 rcx
59%define func(x) x:
60%define FUNC_SAVE
61%define FUNC_RESTORE
62%endif
63
64%ifidn __OUTPUT_FORMAT__, win64
65%define IN0 rcx
66%define IN rcx
67%define IV rdx
68%define KEYS0 r8
69%define OUT0 r9
70%define KEYS r8
71%define OUT r9
72%define LEN r10
73%define PS 8
74%define stack_size 10*16 + 1*8 ; must be an odd multiple of 8
75%define arg(x) [rsp + stack_size + PS + PS*x]
76
77%define func(x) proc_frame x
78%macro FUNC_SAVE 0
79 alloc_stack stack_size
1e59de90
TL
80 vmovdqa [rsp + 0*16], xmm6
81 vmovdqa [rsp + 1*16], xmm7
82 vmovdqa [rsp + 2*16], xmm8
83 vmovdqa [rsp + 3*16], xmm9
84 vmovdqa [rsp + 4*16], xmm10
85 vmovdqa [rsp + 5*16], xmm11
86 vmovdqa [rsp + 6*16], xmm12
87 vmovdqa [rsp + 7*16], xmm13
88 vmovdqa [rsp + 8*16], xmm14
89 vmovdqa [rsp + 9*16], xmm15
7c673cae
FG
90 end_prolog
91 mov LEN, arg(4)
92%endmacro
93
94%macro FUNC_RESTORE 0
1e59de90
TL
95 vmovdqa xmm6, [rsp + 0*16]
96 vmovdqa xmm7, [rsp + 1*16]
97 vmovdqa xmm8, [rsp + 2*16]
98 vmovdqa xmm9, [rsp + 3*16]
99 vmovdqa xmm10, [rsp + 4*16]
100 vmovdqa xmm11, [rsp + 5*16]
101 vmovdqa xmm12, [rsp + 6*16]
102 vmovdqa xmm13, [rsp + 7*16]
103 vmovdqa xmm14, [rsp + 8*16]
104 vmovdqa xmm15, [rsp + 9*16]
7c673cae
FG
105 add rsp, stack_size
106%endmacro
107%endif
108
109%define KEY_ROUNDS 11
110%define XMM_USAGE (16)
111%DEFINE UNROLLED_LOOPS (3)
112%define PARALLEL_BLOCKS (UNROLLED_LOOPS)
113%define IV_CNT (1)
114
115; instruction set specific operation definitions
1e59de90 116%define MOVDQ vmovdqu
7c673cae
FG
117%macro PXOR 2
118 vpxor %1, %1, %2
119%endm
120
121%macro AES_ENC 2
122 vaesenc %1, %1, %2
123%endm
124
125%macro AES_ENC_LAST 2
126 vaesenclast %1, %1, %2
127%endm
128
129%include "cbc_common.asm"
130
131
1e59de90 132mk_global aes_cbc_enc_128_x8, function
7c673cae 133func(aes_cbc_enc_128_x8)
1e59de90 134 endbranch
7c673cae
FG
135 FUNC_SAVE
136
137 mov IDX, 0
138
139 FILL_KEY_CACHE CKEY_CNT, FIRST_CKEY, KEYS, MOVDQ
140 CBC_ENC_INIT FIRST_XDATA, TMP, MOVDQ, PXOR, IV, IN, IDX
141
142main_loop:
143 CBC_ENC_SUBLOOP KEY_ROUNDS, UNROLLED_LOOPS, FIRST_XDATA, MOVDQ, PXOR, AES_ENC, AES_ENC_LAST, TMP, TMP_CNT, FIRST_CKEY, CKEY_CNT, KEYS, CACHED_KEYS, IN, OUT, IDX, LEN
144 jne main_loop
145
146done:
147
148 FUNC_RESTORE
149 ret
150
151endproc_frame