]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/intel-ipsec-mb/sse/kasumi_sse.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_sse
32 #include "include/kasumi_internal.h"
33 #include "include/save_xmms.h"
34 #include "include/clear_regs_mem.h"
36 #define SAVE_XMMS save_xmms
37 #define RESTORE_XMMS restore_xmms
40 kasumi_f8_1_buffer_sse(const kasumi_key_sched_t
*pCtx
, const uint64_t IV
,
41 const void *pBufferIn
, void *pBufferOut
,
42 const uint32_t cipherLengthInBytes
)
45 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
50 /* Check for NULL pointers */
51 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pBufferOut
== NULL
)
54 /* Check input data is in range of supported length */
55 if (cipherLengthInBytes
== 0 ||
56 cipherLengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
59 kasumi_f8_1_buffer(pCtx
, IV
, pBufferIn
, pBufferOut
,
62 /* Clear sensitive data in registers */
64 CLEAR_SCRATCH_SIMD_REGS();
67 RESTORE_XMMS(xmm_save
);
72 kasumi_f8_1_buffer_bit_sse(const kasumi_key_sched_t
*pCtx
,
74 const void *pBufferIn
, void *pBufferOut
,
75 const uint32_t cipherLengthInBits
,
76 const uint32_t offsetInBits
)
79 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
84 /* Check for NULL pointers */
85 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pBufferOut
== NULL
)
88 /* Check input data is in range of supported length */
89 if (cipherLengthInBits
== 0 ||
90 cipherLengthInBits
> KASUMI_MAX_LEN
)
93 kasumi_f8_1_buffer_bit(pCtx
, IV
, pBufferIn
, pBufferOut
,
94 cipherLengthInBits
, offsetInBits
);
96 /* Clear sensitive data in registers */
98 CLEAR_SCRATCH_SIMD_REGS();
101 RESTORE_XMMS(xmm_save
);
106 kasumi_f8_2_buffer_sse(const kasumi_key_sched_t
*pCtx
, const uint64_t IV1
,
107 const uint64_t IV2
, const void *pBufferIn1
,
108 void *pBufferOut1
, const uint32_t lengthInBytes1
,
109 const void *pBufferIn2
, void *pBufferOut2
,
110 const uint32_t lengthInBytes2
)
113 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
118 /* Check for NULL pointers */
122 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
125 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
128 /* Check input data is in range of supported length */
129 if (lengthInBytes1
== 0 || lengthInBytes1
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
132 if (lengthInBytes2
== 0 || lengthInBytes2
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
135 kasumi_f8_2_buffer(pCtx
, IV1
, IV2
,
136 pBufferIn1
, pBufferOut1
, lengthInBytes1
,
137 pBufferIn2
, pBufferOut2
, lengthInBytes2
);
139 /* Clear sensitive data in registers */
141 CLEAR_SCRATCH_SIMD_REGS();
144 RESTORE_XMMS(xmm_save
);
149 kasumi_f8_3_buffer_sse(const kasumi_key_sched_t
*pCtx
, const uint64_t IV1
,
150 const uint64_t IV2
, const uint64_t IV3
,
151 const void *pBufferIn1
, void *pBufferOut1
,
152 const void *pBufferIn2
, void *pBufferOut2
,
153 const void *pBufferIn3
, void *pBufferOut3
,
154 const uint32_t lengthInBytes
)
157 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
162 /* Check for NULL pointers */
166 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
169 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
172 if (pBufferIn3
== NULL
|| pBufferOut3
== NULL
)
175 /* Check input data is in range of supported length */
176 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
179 kasumi_f8_3_buffer(pCtx
, IV1
, IV2
, IV3
,
180 pBufferIn1
, pBufferOut1
,
181 pBufferIn2
, pBufferOut2
,
182 pBufferIn3
, pBufferOut3
, lengthInBytes
);
184 /* Clear sensitive data in registers */
186 CLEAR_SCRATCH_SIMD_REGS();
189 RESTORE_XMMS(xmm_save
);
194 kasumi_f8_4_buffer_sse(const kasumi_key_sched_t
*pCtx
,
195 const uint64_t IV1
, const uint64_t IV2
,
196 const uint64_t IV3
, const uint64_t IV4
,
197 const void *pBufferIn1
, void *pBufferOut1
,
198 const void *pBufferIn2
, void *pBufferOut2
,
199 const void *pBufferIn3
, void *pBufferOut3
,
200 const void *pBufferIn4
, void *pBufferOut4
,
201 const uint32_t lengthInBytes
)
204 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
209 /* Check for NULL pointers */
213 if (pBufferIn1
== NULL
|| pBufferOut1
== NULL
)
216 if (pBufferIn2
== NULL
|| pBufferOut2
== NULL
)
219 if (pBufferIn3
== NULL
|| pBufferOut3
== NULL
)
222 if (pBufferIn4
== NULL
|| pBufferOut4
== NULL
)
225 /* Check input data is in range of supported length */
226 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
229 kasumi_f8_4_buffer(pCtx
, IV1
, IV2
, IV3
, IV4
,
230 pBufferIn1
, pBufferOut1
,
231 pBufferIn2
, pBufferOut2
,
232 pBufferIn3
, pBufferOut3
,
233 pBufferIn4
, pBufferOut4
,
236 /* Clear sensitive data in registers */
238 CLEAR_SCRATCH_SIMD_REGS();
241 RESTORE_XMMS(xmm_save
);
246 kasumi_f8_n_buffer_sse(const kasumi_key_sched_t
*pKeySchedule
,
248 const void * const pDataIn
[], void *pDataOut
[],
249 const uint32_t dataLen
[], const uint32_t dataCount
)
252 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
256 uint32_t numLeft
= dataCount
;
257 const uint64_t *IVPtr
;
258 const void * const *pDataInPtr
;
260 const uint32_t *dataLenPtr
;
265 /* Check for NULL pointers */
266 if (pKeySchedule
== NULL
|| pDataIn
== NULL
|| pDataOut
== NULL
||
267 dataLen
== NULL
|| IV
== NULL
)
270 for (i
= 0; i
< dataCount
; i
++) {
271 /* Check for NULL pointers */
272 if (pDataIn
[i
] == NULL
|| pDataOut
[i
] == NULL
)
275 /* Check input data is in range of supported length */
276 if (dataLen
[i
] == 0 || dataLen
[i
] > (KASUMI_MAX_LEN
/ CHAR_BIT
))
283 /* KASUMI F8 n buffer function can handle up to 16 buffers */
284 while (numLeft
> 0) {
286 pDataInPtr
= &pDataIn
[i
];
287 pDataOutPtr
= &pDataOut
[i
];
288 dataLenPtr
= &dataLen
[i
];
289 numBuffs
= (numLeft
> 16) ? 16 : numLeft
;
291 kasumi_f8_n_buffer(pKeySchedule
, IVPtr
, pDataInPtr
, pDataOutPtr
,
292 dataLenPtr
, numBuffs
);
297 /* Clear sensitive data in registers */
299 CLEAR_SCRATCH_SIMD_REGS();
302 RESTORE_XMMS(xmm_save
);
308 kasumi_f9_1_buffer_sse(const kasumi_key_sched_t
*pCtx
, const void *pBufferIn
,
309 const uint32_t lengthInBytes
, void *pDigest
)
312 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
317 /* Check for NULL pointers */
318 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pDigest
== NULL
)
321 /* Check input data is in range of supported length */
322 if (lengthInBytes
== 0 || lengthInBytes
> (KASUMI_MAX_LEN
/ CHAR_BIT
))
325 kasumi_f9_1_buffer(pCtx
, pBufferIn
, lengthInBytes
, pDigest
);
327 /* Clear sensitive data in registers */
329 CLEAR_SCRATCH_SIMD_REGS();
332 RESTORE_XMMS(xmm_save
);
337 kasumi_f9_1_buffer_user_sse(const kasumi_key_sched_t
*pCtx
, const uint64_t IV
,
338 const void *pBufferIn
, const uint32_t lengthInBits
,
339 void *pDigest
, const uint32_t direction
)
342 DECLARE_ALIGNED(uint128_t xmm_save
[10], 16);
347 /* Check for NULL pointers */
348 if (pCtx
== NULL
|| pBufferIn
== NULL
|| pDigest
== NULL
)
351 /* Check input data is in range of supported length */
352 if (lengthInBits
== 0 || lengthInBits
> KASUMI_MAX_LEN
)
355 kasumi_f9_1_buffer_user(pCtx
, IV
, pBufferIn
, lengthInBits
,
358 /* Clear sensitive data in registers */
360 CLEAR_SCRATCH_SIMD_REGS();
363 RESTORE_XMMS(xmm_save
);
368 kasumi_init_f8_key_sched_sse(const void *const pKey
,
369 kasumi_key_sched_t
*pCtx
)
371 return kasumi_init_f8_key_sched(pKey
, pCtx
);
375 kasumi_init_f9_key_sched_sse(const void *const pKey
,
376 kasumi_key_sched_t
*pCtx
)
378 return kasumi_init_f9_key_sched(pKey
, pCtx
);
382 kasumi_key_sched_size_sse(void)
384 return kasumi_key_sched_size();