From 65db4b15d64c25e488c39c042bbefbb2e734dc3e Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Mon, 9 Sep 2024 16:05:15 +0200 Subject: [PATCH 1/6] api type conversion errors, first half of tls* files --- src/tls.c | 14 +++++++------- src/tls13.c | 36 ++++++++++++++++++------------------ tests/api.c | 26 +++++++++++++------------- tests/unit.h | 4 +++- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/tls.c b/src/tls.c index f61a6e25e8..fd69a1d576 100644 --- a/src/tls.c +++ b/src/tls.c @@ -999,12 +999,12 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, /* Number of blocks to create for hash. */ lenBlock = (realLen + extraLen) >> blockBits; /* Block containing EOC byte. */ - eocBlock = realLen >> blockBits; + eocBlock = (int)(realLen >> (word32)blockBits); /* Index of EOC byte in block. */ - eocIndex = realLen & blockMask; + eocIndex = (int)(realLen & (word32)blockMask); /* Add length of hmac's ipad to total length. */ - realLen += blockSz; + realLen += (word32)blockSz; /* Length as bits - 8 bytes bigendian. */ c32toa(realLen >> ((sizeof(word32) * 8) - 3), lenBytes); c32toa(realLen << 3, lenBytes + sizeof(word32)); @@ -1019,8 +1019,8 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, ret = Hmac_HashUpdate(hmac, header, WOLFSSL_TLS_HMAC_INNER_SZ); if (ret != 0) return ret; - ret = Hmac_HashUpdate(hmac, in, safeBlocks * blockSz - - WOLFSSL_TLS_HMAC_INNER_SZ); + ret = Hmac_HashUpdate(hmac, in, (word32)(safeBlocks * blockSz - + WOLFSSL_TLS_HMAC_INNER_SZ)); if (ret != 0) return ret; } @@ -1278,7 +1278,7 @@ int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int padSz, #endif { ret = Hmac_UpdateFinal_CT(&hmac, digest, in, - sz + hashSz + padSz + 1, hashSz, myInner); + (sz + hashSz + (word32)padSz + 1), (int)hashSz, myInner); } #else ret = Hmac_UpdateFinal(&hmac, digest, in, sz + hashSz + padSz + 1, @@ -7663,7 +7663,7 @@ static int TLSX_KeyShare_GenEccKey(WOLFSSL *ssl, KeyShareEntry* kse) #endif { /* set curve info for EccMakeKey "peer" info */ - ret = wc_ecc_set_curve(eccKey, kse->keyLen, curveId); + ret = wc_ecc_set_curve(eccKey, (int)kse->keyLen, curveId); if (ret == 0) { #ifdef WOLFSSL_ASYNC_CRYPT /* Detect when private key generation is done */ diff --git a/src/tls13.c b/src/tls13.c index bbca4fac57..93e566a880 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -7014,7 +7014,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, if (ret != 0) goto exit_dch; #else - if ((ret = HashInput(ssl, input + args->begin, helloSz)) != 0) + if ((ret = HashInput(ssl, input + args->begin, (int)helloSz)) != 0) goto exit_dch; #endif @@ -7458,7 +7458,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType) } #endif /* WOLFSSL_DTLS13 */ - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; if (!ssl->options.groupMessages || extMsgType != server_hello) ret = SendBuffered(ssl); @@ -7606,11 +7606,11 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl) /* This handshake message is always encrypted. */ sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ, - idx - RECORD_HEADER_SZ, handshake, 1, 0, 0); + (int)(idx - RECORD_HEADER_SZ), handshake, 1, 0, 0); if (sendSz < 0) return sendSz; - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; ssl->options.buildingMsg = 0; ssl->options.serverState = SERVER_ENCRYPTED_EXTENSIONS_COMPLETE; @@ -7636,7 +7636,7 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl) * returns 0 on success, otherwise failure. */ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx, - int reqCtxLen) + word32 reqCtxLen) { byte* output; int ret; @@ -7724,7 +7724,7 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx, /* Always encrypted. */ sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ, - i - RECORD_HEADER_SZ, handshake, 1, 0, 0); + (int)(i - RECORD_HEADER_SZ), handshake, 1, 0, 0); if (sendSz < 0) return sendSz; @@ -7739,7 +7739,7 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx, } #endif - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; ssl->options.buildingMsg = 0; if (!ssl->options.groupMessages) ret = SendBuffered(ssl); @@ -8510,7 +8510,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) certSz = 0; certChainSz = 0; headerSz = OPAQUE8_LEN + certReqCtxLen + CERT_HEADER_SZ; - length = headerSz; + length = (sword32)headerSz; listSz = 0; } else { @@ -8542,7 +8542,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) } /* Length of message data with one certificate and extensions. */ - length = headerSz + certSz + extSz; + length = (sword32)(headerSz + certSz + extSz); /* Length of list data with one certificate and extensions. */ listSz = CERT_HEADER_SZ + certSz + extSz; @@ -8551,7 +8551,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) p = ssl->buffers.certChain->buffer; /* Chain length including extensions. */ certChainSz = ssl->buffers.certChain->length + - OPAQUE16_LEN * ssl->buffers.certChainCnt; + OPAQUE16_LEN * (word32)ssl->buffers.certChainCnt; length += certChainSz; listSz += certChainSz; } @@ -8559,7 +8559,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) certChainSz = 0; } - payloadSz = length; + payloadSz = (word32)length; if (ssl->fragOffset != 0) length -= (ssl->fragOffset + headerSz); @@ -8703,7 +8703,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) { /* This message is always encrypted. */ sendSz = BuildTls13Message(ssl, output, sendSz, - output + RECORD_HEADER_SZ, i - RECORD_HEADER_SZ, handshake, 1, + output + RECORD_HEADER_SZ, (int)(i - RECORD_HEADER_SZ), handshake, 1, 0, 0); if (sendSz < 0) return sendSz; @@ -8719,7 +8719,7 @@ static int SendTls13Certificate(WOLFSSL* ssl) } #endif - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; ssl->options.buildingMsg = 0; if (!ssl->options.groupMessages) ret = SendBuffered(ssl); @@ -9150,7 +9150,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) #endif /* !NO_RSA */ #ifdef HAVE_ECC if (ssl->hsType == DYNAMIC_TYPE_ECC) { - args->sigLen = args->sendSz - args->idx - HASH_SIG_SIZE - + args->sigLen = (word32)args->sendSz - args->idx - HASH_SIG_SIZE - VERIFY_HEADER; #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) if (ssl->buffers.keyType != sm2_sa_algo) @@ -9555,7 +9555,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) } #endif - ssl->buffers.outputBuffer.length += args->sendSz; + ssl->buffers.outputBuffer.length += (word32)args->sendSz; ssl->options.buildingMsg = 0; if (!ssl->options.groupMessages) ret = SendBuffered(ssl); @@ -10846,7 +10846,7 @@ static int SendTls13Finished(WOLFSSL* ssl) input = output + Dtls13GetRlHeaderLength(ssl, 1); #endif /* WOLFSSL_DTLS13 */ - AddTls13HandShakeHeader(input, (word32)finishedSz, 0, finishedSz, finished, ssl); + AddTls13HandShakeHeader(input, (word32)finishedSz, 0, (word32)finishedSz, finished, ssl); #if defined(WOLFSSL_RENESAS_TSIP_TLS) if (ssl->options.side == WOLFSSL_CLIENT_END) { @@ -10931,7 +10931,7 @@ static int SendTls13Finished(WOLFSSL* ssl) } #endif - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; ssl->options.buildingMsg = 0; } @@ -11140,7 +11140,7 @@ static int SendTls13KeyUpdate(WOLFSSL* ssl) } #endif - ssl->buffers.outputBuffer.length += sendSz; + ssl->buffers.outputBuffer.length += (word32)sendSz; ret = SendBuffered(ssl); diff --git a/tests/api.c b/tests/api.c index 5b4be95e73..c24fb339b4 100644 --- a/tests/api.c +++ b/tests/api.c @@ -18620,7 +18620,7 @@ static int test_wc_Chacha_Process(void) ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen), 0); ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0); - ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0); + ExpectIntEQ(XMEMCMP(input, plain, inlen), 0); #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM) /* test checking and using leftovers, currently just in C code */ @@ -18635,7 +18635,7 @@ static int test_wc_Chacha_Process(void) (word32)inlen - 2), 0); ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2), (byte*)input + (inlen - 2), 2), 0); - ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0); + ExpectIntEQ(XMEMCMP(input, plain, inlen), 0); /* check edge cases with counter increment */ { @@ -20142,8 +20142,8 @@ static int test_wc_RsaPublicKeyDecodeRaw(void) RsaKey key; const byte n = 0x23; const byte e = 0x03; - int nSz = sizeof(n); - int eSz = sizeof(e); + word32 nSz = sizeof(n); + word32 eSz = sizeof(e); ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0); ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0); @@ -50065,7 +50065,7 @@ static int test_wc_PemToDer(void) ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0); key_buf[0] = '\n'; ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz)); - ExpectIntNE((ret = wc_PemToDer(key_buf, cert_sz + 1, CERT_TYPE, + ExpectIntNE((ret = wc_PemToDer(key_buf, (long int)cert_sz + 1, CERT_TYPE, &pDer, NULL, &info, &eccKey)), 0); #ifdef OPENSSL_EXTRA @@ -70516,7 +70516,7 @@ static int test_wc_ParseCert_Error(void) /* Test data */ const struct testStruct { const byte* c; - const int cSz; + word32 cSz; const int expRet; } t[] = { {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */ @@ -76326,7 +76326,7 @@ static int test_ForceZero(void) for (i = 0; i < sizeof(data); i++) { for (len = 1; len < sizeof(data) - i; len++) { for (j = 0; j < sizeof(data); j++) - data[j] = j + 1; + data[j] = ((unsigned char)j + 1); ForceZero(data + i, len); @@ -81896,7 +81896,7 @@ static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) { fprintf(stderr, "loading cert %s failed\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string(ret)); + wolfSSL_ERR_reason_error_string((unsigned long)ret)); return -1; } @@ -81910,7 +81910,7 @@ static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) != WOLFSSL_SUCCESS) { fprintf(stderr, "could not verify the cert: %s\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string(ret)); + wolfSSL_ERR_reason_error_string((unsigned long)ret)); return -1; } else { @@ -83223,7 +83223,7 @@ static int error_test(void) break; } } - errStr = wolfSSL_ERR_reason_error_string(i); + errStr = wolfSSL_ERR_reason_error_string((unsigned long)i); if (! this_missing) { ExpectIntNE(XSTRCMP(errStr, unknownStr), 0); @@ -83271,10 +83271,10 @@ static int test_wolfSSL_ERR_strings(void) ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD)); ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0); #else - ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE))); + ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE((unsigned long)UNSUPPORTED_SUITE))); ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0); - ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE))); + ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE((unsigned long)UNSUPPORTED_SUITE))); ExpectIntEQ((*err == '\0'), 1); /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */ @@ -87239,7 +87239,7 @@ static int test_short_session_id_ssl_ready(WOLFSSL* ssl) EXPECT_DECLS; WOLFSSL_SESSION *sess = NULL; /* Setup the session to avoid errors */ - ssl->session->timeout = -1; + ssl->session->timeout = (word32)-1; ssl->session->side = WOLFSSL_CLIENT_END; #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \ defined(HAVE_SESSION_TICKET)) diff --git a/tests/unit.h b/tests/unit.h index f63c4bd636..6184580965 100644 --- a/tests/unit.h +++ b/tests/unit.h @@ -215,7 +215,9 @@ const byte* _x = (const byte*)(x); \ const byte* _y = (const byte*)(y); \ int _z = (int)(z); \ - int _w = ((_x) && (_y)) ? XMEMCMP(_x, _y, _z) : -1; \ + int _w = ((_x) && (_y)) + ? XMEMCMP(_x, _y, (unsigned long)_z) + : -1; Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \ ("\"%p\" " #er " \"%p\" for \"%d\"", \ (const void *)_x, (const void *)_y, _z)); \ From 79d3b955ed6d2f9e82cddcff0fb255d06e4f1a23 Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Tue, 10 Sep 2024 13:51:21 +0200 Subject: [PATCH 2/6] tls.c type conversion fixed. --- src/tls.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/tls.c b/src/tls.c index 08ae784a04..0bcb631d37 100644 --- a/src/tls.c +++ b/src/tls.c @@ -929,7 +929,7 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, int blockBits, blockMask; int lastBlockLen, extraLen, eocIndex; int blocks, safeBlocks, lenBlock, eocBlock; - unsigned int maxLen; + word32 maxLen; int blockSz, padSz; int ret; word32 realLen; @@ -982,22 +982,22 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, blockMask = blockSz - 1; /* Size of data to HMAC if padding length byte is zero. */ - maxLen = WOLFSSL_TLS_HMAC_INNER_SZ + sz - 1 - macLen; + maxLen = WOLFSSL_TLS_HMAC_INNER_SZ + sz - 1 - (word32)macLen; /* Complete data (including padding) has block for EOC and/or length. */ - extraBlock = ctSetLTE((maxLen + padSz) & blockMask, padSz); + extraBlock = ctSetLTE(((int)maxLen + padSz) & blockMask, padSz); /* Total number of blocks for data including padding. */ - blocks = ((maxLen + blockSz - 1) >> blockBits) + extraBlock; + blocks = ((int)(maxLen + (word32)blockSz - 1) >> blockBits) + extraBlock; /* Up to last 6 blocks can be hashed safely. */ safeBlocks = blocks - 6; /* Length of message data. */ realLen = maxLen - in[sz - 1]; /* Number of message bytes in last block. */ - lastBlockLen = realLen & blockMask; + lastBlockLen = (int)realLen & blockMask; /* Number of padding bytes in last block. */ extraLen = ((blockSz * 2 - padSz - lastBlockLen) & blockMask) + 1; /* Number of blocks to create for hash. */ - lenBlock = (realLen + extraLen) >> blockBits; + lenBlock = ((int)realLen + extraLen) >> blockBits; /* Block containing EOC byte. */ eocBlock = (int)(realLen >> (word32)blockBits); /* Index of EOC byte in block. */ @@ -12505,7 +12505,7 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType, continue; /* skip! */ /* ssl level extensions are expected to override ctx level ones. */ - if (!IS_OFF(semaphore, TLSX_ToSemaphore(extension->type))) + if (!IS_OFF(semaphore, TLSX_ToSemaphore((word16)extension->type))) continue; /* skip! */ /* extension type + extension data length. */ @@ -12670,7 +12670,7 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType, /* marks the extension as processed so ctx level */ /* extensions don't overlap with ssl level ones. */ - TURN_ON(semaphore, TLSX_ToSemaphore(extension->type)); + TURN_ON(semaphore, TLSX_ToSemaphore((word16)extension->type)); } *pLength += length; @@ -12697,11 +12697,11 @@ static int TLSX_Write(TLSX* list, byte* output, byte* semaphore, continue; /* skip! */ /* ssl level extensions are expected to override ctx level ones. */ - if (!IS_OFF(semaphore, TLSX_ToSemaphore(extension->type))) + if (!IS_OFF(semaphore, TLSX_ToSemaphore((word16)extension->type))) continue; /* skip! */ /* writes extension type. */ - c16toa(extension->type, output + offset); + c16toa((word16)extension->type, output + offset); offset += HELLO_EXT_TYPE_SZ + OPAQUE16_LEN; length_offset = offset; @@ -12919,7 +12919,7 @@ static int TLSX_Write(TLSX* list, byte* output, byte* semaphore, /* marks the extension as processed so ctx level */ /* extensions don't overlap with ssl level ones. */ - TURN_ON(semaphore, TLSX_ToSemaphore(extension->type)); + TURN_ON(semaphore, TLSX_ToSemaphore((word16)extension->type)); /* if we encountered an error propagate it */ if (ret != 0) From be88ddda1599b326302c66e5acfa1296d8ca81e3 Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Wed, 18 Sep 2024 16:53:39 +0200 Subject: [PATCH 3/6] more Wconversion fixes: api/test* block --- tests/api.c | 62 +++++++++++++------------ tests/unit.h | 4 +- wolfcrypt/test/test.c | 105 ++++++++++++++++++++++-------------------- 3 files changed, 89 insertions(+), 82 deletions(-) diff --git a/tests/api.c b/tests/api.c index 28a7676744..499bec645f 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2431,7 +2431,7 @@ static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz, return -1; } - ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, cert_sz, file_type); + ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, (sword32)cert_sz, file_type); wolfSSL_CertManagerFree(cm); @@ -2470,7 +2470,8 @@ static int test_cm_load_ca_file(const char* ca_cert_file) #if defined(WOLFSSL_PEM_TO_DER) if (ret == WOLFSSL_SUCCESS) { /* test loading DER */ - ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL); + ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer, + NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length, WOLFSSL_FILETYPE_ASN1); @@ -2498,7 +2499,7 @@ static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz, return -1; } - ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, cert_sz, file_type, + ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, (sword32)cert_sz, file_type, 0, flags); wolfSSL_CertManagerFree(cm); @@ -2539,7 +2540,8 @@ static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags) #if defined(WOLFSSL_PEM_TO_DER) if (ret == WOLFSSL_SUCCESS) { /* test loading DER */ - ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL); + ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer, + NULL, NULL, NULL); if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length, WOLFSSL_FILETYPE_ASN1, flags); @@ -4808,13 +4810,13 @@ static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void) WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); - ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (long)len), + ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (sword32)len), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); - ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (long)len), + ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (sword32)len), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, @@ -4822,14 +4824,14 @@ static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void) WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf, - (long)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); + (sword32)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS); - ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (long)len), + ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (sword32)len), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); - ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (long)len), + ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (sword32)len), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER)); @@ -7272,7 +7274,7 @@ static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds, err != WOLFSSL_ERROR_WANT_WRITE) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); failing_c = 1; hs_c = 1; if (failing_c && failing_s) { @@ -7294,7 +7296,7 @@ static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds, err != WOLFSSL_ERROR_WANT_WRITE) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); failing_s = 1; hs_s = 1; if (failing_c && failing_s) { @@ -7804,7 +7806,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args) if (ret != WOLFSSL_SUCCESS) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); /*err_sys("SSL_accept failed");*/ goto done; } @@ -8252,7 +8254,7 @@ static int test_client_nofail(void* args, cbType cb) if (ret != WOLFSSL_SUCCESS) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); /*err_sys("SSL_connect failed");*/ goto done; } @@ -8262,7 +8264,7 @@ static int test_client_nofail(void* args, cbType cb) cipherSuite = wolfSSL_get_current_cipher_suite(ssl); cipherName1 = wolfSSL_get_cipher_name(ssl); cipherName2 = wolfSSL_get_cipher_name_from_suite( - (cipherSuite >> 8), cipherSuite & 0xFF); + (byte)(cipherSuite >> 8), cipherSuite & 0xFF); AssertStrEQ(cipherName1, cipherName2); /* IANA Cipher Suites Names */ @@ -8275,7 +8277,7 @@ static int test_client_nofail(void* args, cbType cb) #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \ !defined(WOLFSSL_QT) cipherName1 = wolfSSL_get_cipher_name_iana_from_suite( - (cipherSuite >> 8), cipherSuite & 0xFF); + (byte)(cipherSuite >> 8), cipherSuite & 0xFF); AssertStrEQ(cipherName1, cipherName2); #endif @@ -8822,7 +8824,7 @@ static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args) if (ret != WOLFSSL_SUCCESS) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "accept error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); /*err_sys("SSL_accept failed");*/ } else { @@ -9040,7 +9042,7 @@ static void run_wolfssl_client(void* args) if (ret != WOLFSSL_SUCCESS) { char buff[WOLFSSL_MAX_ERROR_SZ]; fprintf(stderr, "error = %d, %s\n", err, - wolfSSL_ERR_error_string(err, buff)); + wolfSSL_ERR_error_string((word32)err, buff)); /*err_sys("SSL_connect failed");*/ } else { @@ -11109,8 +11111,8 @@ static int test_wolfSSL_UseSNI_params(void) ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3)); ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3)); /* invalid type */ - ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, -1, "ctx", 3)); - ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, -1, "ssl", 3)); + ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, (byte)-1, "ctx", 3)); + ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, (byte)-1, "ssl", 3)); /* invalid data */ ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3)); ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3)); @@ -12411,7 +12413,7 @@ static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx) XMEMCPY(buf, msg->buffer, len); /* Move over returned data. */ msg->buffer += len; - msg->length -= len; + msg->length -= (word32)len; /* Amount actually copied. */ return len; @@ -18682,7 +18684,7 @@ static int test_wc_Chacha_Process(void) int i; for (i = 0; i < 256; i++) - input2[i] = i; + input2[i] = (byte)i; ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0); @@ -64229,7 +64231,7 @@ static int test_wolfSSL_MD4(void) XMEMSET(out, 0, sizeof(out)); MD4_Init(&md4); - MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz); + MD4_Update(&md4, (const void*)msg, (word32)msgSz); MD4_Final(out, &md4); ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0); #endif @@ -72786,7 +72788,7 @@ static int test_wolfSSL_OBJ_sn(void) } #if !defined(NO_BIO) -static unsigned long TXT_DB_hash(const WOLFSSL_STRING *s) +static word32 TXT_DB_hash(const WOLFSSL_STRING *s) { return lh_strhash(s[3]); } @@ -86303,7 +86305,7 @@ static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) { fprintf(stderr, "loading cert %s failed\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((unsigned long)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; } @@ -86317,7 +86319,7 @@ static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA) != WOLFSSL_SUCCESS) { fprintf(stderr, "could not verify the cert: %s\n", certA); fprintf(stderr, "Error: (%d): %s\n", ret, - wolfSSL_ERR_reason_error_string((unsigned long)ret)); + wolfSSL_ERR_reason_error_string((word32)ret)); return -1; } else { @@ -86596,7 +86598,7 @@ static int test_wolfSSL_THREADID_hash(void) CRYPTO_THREADID id; CRYPTO_THREADID_current(NULL); - /* Hash result is unsigned long. */ + /* Hash result is word32. */ ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL); XMEMSET(&id, 0, sizeof(id)); ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL); @@ -87630,7 +87632,7 @@ static int error_test(void) break; } } - errStr = wolfSSL_ERR_reason_error_string((unsigned long)i); + errStr = wolfSSL_ERR_reason_error_string((word32)i); if (! this_missing) { ExpectIntNE(XSTRCMP(errStr, unknownStr), 0); @@ -87678,10 +87680,10 @@ static int test_wolfSSL_ERR_strings(void) ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD)); ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0); #else - ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE((unsigned long)UNSUPPORTED_SUITE))); + ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE))); ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0); - ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE((unsigned long)UNSUPPORTED_SUITE))); + ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE))); ExpectIntEQ((*err == '\0'), 1); /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */ @@ -93858,7 +93860,7 @@ static int test_tls_multi_handshakes_one_record(void) } rh = (RecordLayerHeader*)(test_ctx.c_buff); len = &rh->length[0]; - c16toa(newRecIdx - RECORD_HEADER_SZ, len); + c16toa((word16)newRecIdx - RECORD_HEADER_SZ, len); test_ctx.c_len = newRecIdx; ExpectIntEQ(wolfSSL_connect(ssl_c), -1); diff --git a/tests/unit.h b/tests/unit.h index 6184580965..c138cd280c 100644 --- a/tests/unit.h +++ b/tests/unit.h @@ -215,9 +215,7 @@ const byte* _x = (const byte*)(x); \ const byte* _y = (const byte*)(y); \ int _z = (int)(z); \ - int _w = ((_x) && (_y)) - ? XMEMCMP(_x, _y, (unsigned long)_z) - : -1; + int _w = ((_x) && (_y)) ? XMEMCMP(_x, _y, (unsigned long)_z) : -1; \ Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \ ("\"%p\" " #er " \"%p\" for \"%d\"", \ (const void *)_x, (const void *)_y, _z)); \ diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 90cb4ce89a..7a35d56a1e 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -4092,7 +4092,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void) /* Unaligned memory access test */ for (i = 1; i < 16; i++) { ret = wc_Sha512Update(&sha, (byte*)large_input + i, - LARGE_HASH_TEST_INPUT_SZ - i); + LARGE_HASH_TEST_INPUT_SZ - (word32)i); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Sha512Final(&sha, hash); @@ -4250,7 +4250,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void) /* Unaligned memory access test */ for (i = 1; i < 16; i++) { ret = wc_Sha512_224Update(&sha, (byte*)large_input + i, - (word32)sizeof(large_input) - i); + (word32)sizeof(large_input) - (word32)i); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Sha512_224Final(&sha, hash); @@ -4403,7 +4403,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void) /* Unaligned memory access test */ for (i = 1; i < 16; i++) { ret = wc_Sha512_256Update(&sha, (byte*)large_input + i, - (word32)sizeof(large_input) - i); + (word32)sizeof(large_input) - (word32)i); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Sha512_256Final(&sha, hash); @@ -5985,14 +5985,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void) return WC_TEST_RET_ENC_I(i); if (exp_ret == 0) { ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, - digestSz - 1); + (word32)digestSz - 1); if (ret != WC_NO_ERR_TRACE(BUFFER_E)) return WC_TEST_RET_ENC_I(i); } ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz); if (ret != exp_ret) return WC_TEST_RET_ENC_I(i); - if (exp_ret == 0 && XMEMCMP(out, hashOut, digestSz) != 0) + if (exp_ret == 0 && XMEMCMP(out, hashOut, (word32)digestSz) != 0) return WC_TEST_RET_ENC_I(i); ret = wc_HashGetBlockSize(typesGood[i]); @@ -7790,10 +7790,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void) if (ret != 0) return ret; - if (XMEMCMP(plain_big, input_big, block_size)) + if (XMEMCMP(plain_big, input_big, (word32)block_size)) return WC_TEST_RET_ENC_I(i); - if (XMEMCMP(cipher_big, cipher_big_result, block_size)) + if (XMEMCMP(cipher_big, cipher_big_result, (word32)block_size)) return WC_TEST_RET_ENC_I(i); } @@ -14464,18 +14464,18 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, ivSz, - resultT, (word32)tagSz, aad, aadSz); + ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz, + resultT, (word32)tagSz, aad, (word32)aadSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (cipher != NULL) { - if (XMEMCMP(cipher, resultC, cipherSz)) + if (XMEMCMP(cipher, resultC, (word32)cipherSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); } - if (XMEMCMP(tag, resultT, tagSz)) + if (XMEMCMP(tag, resultT, (unsigned long)tagSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK) @@ -14489,7 +14489,7 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (cipher != NULL) { - if (XMEMCMP(cipher, resultC, cipherSz)) + if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); } if (XMEMCMP(tag, resultT, tagSz)) @@ -14502,14 +14502,14 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz, - iv, (word32)ivSz, resultT, tagSz, aad, aadSz); + iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (plain != NULL) { - if (XMEMCMP(plain, resultP, plainSz)) + if (XMEMCMP(plain, resultP, (unsigned long)plainSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); } @@ -14524,7 +14524,7 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (plain != NULL) { - if (XMEMCMP(plain, resultP, plainSz)) + if (XMEMCMP(plain, resultP, (unsigned long)plainSz)) ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif @@ -17719,7 +17719,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void) #endif #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC) -static int simple_mem_test(int sz) +static int simple_mem_test(size_t sz) { int ret = 0; byte* b; @@ -17730,11 +17730,11 @@ static int simple_mem_test(int sz) return WC_TEST_RET_ENC_NC; } /* utilize memory */ - for (i = 0; i < sz; i++) { + for (i = 0; i < (int)sz; i++) { b[i] = (byte)i; } /* read back and verify */ - for (i = 0; i < sz; i++) { + for (i = 0; i < (int)sz; i++) { if (b[i] != (byte)i) { ret = WC_TEST_RET_ENC_NC; break; @@ -17894,7 +17894,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC) /* simple test */ - ret = simple_mem_test(MEM_TEST_SZ); + ret = simple_mem_test((size_t)MEM_TEST_SZ); if (ret != 0) return ret; #endif @@ -17902,7 +17902,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) #ifdef COMPLEX_MEM_TEST /* test various size blocks */ for (i = 1; i < MEM_TEST_SZ; i*=2) { - ret = simple_mem_test(i); + ret = simple_mem_test((size_t)i); if (ret != 0) return ret; } @@ -19800,7 +19800,7 @@ static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key) #endif if (ret >= 0) { ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0], - mgf[0], digestSz + 1, key, rng); + mgf[0], (int)digestSz + 1, key, rng); } } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E)); if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E)) @@ -19828,7 +19828,7 @@ static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key) #endif if (ret >= 0) { ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0], - digestSz + 1, key); + (int)digestSz + 1, key); } } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E)); if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E)) @@ -26470,7 +26470,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void) if (ret < 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(derived, verify, kLen) != 0) + if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0) return WC_TEST_RET_ENC_NC; iterations = 1000; @@ -26755,7 +26755,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(okm1, res1, L) != 0) + if (XMEMCMP(okm1, res1, (unsigned long)L) != 0) return WC_TEST_RET_ENC_NC; #ifndef HAVE_FIPS @@ -26766,7 +26766,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(okm1, res2, L) != 0) + if (XMEMCMP(okm1, res2, (unsigned long)L) != 0) return WC_TEST_RET_ENC_NC; #endif /* HAVE_FIPS */ #endif /* !NO_SHA */ @@ -26777,7 +26777,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(okm1, res3, L) != 0) + if (XMEMCMP(okm1, res3, (unsigned long)L) != 0) return WC_TEST_RET_ENC_NC; #ifndef HAVE_FIPS @@ -26787,7 +26787,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void) if (ret != 0) return WC_TEST_RET_ENC_EC(ret); - if (XMEMCMP(okm1, res4, L) != 0) + if (XMEMCMP(okm1, res4, (unsigned long)L) != 0) return WC_TEST_RET_ENC_NC; #endif /* HAVE_FIPS */ #endif /* !NO_SHA256 */ @@ -26994,7 +26994,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void) int lblsdL = LBSL; int hash_type = sha384_mac; - ret = wc_PRF(dig, (word32)digL, secret, secL, lablSd, lblsdL, hash_type, + ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd, + (word32)lblsdL, hash_type, HEAP_HINT, INVALID_DEVID); if (ret != 0) { printf("Failed w/ code: %d\n", ret); @@ -27645,111 +27646,117 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void) ret = wc_Tls13_HKDF_Extract(secret, NULL, 0, (tv->pskSz == 0) ? zeroes : (byte*)tv->psk, - tv->pskSz, tv->hashAlg); + tv->pskSz, (int)tv->hashAlg); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel), - tv->hashHello1, (word32)hashAlgSz, tv->hashAlg); + tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->clientEarlyTrafficSecret, output, hashAlgSz); + ret = XMEMCMP(tv->clientEarlyTrafficSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel), - tv->hashHello1, (word32)hashAlgSz, tv->hashAlg); + tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->earlyExporterMasterSecret, output, hashAlgSz); + ret = XMEMCMP(tv->earlyExporterMasterSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel), - hashZero, (word32)hashAlgSz, tv->hashAlg); + hashZero, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz, (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe, - tv->dheSz, tv->hashAlg); + tv->dheSz, (int)tv->hashAlg); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel), - tv->hashHello2, (word32)hashAlgSz, tv->hashAlg); + tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; ret = XMEMCMP(tv->clientHandshakeTrafficSecret, - output, hashAlgSz); + output, (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel), - tv->hashHello2, (word32)hashAlgSz, tv->hashAlg); + tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output, hashAlgSz); + ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel), - hashZero, (word32)hashAlgSz, tv->hashAlg); + hashZero, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz, - zeroes, (word32)(word32)hashAlgSz, tv->hashAlg); + zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel), - tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg); + tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->clientApplicationTrafficSecret, output, hashAlgSz); + ret = XMEMCMP(tv->clientApplicationTrafficSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel), - tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg); + tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->serverApplicationTrafficSecret, output, hashAlgSz); + ret = XMEMCMP(tv->serverApplicationTrafficSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel), - tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg); + tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->exporterMasterSecret, output, hashAlgSz); + ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz); if (ret != 0) break; ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz, secret, (word32)hashAlgSz, (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel), - tv->hashFinished2, (word32)hashAlgSz, tv->hashAlg); + tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg); if (ret != 0) break; - ret = XMEMCMP(tv->resumptionMasterSecret, output, hashAlgSz); + ret = XMEMCMP(tv->resumptionMasterSecret, output, + (unsigned long)hashAlgSz); if (ret != 0) break; } From 3193ecb2c3537568433216d6b595295c667b3933 Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Tue, 1 Oct 2024 15:07:59 +0200 Subject: [PATCH 4/6] fixed Wconversion in the api.c file --- tests/api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 6d3cc40430..563f477af4 100644 --- a/tests/api.c +++ b/tests/api.c @@ -73076,7 +73076,7 @@ static int test_wolfSSL_OBJ_sn(void) #if !defined(NO_BIO) static word32 TXT_DB_hash(const WOLFSSL_STRING *s) { - return lh_strhash(s[3]); + return (word32)lh_strhash(s[3]); } static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b) @@ -73124,7 +73124,8 @@ static int test_wolfSSL_TXT_DB(void) BIO_free(bio); /* Test index */ - ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)TXT_DB_hash, + ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, + (wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash, (wolf_lh_compare_cb)TXT_DB_cmp), 1); ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields)); fields[3] = "12DA"; From 666e658398e4593e79dd8410f8acff15f53bcc51 Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Tue, 1 Oct 2024 16:28:31 +0200 Subject: [PATCH 5/6] trailing spaces and overlong lines fixes --- src/tls.c | 5 +++-- src/tls13.c | 12 ++++++++---- tests/api.c | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tls.c b/src/tls.c index 7774a85cb9..2cf9fee426 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1020,7 +1020,7 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, if (ret != 0) return ret; ret = Hmac_HashUpdate(hmac, in, (word32)(safeBlocks * blockSz - - WOLFSSL_TLS_HMAC_INNER_SZ)); + WOLFSSL_TLS_HMAC_INNER_SZ)); if (ret != 0) return ret; } @@ -1278,7 +1278,8 @@ int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int padSz, #endif { ret = Hmac_UpdateFinal_CT(&hmac, digest, in, - (sz + hashSz + (word32)padSz + 1), (int)hashSz, myInner); + (sz + hashSz + (word32)padSz + 1), + (int)hashSz, myInner); } #else ret = Hmac_UpdateFinal(&hmac, digest, in, sz + hashSz + padSz + 1, diff --git a/src/tls13.c b/src/tls13.c index 2c772ed59a..2b266d837a 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -7604,7 +7604,8 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl) /* This handshake message is always encrypted. */ sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ, - (int)(idx - RECORD_HEADER_SZ), handshake, 1, 0, 0); + (int)(idx - RECORD_HEADER_SZ), + handshake, 1, 0, 0); if (sendSz < 0) return sendSz; @@ -8701,7 +8702,8 @@ static int SendTls13Certificate(WOLFSSL* ssl) { /* This message is always encrypted. */ sendSz = BuildTls13Message(ssl, output, sendSz, - output + RECORD_HEADER_SZ, (int)(i - RECORD_HEADER_SZ), handshake, 1, + output + RECORD_HEADER_SZ, (int)(i - RECORD_HEADER_SZ), + handshake, 1, 0, 0); if (sendSz < 0) return sendSz; @@ -9152,7 +9154,8 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) #endif /* !NO_RSA */ #ifdef HAVE_ECC if (ssl->hsType == DYNAMIC_TYPE_ECC) { - args->sigLen = (word32)args->sendSz - args->idx - HASH_SIG_SIZE - + args->sigLen = (word32)args->sendSz - args->idx - + HASH_SIG_SIZE - VERIFY_HEADER; #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) if (ssl->buffers.keyType != sm2_sa_algo) @@ -10868,7 +10871,8 @@ static int SendTls13Finished(WOLFSSL* ssl) input = output + Dtls13GetRlHeaderLength(ssl, 1); #endif /* WOLFSSL_DTLS13 */ - AddTls13HandShakeHeader(input, (word32)finishedSz, 0, (word32)finishedSz, finished, ssl); + AddTls13HandShakeHeader(input, (word32)finishedSz, 0, (word32)finishedSz, + finished, ssl); #if defined(WOLFSSL_RENESAS_TSIP_TLS) if (ssl->options.side == WOLFSSL_CLIENT_END) { diff --git a/tests/api.c b/tests/api.c index 563f477af4..ddb2421920 100644 --- a/tests/api.c +++ b/tests/api.c @@ -73124,7 +73124,7 @@ static int test_wolfSSL_TXT_DB(void) BIO_free(bio); /* Test index */ - ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, + ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash, (wolf_lh_compare_cb)TXT_DB_cmp), 1); ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields)); From ea852c1c67863e6c44a896e23f9bcc60e67f7a0d Mon Sep 17 00:00:00 2001 From: Reda Chouk Date: Wed, 2 Oct 2024 17:21:50 +0200 Subject: [PATCH 6/6] missing argument --- src/tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tls.c b/src/tls.c index b4e723a291..4fc15e53cd 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1345,7 +1345,7 @@ int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int padSz, { ret = Hmac_UpdateFinal_CT(&hmac, digest, in, (sz + hashSz + (word32)padSz + 1), - (int)hashSz, myInner); + (int)hashSz, myInner, innerSz); } #else