1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
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
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.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; routine to do a 128 bit CBC AES encrypt
31 ;;; Updates In and Out pointers at end
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;;void aes_cbc_enc_128_x4(void *in,
37 ;; uint64_t len_bytes);
38 ; arg 1: IN: pointer to input (cipher text)
39 ; arg 2: IV: pointer to IV
40 ; arg 3: KEYS: pointer to keys
41 ; arg 4: OUT: pointer to output (plain text)
42 ; arg 5: LEN: length in bytes (multiple of 16)
44 %include "reg_sizes.asm"
46 %ifidn __OUTPUT_FORMAT__, elf64
60 %ifidn __OUTPUT_FORMAT__, win64
70 %define stack_size 10*16 + 1*8 ; must be an odd multiple of 8
71 %define arg(x) [rsp + stack_size + PS + PS*x]
73 %define func(x) proc_frame x
75 alloc_stack stack_size
76 save_xmm128 xmm6, 0*16
77 save_xmm128 xmm7, 1*16
78 save_xmm128 xmm8, 2*16
79 save_xmm128 xmm9, 3*16
80 save_xmm128 xmm10, 4*16
81 save_xmm128 xmm11, 5*16
82 save_xmm128 xmm12, 6*16
83 save_xmm128 xmm13, 7*16
84 save_xmm128 xmm14, 8*16
85 save_xmm128 xmm15, 9*16
91 movdqa xmm6, [rsp + 0*16]
92 movdqa xmm7, [rsp + 1*16]
93 movdqa xmm8, [rsp + 2*16]
94 movdqa xmm9, [rsp + 3*16]
95 movdqa xmm10, [rsp + 4*16]
96 movdqa xmm11, [rsp + 5*16]
97 movdqa xmm12, [rsp + 6*16]
98 movdqa xmm13, [rsp + 7*16]
99 movdqa xmm14, [rsp + 8*16]
100 movdqa xmm15, [rsp + 9*16]
105 %define KEY_ROUNDS 11
106 %define XMM_USAGE (16)
107 %define UNROLLED_LOOPS (3)
108 %define PARALLEL_BLOCKS (UNROLLED_LOOPS)
109 %define EARLY_BLOCKS (2)
111 ; instruction set specific operation definitions
114 %define AES_ENC aesenc
115 %define AES_ENC_LAST aesenclast
117 %include "cbc_common.asm"
120 global aes_cbc_enc_128_x4:function
121 func(aes_cbc_enc_128_x4)
125 FILL_KEY_CACHE CKEY_CNT, FIRST_CKEY, KEYS, MOVDQ
126 CBC_ENC_INIT FIRST_XDATA, TMP, MOVDQ, PXOR, IV, IN, IDX
129 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