Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wolfSSL/wolfssl into ED25…
Browse files Browse the repository at this point in the history
…519_SHA2_fix
  • Loading branch information
gojimmypi committed Oct 1, 2024
2 parents cdeb342 + 5927951 commit 5275eab
Show file tree
Hide file tree
Showing 36 changed files with 2,673 additions and 357 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ AC_ARG_WITH([liboqs],
tryliboqsdir="/usr/local"
fi
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBOQS -DHAVE_TLS_EXTENSIONS -I$tryliboqsdir/include"
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBOQS -DHAVE_TLS_EXTENSIONS -I$tryliboqsdir/include -pthread"
LDFLAGS="$AM_LDFLAGS $LDFLAGS -L$tryliboqsdir/lib"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <oqs/common.h>]], [[ OQS_init(); ]])], [ liboqs_linked=yes ],[ liboqs_linked=no ])
Expand Down
7 changes: 7 additions & 0 deletions examples/pem/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,13 @@ int main(int argc, char* argv[])
if (ret < 0) {
fprintf(stderr, "%s\n", wc_GetErrorString(ret));
}

if (in_file != stdin)
(void)fclose(in_file);

if (out_file != stdout)
(void)fclose(out_file);

return (ret == 0) ? 0 : 1;
}

Expand Down
18 changes: 7 additions & 11 deletions src/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-aes.c
endif BUILD_ARMASM
if BUILD_ARMASM_NEON
if !BUILD_ARMASM_CRYPTO
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm.S
endif !BUILD_ARMASM_INLINE
endif !BUILD_ARMASM_CRYPTO
else
if BUILD_ARMASM
if BUILD_ARMASM_INLINE
Expand Down Expand Up @@ -336,13 +334,11 @@ if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-aes.c
endif BUILD_ARMASM
if BUILD_ARMASM_NEON
if !BUILD_ARMASM_CRYPTO
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm.S
endif !BUILD_ARMASM_INLINE
endif !BUILD_ARMASM_CRYPTO
else
if BUILD_ARMASM
if BUILD_ARMASM_INLINE
Expand Down Expand Up @@ -701,15 +697,13 @@ if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-aes.c
endif BUILD_ARMASM
if BUILD_ARMASM_NEON
if !BUILD_ARMASM_CRYPTO
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-aes-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-aes-asm.S
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-aes-asm.S
endif !BUILD_ARMASM_INLINE
endif !BUILD_ARMASM_CRYPTO
else
if BUILD_ARMASM
if BUILD_ARMASM_INLINE
Expand Down Expand Up @@ -924,8 +918,10 @@ if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-poly1305.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305.c
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-poly1305-asm_c.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-poly1305-asm.S
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm.S
endif !BUILD_ARMASM_INLINE
endif
Expand Down Expand Up @@ -999,17 +995,17 @@ endif

