]>
Commit | Line | Data |
---|---|---|
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 256 bit CBC AES encrypt | |
31 | ;;; Updates In and Out pointers at end | |
32 | ||
33 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
34 | ;;; Updates In and Out pointers at end | |
35 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
36 | ;;void aes_cbc_enc_256_x4(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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
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 | |
80 | save_xmm128 xmm6, 0*16 | |
81 | save_xmm128 xmm7, 1*16 | |
82 | save_xmm128 xmm8, 2*16 | |
83 | save_xmm128 xmm9, 3*16 | |
84 | save_xmm128 xmm10, 4*16 | |
85 | save_xmm128 xmm11, 5*16 | |
86 | save_xmm128 xmm12, 6*16 | |
87 | save_xmm128 xmm13, 7*16 | |
88 | save_xmm128 xmm14, 8*16 | |
89 | save_xmm128 xmm15, 9*16 | |
90 | end_prolog | |
91 | mov LEN, arg(4) | |
92 | %endmacro | |
93 | ||
94 | %macro FUNC_RESTORE 0 | |
95 | movdqa xmm6, [rsp + 0*16] | |
96 | movdqa xmm7, [rsp + 1*16] | |
97 | movdqa xmm8, [rsp + 2*16] | |
98 | movdqa xmm9, [rsp + 3*16] | |
99 | movdqa xmm10, [rsp + 4*16] | |
100 | movdqa xmm11, [rsp + 5*16] | |
101 | movdqa xmm12, [rsp + 6*16] | |
102 | movdqa xmm13, [rsp + 7*16] | |
103 | movdqa xmm14, [rsp + 8*16] | |
104 | movdqa xmm15, [rsp + 9*16] | |
105 | add rsp, stack_size | |
106 | %endmacro | |
107 | %endif | |
108 | ||
109 | %define KEY_ROUNDS 15 | |
110 | %define XMM_USAGE (16) | |
111 | %DEFINE UNROLLED_LOOPS (3) | |
112 | %define PARALLEL_BLOCKS (UNROLLED_LOOPS) | |
113 | ||
114 | ; instruction set specific operation definitions | |
115 | %define MOVDQ movdqu | |
116 | %define PXOR pxor | |
117 | %define AES_ENC aesenc | |
118 | %define AES_ENC_LAST aesenclast | |
119 | ||
120 | %include "cbc_common.asm" | |
121 | ||
122 | ||
1e59de90 | 123 | mk_global aes_cbc_enc_256_x4, function |
7c673cae | 124 | func(aes_cbc_enc_256_x4) |
1e59de90 | 125 | endbranch |
7c673cae FG |
126 | FUNC_SAVE |
127 | ||
128 | mov IDX, 0 | |
129 | ||
130 | FILL_KEY_CACHE CKEY_CNT, FIRST_CKEY, KEYS, MOVDQ | |
131 | CBC_ENC_INIT FIRST_XDATA, TMP, MOVDQ, PXOR, IV, IN, IDX | |
132 | ||
133 | main_loop: | |
134 | 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 | |
135 | jne main_loop | |
136 | ||
137 | done: | |
138 | FUNC_RESTORE | |
139 | ret | |
140 | ||
141 | endproc_frame |