]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/intel-ipsec-mb/avx/kasumi_avx.c
1 /*******************************************************************************
2 Copyright (c) 2009-2019, Intel Corporation
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
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.
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 *******************************************************************************/
30 #define CLEAR_SCRATCH_SIMD_REGS clear_scratch_xmms_avx
32 #include "include/save_xmms.h"
33 #include "include/kasumi_internal.h"
34 #include "include/save_xmms.h"
35 #include "include/clear_regs_mem.h"
37 #define SAVE_XMMS save_xmms_avx
38 #define RESTORE_XMMS restore_xmms_avx
41 kasumi_f8_1_buffer_avx(const kasumi_key_sched_t
*pCtx
, const uint64_t IV
,
42 const void *pBufferIn
, void *pBufferOut
,
43 const uint32_t cipherLengthInBytes
)
46 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
51 /* Check for NULL pointers */
52 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pBufferOut
== NULL
)
55 /* Check input data is in range of supported length */
56 if (cipherLengthInBytes
== 0 ||
57 cipherLengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
60 kasumi_f8_1_buffer(pCtx
, IV
, pBufferIn
, pBufferOut
,
63 /* Clear sensitive data in registers */
65 CLEAR_SCRATCH_SIMD_REGS();
68 RESTORE_XMMS(xmm_save
);
73 kasumi_f8_1_buffer_bit_avx(const kasumi_key_sched_t
*pCtx
, const uint64_t IV
,
74 const void *pBufferIn
,
76 const uint32_t cipherLengthInBits
,
77 const uint32_t offsetInBits
)
80 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
85 /* Check for NULL pointers */
86 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pBufferOut
== NULL
)
89 /* Check input data is in range of supported length */
90 if (cipherLengthInBits
== 0 ||
91 cipherLengthInBits
> KASUMI_MAX_LEN
)
94 kasumi_f8_1_buffer_bit(pCtx
, IV
, pBufferIn
, pBufferOut
,
95 cipherLengthInBits
, offsetInBits
);
97 /* Clear sensitive data in registers */
99 CLEAR_SCRATCH_SIMD_REGS();
102 RESTORE_XMMS(xmm_save
);
107 kasumi_f8_2_buffer_avx(const kasumi_key_sched_t
*pCtx
, const uint64_t IV1
,
108 const uint64_t IV2
, const void *pBufferIn1
,
109 void *pBufferOut1
, const uint32_t lengthInBytes1
,
110 const void *pBufferIn2
, void *pBufferOut2
,
111 const uint32_t lengthInBytes2
)
114 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
119 /* Check for NULL pointers */
123 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
126 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
129 /* Check input data is in range of supported length */
130 if (lengthInBytes1
== 0 || lengthInBytes1
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
133 if (lengthInBytes2
== 0 || lengthInBytes2
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
136 kasumi_f8_2_buffer(pCtx
, IV1
, IV2
,
137 pBufferIn1
, pBufferOut1
, lengthInBytes1
,
138 pBufferIn2
, pBufferOut2
, lengthInBytes2
);
140 /* Clear sensitive data in registers */
142 CLEAR_SCRATCH_SIMD_REGS();
145 RESTORE_XMMS(xmm_save
);
150 kasumi_f8_3_buffer_avx(const kasumi_key_sched_t
*pCtx
, const uint64_t IV1
,
151 const uint64_t IV2
, const uint64_t IV3
,
152 const void *pBufferIn1
, void *pBufferOut1
,
153 const void *pBufferIn2
, void *pBufferOut2
,
154 const void *pBufferIn3
, void *pBufferOut3
,
155 const uint32_t lengthInBytes
)
158 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
163 /* Check for NULL pointers */
167 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
170 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
173 if (pBufferIn3
== NULL
|| pBufferOut3
== NULL
)
176 /* Check input data is in range of supported length */
177 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
180 kasumi_f8_3_buffer(pCtx
, IV1
, IV2
, IV3
,
181 pBufferIn1
, pBufferOut1
,
182 pBufferIn2
, pBufferOut2
,
183 pBufferIn3
, pBufferOut3
, lengthInBytes
);
185 /* Clear sensitive data in registers */
187 CLEAR_SCRATCH_SIMD_REGS();
190 RESTORE_XMMS(xmm_save
);
195 kasumi_f8_4_buffer_avx(const kasumi_key_sched_t
*pCtx
,
196 const uint64_t IV1
, const uint64_t IV2
,
197 const uint64_t IV3
, const uint64_t IV4
,
198 const void *pBufferIn1
, void *pBufferOut1
,
199 const void *pBufferIn2
, void *pBufferOut2
,
200 const void *pBufferIn3
, void *pBufferOut3
,
201 const void *pBufferIn4
, void *pBufferOut4
,
202 const uint32_t lengthInBytes
)
205 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
210 /* Check for NULL pointers */
214 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
217 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
220 if (pBufferIn3
== NULL
|| pBufferOut3
== NULL
)
223 if (pBufferIn4
== NULL
|| pBufferOut4
== NULL
)
226 /* Check input data is in range of supported length */
227 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
230 kasumi_f8_4_buffer(pCtx
, IV1
, IV2
, IV3
, IV4
,
231 pBufferIn1
, pBufferOut1
,
232 pBufferIn2
, pBufferOut2
,
233 pBufferIn3
, pBufferOut3
,
234 pBufferIn4
, pBufferOut4
,
237 /* Clear sensitive data in registers */
239 CLEAR_SCRATCH_SIMD_REGS();
242 RESTORE_XMMS(xmm_save
);
247 kasumi_f8_n_buffer_avx(const kasumi_key_sched_t
*pKeySchedule
,
249 const void * const pDataIn
[], void *pDataOut
[],
250 const uint32_t dataLen
[], const uint32_t dataCount
)
253 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
257 uint32_t numLeft
= dataCount
;
258 const uint64_t *IVPtr
;
259 const void * const *pDataInPtr
;
261 const uint32_t *dataLenPtr
;
266 /* Check for NULL pointers */
267 if (pKeySchedule
== NULL
|| pDataIn
== NULL
|| pDataOut
== NULL
||
268 dataLen
== NULL
|| IV
== NULL
)
271 for (i
= 0; i
< dataCount
; i
++) {
272 /* Check for NULL pointers */
273 if (pDataIn
[i
] == NULL
|| pDataOut
[i
] == NULL
)
276 /* Check input data is in range of supported length */
277 if (dataLen
[i
] == 0 || dataLen
[i
] > (KASUMI_MAX_LEN
/ CHAR_BIT
))
284 /* KASUMI F8 n buffer function can handle up to 16 buffers */
285 while (numLeft
> 0) {
287 pDataInPtr
= &pDataIn
[i
];
288 pDataOutPtr
= &pDataOut
[i
];
289 dataLenPtr
= &dataLen
[i
];
290 numBuffs
= (numLeft
> 16) ? 16 : numLeft
;
292 kasumi_f8_n_buffer(pKeySchedule
, IVPtr
, pDataInPtr
, pDataOutPtr
,
293 dataLenPtr
, numBuffs
);
298 /* Clear sensitive data in registers */
300 CLEAR_SCRATCH_SIMD_REGS();
303 RESTORE_XMMS(xmm_save
);
309 kasumi_f9_1_buffer_avx(const kasumi_key_sched_t
*pCtx
, const void *pBufferIn
,
310 const uint32_t lengthInBytes
, void *pDigest
)
313 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
318 /* Check for NULL pointers */
319 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pDigest
== NULL
)
322 /* Check input data is in range of supported length */
323 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
326 kasumi_f9_1_buffer(pCtx
, pBufferIn
, lengthInBytes
, pDigest
);
328 /* Clear sensitive data in registers */
330 CLEAR_SCRATCH_SIMD_REGS();
333 RESTORE_XMMS(xmm_save
);
338 kasumi_f9_1_buffer_user_avx(const kasumi_key_sched_t
*pCtx
, const uint64_t IV
,
339 const void *pBufferIn
, const uint32_t lengthInBits
,
340 void *pDigest
, const uint32_t direction
)
343 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
348 /* Check for NULL pointers */
349 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pDigest
== NULL
)
352 /* Check input data is in range of supported length */
353 if (lengthInBits
== 0 || lengthInBits
> KASUMI_MAX_LEN
)
356 kasumi_f9_1_buffer_user(pCtx
, IV
, pBufferIn
, lengthInBits
,
359 /* Clear sensitive data in registers */
361 CLEAR_SCRATCH_SIMD_REGS();
364 RESTORE_XMMS(xmm_save
);
369 kasumi_init_f8_key_sched_avx(const void *const pKey
,
370 kasumi_key_sched_t
*pCtx
)
372 return kasumi_init_f8_key_sched(pKey
, pCtx
);
376 kasumi_init_f9_key_sched_avx(const void *const pKey
,
377 kasumi_key_sched_t
*pCtx
)
379 return kasumi_init_f9_key_sched(pKey
, pCtx
);
383 kasumi_key_sched_size_avx(void)
385 return kasumi_key_sched_size();