if BUILD_CHACHA
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/chacha.c
if BUILD_ARMASM_NEON
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-chacha.c
else
if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-chacha.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-chacha.c
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-chacha-asm_c.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-chacha-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-32-chacha-asm.S
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-chacha-asm.S
endif !BUILD_ARMASM_INLINE
endif BUILD_ARMASM
else
if BUILD_RISCV_ASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-chacha.c
endif BUILD_RISCV_ASM
Expand All @@ -1018,7 +1014,7 @@ if BUILD_INTELASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/chacha_asm.S
endif BUILD_INTELASM
endif !BUILD_X86_ASM
endif !BUILD_ARMASM_NEON
endif !BUILD_ARMASM
if BUILD_POLY1305
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/chacha20_poly1305.c
endif BUILD_POLY1305
Expand Down
15 changes: 15 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -6829,7 +6829,22 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
ssl->buffers.certChainCnt = ctx->certChainCnt;
#endif
#ifndef WOLFSSL_BLIND_PRIVATE_KEY
#ifdef WOLFSSL_COPY_KEY
if (ctx->privateKey != NULL) {
if (ssl->buffers.key != NULL) {
FreeDer(&ssl->buffers.key);
}
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
ctx->privateKey->length, ctx->privateKey->type,
ctx->privateKey->heap);
ssl->buffers.weOwnKey = 1;
}
else {
ssl->buffers.key = ctx->privateKey;
}
#else
ssl->buffers.key = ctx->privateKey;
#endif
#else
if (ctx->privateKey != NULL) {
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
Expand Down
21 changes: 20 additions & 1 deletion src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20410,7 +20410,22 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
ssl->buffers.certChainCnt = ctx->certChainCnt;
#endif
#ifndef WOLFSSL_BLIND_PRIVATE_KEY
#ifdef WOLFSSL_COPY_KEY
if (ctx->privateKey != NULL) {
if (ssl->buffers.key != NULL) {
FreeDer(&ssl->buffers.key);
}
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
ctx->privateKey->length, ctx->privateKey->type,
ctx->privateKey->heap);
ssl->buffers.weOwnKey = 1;
}
else {
ssl->buffers.key = ctx->privateKey;
}
#else
ssl->buffers.key = ctx->privateKey;
#endif
#else
if (ctx->privateKey != NULL) {
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
Expand Down Expand Up @@ -23984,7 +23999,7 @@ int wolfSSL_RAND_seed(const void* seed, int len)
*/
const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
{
#if !defined(NO_FILESYSTEM) && defined(XGETENV)
#if !defined(NO_FILESYSTEM) && defined(XGETENV) && !defined(NO_GETENV)
char* rt;

WOLFSSL_ENTER("wolfSSL_RAND_file_name");
Expand All @@ -23995,6 +24010,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)

XMEMSET(fname, 0, len);

/* // NOLINTBEGIN(concurrency-mt-unsafe) */
if ((rt = XGETENV("RANDFILE")) != NULL) {
if (len > XSTRLEN(rt)) {
XMEMCPY(fname, rt, XSTRLEN(rt));
Expand All @@ -24004,13 +24020,15 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
rt = NULL;
}
}
/* // NOLINTEND(concurrency-mt-unsafe) */

/* $RANDFILE was not set or is too large, check $HOME */
if (rt == NULL) {
const char ap[] = "/.rnd";

WOLFSSL_MSG("Environment variable RANDFILE not set");

/* // NOLINTBEGIN(concurrency-mt-unsafe) */
if ((rt = XGETENV("HOME")) == NULL) {
#ifdef XALTHOMEVARNAME
if ((rt = XGETENV(XALTHOMEVARNAME)) == NULL) {
Expand All @@ -24023,6 +24041,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
return NULL;
#endif
}
/* // NOLINTEND(concurrency-mt-unsafe) */

if (len > XSTRLEN(rt) + XSTRLEN(ap)) {
fname[0] = '\0';
Expand Down
8 changes: 5 additions & 3 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -5099,7 +5099,7 @@ int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa)
int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
{
int ret;
#ifdef XGETENV
#if defined(XGETENV) && !defined(NO_GETENV)
char* certDir = NULL;
char* certFile = NULL;
word32 flags = 0;
Expand All @@ -5109,7 +5109,8 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)

WOLFSSL_ENTER("wolfSSL_CTX_set_default_verify_paths");

#ifdef XGETENV
#if defined(XGETENV) && !defined(NO_GETENV)
/* // NOLINTBEGIN(concurrency-mt-unsafe) */
certDir = wc_strdup_ex(XGETENV("SSL_CERT_DIR"), DYNAMIC_TYPE_TMP_BUFFER);
certFile = wc_strdup_ex(XGETENV("SSL_CERT_FILE"), DYNAMIC_TYPE_TMP_BUFFER);
flags = WOLFSSL_LOAD_FLAG_PEM_CA_ONLY;
Expand All @@ -5133,6 +5134,7 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
ret = 0;
}
}
/* // NOLINTEND(concurrency-mt-unsafe) */
else
#endif

Expand All @@ -5157,7 +5159,7 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx)
#endif
}

#ifdef XGETENV
#if defined(XGETENV) && !defined(NO_GETENV)
XFREE(certFile, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(certDir, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
Expand Down
13 changes: 11 additions & 2 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4759,7 +4759,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)

#ifdef WC_C_DYNAMIC_FALLBACK

#define VECTOR_REGISTERS_PUSH { \
#define VECTOR_REGISTERS_PUSH { \
int orig_use_aesni = aes->use_aesni; \
if (aes->use_aesni && (SAVE_VECTOR_REGISTERS2() != 0)) { \
aes->use_aesni = 0; \
Expand All @@ -4774,6 +4774,15 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
} \
WC_DO_NOTHING

#elif defined(SAVE_VECTOR_REGISTERS2_DOES_NOTHING)

#define VECTOR_REGISTERS_PUSH { \
WC_DO_NOTHING

#define VECTOR_REGISTERS_POP \
} \
WC_DO_NOTHING

#else

#define VECTOR_REGISTERS_PUSH { \
Expand Down Expand Up @@ -9796,7 +9805,7 @@ static WARN_UNUSED_RESULT int AesGcmDecryptUpdate_aesni(
ASSERT_SAVED_VECTOR_REGISTERS();

/* Hash in A, the Authentication Data */
ret = AesGcmAadUpdate_aesni(aes, a, aSz, (cSz > 0) && (c != NULL));
ret = AesGcmAadUpdate_aesni(aes, a, aSz, cSz > 0);
if (ret != 0)
return ret;

Expand Down
3 changes: 1 addition & 2 deletions wolfcrypt/src/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ Public domain.
#endif /* HAVE_CHACHA */


#if defined(WOLFSSL_ARMASM) && (!defined(WOLFSSL_ARMASM_NO_NEON) || \
defined(__thumb__))
#if defined(WOLFSSL_ARMASM)
/* implementation is located in wolfcrypt/src/port/arm/armv8-chacha.c */

