Skip to content

Commit 21484ec

Browse files
committed
linuxkm: add asm support for Kyber.
1 parent 8b57e3e commit 21484ec

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

linuxkm/Kbuild

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ $(obj)/wolfcrypt/benchmark/benchmark.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS
115115
asflags-y := $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPUSIMD_DISABLE)
116116

117117
# vectorized implementations that are kernel-safe are listed here.
118-
# these are known kernel-compatible, but they still irritate objtool.
118+
# these are known kernel-compatible, but need the vector instructions enabled in the assembler,
119+
# and most of them still irritate objtool.
119120
$(obj)/wolfcrypt/src/aes_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
120121
$(obj)/wolfcrypt/src/aes_asm.o: OBJECT_FILES_NON_STANDARD := y
121122
$(obj)/wolfcrypt/src/aes_gcm_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
@@ -134,6 +135,7 @@ $(obj)/wolfcrypt/src/chacha_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_
134135
$(obj)/wolfcrypt/src/chacha_asm.o: OBJECT_FILES_NON_STANDARD := y
135136
$(obj)/wolfcrypt/src/poly1305_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
136137
$(obj)/wolfcrypt/src/poly1305_asm.o: OBJECT_FILES_NON_STANDARD := y
138+
$(obj)/wolfcrypt/src/wc_kyber_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
137139

138140
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
139141

linuxkm/module_exports.c.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
#include <wolfssl/wolfcrypt/wc_lms.h>
172172
#endif
173173
#endif
174+
#ifdef HAVE_DILITHIUM
175+
#include <wolfssl/wolfcrypt/dilithium.h>
176+
#endif
174177

175178
#ifdef OPENSSL_EXTRA
176179
#ifndef WOLFCRYPT_ONLY

wolfcrypt/src/wc_kyber.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,7 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
377377
sword16* epp = NULL;
378378
unsigned int kp = 0;
379379
unsigned int compVecSz = 0;
380-
#ifndef USE_INTEL_SPEEDUP
381380
sword16* at = NULL;
382-
#else
383-
sword16 at[((KYBER_MAX_K + 3) * KYBER_MAX_K + 3) * KYBER_N];
384-
#endif
385381

386382
/* Establish parameters based on key type. */
387383
switch (key->type) {
@@ -409,16 +405,20 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
409405
break;
410406
}
411407

412-
#ifndef USE_INTEL_SPEEDUP
413408
if (ret == 0) {
414409
/* Allocate dynamic memory for all matrices, vectors and polynomials. */
410+
#ifndef USE_INTEL_SPEEDUP
415411
at = (sword16*)XMALLOC(((kp + 3) * kp + 3) * KYBER_N * sizeof(sword16),
416412
key->heap, DYNAMIC_TYPE_TMP_BUFFER);
413+
#else
414+
at = (sword16*)XMALLOC(
415+
((KYBER_MAX_K + 3) * KYBER_MAX_K + 3) * KYBER_N * sizeof(sword16),
416+
key->heap, DYNAMIC_TYPE_TMP_BUFFER);
417+
#endif
417418
if (at == NULL) {
418419
ret = MEMORY_E;
419420
}
420421
}
421-
#endif
422422

423423
if (ret == 0) {
424424
/* Assign allocated dynamic memory to pointers.
@@ -472,10 +472,8 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
472472
#endif
473473
}
474474

475-
#ifndef USE_INTEL_SPEEDUP
476475
/* Dispose of dynamic memory allocated in function. */
477476
XFREE(at, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
478-
#endif
479477

480478
return ret;
481479
}

0 commit comments

Comments
 (0)