Skip to content

Commit

Permalink
Merge pull request #7872 from douzzer/20240814-linuxkm-kyber-asm
Browse files Browse the repository at this point in the history
20240814-linuxkm-kyber-asm
  • Loading branch information
SparkiDev authored Aug 15, 2024
2 parents 003ea8b + a2acc41 commit ccd8b9a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
4 changes: 3 additions & 1 deletion linuxkm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ $(obj)/wolfcrypt/benchmark/benchmark.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS
asflags-y := $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPUSIMD_DISABLE)

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

ifeq "$(ENABLED_LINUXKM_PIE)" "yes"

Expand Down
3 changes: 3 additions & 0 deletions linuxkm/module_exports.c.template
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
#include <wolfssl/wolfcrypt/wc_lms.h>
#endif
#endif
#ifdef HAVE_DILITHIUM
#include <wolfssl/wolfcrypt/dilithium.h>
#endif

#ifdef OPENSSL_EXTRA
#ifndef WOLFCRYPT_ONLY
Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
#define AESNI_ALIGN 16
#endif

/* note that all write access to these static variables must be idempotent,
* as arranged by Check_CPU_support_AES(), else they will be susceptible to
* data races.
*/
static int checkedAESNI = 0;
static int haveAESNI = 0;
static word32 intel_flags = 0;
Expand Down
5 changes: 3 additions & 2 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -19717,13 +19717,14 @@ static int DecodeAuthKeyId(const byte* input, word32 sz, DecodedCert* cert)
return ASN_PARSE_E;
}

cert->extAuthKeyIdSz = length;

#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
#ifdef WOLFSSL_AKID_NAME
cert->extRawAuthKeyIdSrc = input;
cert->extRawAuthKeyIdSz = sz;
#endif
cert->extAuthKeyIdSrc = &input[idx];
cert->extAuthKeyIdSz = length;
#endif /* OPENSSL_EXTRA */

return GetHashId(input + idx, length, cert->extAuthKeyId,
Expand Down Expand Up @@ -19819,9 +19820,9 @@ static int DecodeSubjKeyId(const byte* input, word32 sz, DecodedCert* cert)

ret = GetOctetString(input, &idx, &length, sz);
if (ret > 0) {
cert->extSubjKeyIdSz = (word32)length;
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
cert->extSubjKeyIdSrc = &input[idx];
cert->extSubjKeyIdSz = (word32)length;
#endif /* OPENSSL_EXTRA */

/* Get the hash or hash of the hash if wrong size. */
Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ static int InitSha256(wc_Sha256* sha256)
SHA256_SSE2, SHA256_C };

#ifndef WC_C_DYNAMIC_FALLBACK
/* note that all write access to this static variable must be idempotent,
* as arranged by Sha256_SetTransform(), else it will be susceptible to
* data races.
*/
static enum sha_methods sha_method = SHA256_UNSET;
#endif

Expand Down
4 changes: 4 additions & 0 deletions wolfcrypt/src/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ static int InitSha512_256(wc_Sha512* sha512)
SHA512_AVX1_RORX, SHA512_AVX2_RORX, SHA512_C };

#ifndef WC_C_DYNAMIC_FALLBACK
/* note that all write access to this static variable must be idempotent,
* as arranged by Sha512_SetTransform(), else it will be susceptible to
* data races.
*/
static enum sha_methods sha_method = SHA512_UNSET;
#endif

Expand Down
8 changes: 0 additions & 8 deletions wolfcrypt/src/wc_kyber.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,7 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
sword16* epp = NULL;
unsigned int kp = 0;
unsigned int compVecSz = 0;
#ifndef USE_INTEL_SPEEDUP
sword16* at = NULL;
#else
sword16 at[((KYBER_MAX_K + 3) * KYBER_MAX_K + 3) * KYBER_N];
#endif

/* Establish parameters based on key type. */
switch (key->type) {
Expand Down Expand Up @@ -409,7 +405,6 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
break;
}

#ifndef USE_INTEL_SPEEDUP
if (ret == 0) {
/* Allocate dynamic memory for all matrices, vectors and polynomials. */
at = (sword16*)XMALLOC(((kp + 3) * kp + 3) * KYBER_N * sizeof(sword16),
Expand All @@ -418,7 +413,6 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
ret = MEMORY_E;
}
}
#endif

if (ret == 0) {
/* Assign allocated dynamic memory to pointers.
Expand Down Expand Up @@ -472,10 +466,8 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
#endif
}

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

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions wolfssl/wolfcrypt/asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,9 @@ struct DecodedCert {
const byte* extCrlInfo; /* CRL Distribution Points */
int extCrlInfoSz; /* length of the URI */
byte extSubjKeyId[KEYID_SIZE]; /* Subject Key ID */
word32 extSubjKeyIdSz;
byte extAuthKeyId[KEYID_SIZE]; /* Authority Key ID */
word32 extAuthKeyIdSz;
#ifdef WOLFSSL_AKID_NAME
const byte* extAuthKeyIdIssuer; /* Authority Key ID authorityCertIssuer */
word32 extAuthKeyIdIssuerSz; /* Authority Key ID authorityCertIssuer length */
Expand All @@ -1751,9 +1753,7 @@ struct DecodedCert {
word32 extRawAuthKeyIdSz;
#endif
const byte* extAuthKeyIdSrc;
word32 extAuthKeyIdSz;
const byte* extSubjKeyIdSrc;
word32 extSubjKeyIdSz;
#endif
#ifdef OPENSSL_ALL
const byte* extSubjAltNameSrc;
Expand Down

0 comments on commit ccd8b9a

Please sign in to comment.