#elif defined(WOLFSSL_RISCV_ASM)
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/dilithium.c
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ static int dilithium_check_hint(const byte* h, byte k, byte omega)
}
}
/* Ensure the last hint is less than the current hint. */
else if (h[i - 1] > h[i]) {
else if (h[i - 1] >= h[i]) {
ret = SIG_VERIFY_E;
break;
}
Expand Down Expand Up @@ -9654,7 +9654,7 @@ int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx,
ret = dilitihium_get_der_length(input, &idx, &length, inSz);
}
if (ret == 0) {
if (input[idx] != 0) {
if ((input[idx] != 0) || (length == 0)) {
ret = ASN_PARSE_E;
}
idx++;
Expand Down
46 changes: 46 additions & 0 deletions wolfcrypt/src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,52 @@ WC_MISC_STATIC WC_INLINE void ByteReverseWords(word32* out, const word32* in,

#if defined(WORD64_AVAILABLE) && !defined(WOLFSSL_NO_WORD64_OPS)

WC_MISC_STATIC WC_INLINE word64 readUnalignedWord64(const byte *in)
{
if (((wc_ptr_t)in & (wc_ptr_t)(sizeof(word64) - 1U)) == (wc_ptr_t)0)
return *(word64 *)in;
else {
word64 out;
XMEMCPY(&out, in, sizeof(word64));
return out;
}
}

WC_MISC_STATIC WC_INLINE word64 writeUnalignedWord64(void *out, word64 in)
{
if (((wc_ptr_t)out & (wc_ptr_t)(sizeof(word64) - 1U)) == (wc_ptr_t)0)
*(word64 *)out = in;
else {
XMEMCPY(out, &in, sizeof(word64));
}
return in;
}

WC_MISC_STATIC WC_INLINE void readUnalignedWords64(word64 *out, const byte *in,
size_t count)
{
if (((wc_ptr_t)in & (wc_ptr_t)(sizeof(word64) - 1U)) == (wc_ptr_t)0) {
const word64 *in_word64 = (const word64 *)in;
while (count-- > 0)
*out++ = *in_word64++;
}
else {
XMEMCPY(out, in, count * sizeof(word64));
}
}

WC_MISC_STATIC WC_INLINE void writeUnalignedWords64(byte *out, const word64 *in,
size_t count)
{
if (((wc_ptr_t)out & (wc_ptr_t)(sizeof(word64) - 1U)) == (wc_ptr_t)0) {
word64 *out_word64 = (word64 *)out;
while (count-- > 0)
*out_word64++ = *in++;
}
else {
XMEMCPY(out, in, count * sizeof(word64));
}
}

WC_MISC_STATIC WC_INLINE word64 rotlFixed64(word64 x, word64 y)
{
Expand Down
11 changes: 4 additions & 7 deletions wolfcrypt/src/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
}
#endif/* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
/* if not 64 bit then use 32 bit */
#elif !defined(WOLFSSL_ARMASM) || !defined(__thumb__)
#elif !defined(WOLFSSL_ARMASM)

static word32 U8TO32(const byte *p)
{
Expand Down Expand Up @@ -269,8 +269,7 @@ static WC_INLINE void u32tole64(const word32 inLe32, byte outLe64[8])
}


#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
!defined(__thumb__))) && !defined(WOLFSSL_RISCV_ASM)
#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_RISCV_ASM)
/*
This local function operates on a message with a given number of bytes
with a given ctx pointer to a Poly1305 structure.
Expand Down Expand Up @@ -789,8 +788,7 @@ int wc_Poly1305Final(Poly1305* ctx, byte* mac)

return 0;
}
#endif /* (!WOLFSSL_ARMASM || (!__aarch64__ && !__thumb__)) &&
* !WOLFSSL_RISCV_ASM */
#endif /* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */


int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
Expand Down Expand Up @@ -885,8 +883,7 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
/* process full blocks */
if (bytes >= POLY1305_BLOCK_SIZE) {
size_t want = ((size_t)bytes & ~((size_t)POLY1305_BLOCK_SIZE - 1));
#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
!defined(__thumb__))) && !defined(WOLFSSL_RISCV_ASM)
#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_RISCV_ASM)
int ret;
ret = poly1305_blocks(ctx, m, want);
if (ret != 0)
Expand Down
Loading

0 comments on commit 5275eab

Please sign in to comment.