]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | ;; |
2 | ;; Copyright (c) 2017-2018, Intel Corporation | |
3 | ;; | |
4 | ;; Redistribution and use in source and binary forms, with or without | |
5 | ;; modification, are permitted provided that the following conditions are met: | |
6 | ;; | |
7 | ;; * Redistributions of source code must retain the above copyright notice, | |
8 | ;; 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 the | |
11 | ;; documentation and/or other materials provided with the distribution. | |
12 | ;; * Neither the name of Intel Corporation nor the names of its contributors | |
13 | ;; may be used to endorse or promote products derived from this software | |
14 | ;; without specific prior written permission. | |
15 | ;; | |
16 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
20 | ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
22 | ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
23 | ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
25 | ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | ;; | |
27 | ||
28 | %include "os.asm" | |
29 | %include "memcpy.asm" | |
30 | ||
31 | ;;; Routine to do 128 bit CFB AES encrypt/decrypt operations on one block only. | |
32 | ;;; It processes only one buffer at a time. | |
33 | ;;; It is designed to manage partial blocks of DOCSIS 3.1 SEC BPI | |
34 | ||
35 | ;; In System V AMD64 ABI | |
36 | ;; calle saves: RBX, RBP, R12-R15 | |
37 | ;; Windows x64 ABI | |
38 | ;; calle saves: RBX, RBP, RDI, RSI, RSP, R12-R15 | |
39 | ;; | |
40 | ;; Registers: RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15 | |
41 | ;; ----------------------------------------------------------- | |
42 | ;; Windows clobbers: RAX R9 R10 R11 | |
43 | ;; Windows preserves: RBX RCX RDX RBP RSI RDI R8 R12 R13 R14 R15 | |
44 | ;; ----------------------------------------------------------- | |
45 | ;; Linux clobbers: RAX R9 R10 | |
46 | ;; Linux preserves: RBX RCX RDX RBP RSI RDI R8 R11 R12 R13 R14 R15 | |
47 | ;; ----------------------------------------------------------- | |
48 | ;; | |
49 | ;; Linux/Windows clobbers: xmm0 | |
50 | ;; | |
51 | ||
9f95a23c TL |
52 | %ifndef AES_CFB_128_ONE |
53 | %define AES_CFB_128_ONE aes_cfb_128_one_sse | |
54 | %endif | |
55 | ||
11fdf7f2 TL |
56 | %ifdef LINUX |
57 | %define arg1 rdi | |
58 | %define arg2 rsi | |
59 | %define arg3 rdx | |
60 | %define arg4 rcx | |
61 | %define arg5 r8 | |
62 | %else | |
63 | %define arg1 rcx | |
64 | %define arg2 rdx | |
65 | %define arg3 r8 | |
66 | %define arg4 r9 | |
67 | %define arg5 [rsp + 5*8] | |
68 | %endif | |
69 | ||
70 | %define OUT arg1 | |
71 | %define IN arg2 | |
72 | %define IV arg3 | |
73 | %define KEYS arg4 | |
74 | %ifdef LINUX | |
75 | %define LEN arg5 | |
76 | %else | |
77 | %define LEN2 arg5 | |
78 | %define LEN r11 | |
79 | %endif | |
80 | ||
81 | %define TMP0 rax | |
82 | %define TMP1 r10 | |
83 | %define PTR0 rsp + _buffer | |
84 | ||
85 | %define XDATA xmm0 | |
86 | ||
87 | section .text | |
88 | ||
89 | struc STACK | |
90 | _buffer: resq 2 | |
91 | _rsp_save: resq 1 | |
92 | endstruc | |
93 | ||
94 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
95 | ;; void aes_cfb_128_one(void *out, void *in, void *iv, void *keys) | |
96 | ;; arg 1: OUT : addr to put clear/cipher text out | |
97 | ;; arg 2: IN : addr to take cipher/clear text from | |
98 | ;; arg 3: IV : initialization vector | |
99 | ;; arg 4: KEYS: pointer to expanded keys structure (16 byte aligned) | |
100 | ;; arg 5: LEN: length of the text to encrypt/decrypt (valid range is 0 to 16) | |
101 | ;; | |
102 | ;; AES CFB128 one block encrypt/decrypt implementation. | |
103 | ;; The function doesn't update IV. The result of operation can be found in OUT. | |
104 | ;; | |
105 | ;; It is primarly designed to process partial block of | |
106 | ;; DOCSIS 3.1 AES Packet PDU Encryption (I.10) | |
107 | ;; | |
108 | ;; It process up to one block only (up to 16 bytes). | |
109 | ;; | |
110 | ;; It makes sure not to read more than LEN bytes from IN and | |
111 | ;; not to store more than LEN bytes to OUT. | |
112 | ||
9f95a23c | 113 | MKGLOBAL(AES_CFB_128_ONE,function,) |
11fdf7f2 | 114 | align 32 |
9f95a23c | 115 | AES_CFB_128_ONE: |
11fdf7f2 TL |
116 | %ifndef LINUX |
117 | mov LEN, LEN2 | |
118 | %endif | |
119 | mov rax, rsp | |
120 | sub rsp, STACK_size | |
121 | and rsp, -16 | |
122 | mov [rsp + _rsp_save], rax | |
123 | ||
124 | test LEN, 16 | |
125 | jz copy_in_lt16 | |
126 | movdqu XDATA, [IN] | |
127 | movdqa [PTR0], XDATA | |
128 | jmp copy_in_end | |
129 | copy_in_lt16: | |
130 | memcpy_sse_16 PTR0, IN, LEN, TMP0, TMP1 | |
131 | copy_in_end: | |
132 | ||
133 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
134 | ||
135 | movdqu XDATA, [IV] ; IV (or next to last block) | |
136 | pxor XDATA, [KEYS + 16*0] ; 0. ARK | |
137 | aesenc XDATA, [KEYS + 16*1] ; 1. ENC | |
138 | aesenc XDATA, [KEYS + 16*2] ; 2. ENC | |
139 | aesenc XDATA, [KEYS + 16*3] ; 3. ENC | |
140 | aesenc XDATA, [KEYS + 16*4] ; 4. ENC | |
141 | aesenc XDATA, [KEYS + 16*5] ; 5. ENC | |
142 | aesenc XDATA, [KEYS + 16*6] ; 6. ENC | |
143 | aesenc XDATA, [KEYS + 16*7] ; 7. ENC | |
144 | aesenc XDATA, [KEYS + 16*8] ; 8. ENC | |
145 | aesenc XDATA, [KEYS + 16*9] ; 9. ENC | |
146 | aesenclast XDATA, [KEYS + 16*10] ; 10. ENC | |
147 | ||
148 | pxor XDATA, [PTR0] ; plaintext/ciphertext XOR block cipher encryption | |
149 | ||
150 | test LEN, 16 | |
151 | jz copy_out_lt16 | |
152 | movdqu [OUT], XDATA | |
153 | jmp copy_out_end | |
154 | copy_out_lt16: | |
155 | movdqa [PTR0], XDATA | |
156 | memcpy_sse_16 OUT, PTR0, LEN, TMP0, TMP1 | |
157 | copy_out_end: | |
158 | ||
159 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
160 | ||
161 | mov rsp, [rsp + _rsp_save] ; original SP | |
162 | ret | |
163 | ||
164 | %ifdef LINUX | |
165 | section .note.GNU-stack noalloc noexec nowrite progbits | |
166 | %endif |