Skip to content

Commit 6261108

Browse files
committed
linuxkm: fix line lengths throughout; in linuxkm/lkcapi_glue.c: fix/harmonize error catching, reporting, and error codes; further address peer review feedback.
1 parent 856c9a9 commit 6261108

7 files changed

Lines changed: 494 additions & 268 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
(int)_xatoi_res; \
6666
})
6767

68-
/* Kbuild+gcc on x86 doesn't consistently honor the default ALIGN16 on stack objects,
69-
* but gives adequate alignment with "32".
68+
/* Kbuild+gcc on x86 doesn't consistently honor the default ALIGN16 on stack
69+
* objects, but gives adequate alignment with "32".
7070
*/
7171
#if defined(CONFIG_X86) && !defined(ALIGN16)
7272
#define ALIGN16 __attribute__ ( (aligned (32)))
@@ -157,7 +157,9 @@
157157
(sizeof(s) - 1) : strlen(s))
158158

159159
static inline void *my_memcpy(void *dest, const void *src, size_t n) {
160-
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n) & (uintptr_t)(sizeof(uintptr_t) - 1))) {
160+
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n)
161+
& (uintptr_t)(sizeof(uintptr_t) - 1)))
162+
{
161163
uintptr_t *src_longs = (uintptr_t *)src,
162164
*dest_longs = (uintptr_t *)dest,
163165
*endp = (uintptr_t *)((u8 *)src + n);
@@ -176,13 +178,16 @@
176178
#define memcpy my_memcpy
177179

178180
static inline void *my_memset(void *dest, int c, size_t n) {
179-
if (! (((uintptr_t)dest | (uintptr_t)n) & (uintptr_t)(sizeof(uintptr_t) - 1))) {
181+
if (! (((uintptr_t)dest | (uintptr_t)n)
182+
& (uintptr_t)(sizeof(uintptr_t) - 1)))
183+
{
180184
uintptr_t c_long = __builtin_choose_expr(
181185
sizeof(uintptr_t) == 8,
182186
(uintptr_t)(u8)c * 0x0101010101010101UL,
183187
(uintptr_t)(u8)c * 0x01010101U
184188
);
185-
uintptr_t *dest_longs = (uintptr_t *)dest, *endp = (uintptr_t *)((u8 *)dest_longs + n);
189+
uintptr_t *dest_longs = (uintptr_t *)dest,
190+
*endp = (uintptr_t *)((u8 *)dest_longs + n);
186191
while (dest_longs < endp)
187192
*dest_longs++ = c_long;
188193
} else {
@@ -196,8 +201,11 @@
196201
#define memset my_memset
197202

198203
static inline void *my_memmove(void *dest, const void *src, size_t n) {
199-
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n) & (uintptr_t)(sizeof(uintptr_t) - 1))) {
200-
uintptr_t *src_longs = (uintptr_t *)src, *dest_longs = (uintptr_t *)dest;
204+
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n)
205+
& (uintptr_t)(sizeof(uintptr_t) - 1)))
206+
{
207+
uintptr_t *src_longs = (uintptr_t *)src,
208+
*dest_longs = (uintptr_t *)dest;
201209
n >>= __builtin_choose_expr(
202210
sizeof(uintptr_t) == 8,
203211
3U,
@@ -270,12 +278,26 @@
270278
#include <crypto/internal/aead.h>
271279
#include <crypto/internal/skcipher.h>
272280

281+
/* the LKCAPI assumes that expanded encrypt and decrypt keys will stay
282+
* loaded simultaneously, and the Linux in-tree implementations have two
283+
* AES key structs in each context, one for each direction. in
284+
* linuxkm/lkcapi_glue.c (used for CBC, CFB, and GCM), we do the same
285+
* thing with "struct km_AesCtx". however, wolfCrypt struct AesXts
286+
* already has two AES expanded keys, the main and tweak, and the tweak
287+
* is always used in the encrypt direction regardless of the main
288+
* direction. to avoid allocating and computing a duplicate second
289+
* tweak encrypt key, we set
290+
* WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS, which adds a second
291+
* Aes slot to wolfCrypt's struct AesXts, and activates support for
292+
* AES_ENCRYPTION_AND_DECRYPTION on AES-XTS.
293+
*/
273294
#ifndef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
274295
#define WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
275296
#endif
276297
#endif
277298

278-
#if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || defined(WOLFSSL_SP_X86_64_ASM)
299+
#if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \
300+
defined(WOLFSSL_SP_X86_64_ASM)
279301
#ifndef CONFIG_X86
280302
#error X86 SIMD extensions requested, but CONFIG_X86 is not set.
281303
#endif
@@ -301,21 +323,35 @@
301323
#endif
302324
#endif
303325

304-
/* benchmarks.c uses floating point math, so needs a working SAVE_VECTOR_REGISTERS(). */
305-
#if defined(WOLFSSL_LINUXKM_BENCHMARKS) && !defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
326+
/* benchmarks.c uses floating point math, so needs a working
327+
* SAVE_VECTOR_REGISTERS().
328+
*/
329+
#if defined(WOLFSSL_LINUXKM_BENCHMARKS) && \
330+
!defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
306331
#define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
307332
#endif
308333

309-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
334+
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && \
335+
defined(CONFIG_X86)
310336
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
311337
#include <asm/i387.h>
312338
#else
313339
#include <asm/simd.h>
314340
#endif
315341
#ifndef SAVE_VECTOR_REGISTERS
316-
#define SAVE_VECTOR_REGISTERS(fail_clause) { int _svr_ret = save_vector_registers_x86(); if (_svr_ret != 0) { fail_clause } }
342+
#define SAVE_VECTOR_REGISTERS(fail_clause) { \
343+
int _svr_ret = save_vector_registers_x86(); \
344+
if (_svr_ret != 0) { \
345+
fail_clause \
346+
} \
347+
}
317348
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
318-
#define SAVE_VECTOR_REGISTERS2() ({ int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); (_fuzzer_ret == 0) ? save_vector_registers_x86() : _fuzzer_ret; })
349+
#define SAVE_VECTOR_REGISTERS2() ({ \
350+
int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); \
351+
(_fuzzer_ret == 0) ? \
352+
save_vector_registers_x86() : \
353+
_fuzzer_ret; \
354+
})
319355
#else
320356
#define SAVE_VECTOR_REGISTERS2() save_vector_registers_x86()
321357
#endif

0 commit comments

Comments
 (0)