api type conversion errors, first half of tls* files

pull/7988/head
Reda Chouk 2024-09-09 16:05:15 +02:00
parent 73786112ec
commit 65db4b15d6
4 changed files with 41 additions and 39 deletions

View File

@ -999,12 +999,12 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in,
/* Number of blocks to create for hash. */ /* Number of blocks to create for hash. */
lenBlock = (realLen + extraLen) >> blockBits; lenBlock = (realLen + extraLen) >> blockBits;
/* Block containing EOC byte. */ /* Block containing EOC byte. */
eocBlock = realLen >> blockBits; eocBlock = (int)(realLen >> (word32)blockBits);
/* Index of EOC byte in block. */ /* Index of EOC byte in block. */
eocIndex = realLen & blockMask; eocIndex = (int)(realLen & (word32)blockMask);
/* Add length of hmac's ipad to total length. */ /* Add length of hmac's ipad to total length. */
realLen += blockSz; realLen += (word32)blockSz;
/* Length as bits - 8 bytes bigendian. */ /* Length as bits - 8 bytes bigendian. */
c32toa(realLen >> ((sizeof(word32) * 8) - 3), lenBytes); c32toa(realLen >> ((sizeof(word32) * 8) - 3), lenBytes);
c32toa(realLen << 3, lenBytes + sizeof(word32)); 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); ret = Hmac_HashUpdate(hmac, header, WOLFSSL_TLS_HMAC_INNER_SZ);
if (ret != 0) if (ret != 0)
return ret; return ret;
ret = Hmac_HashUpdate(hmac, in, safeBlocks * blockSz - ret = Hmac_HashUpdate(hmac, in, (word32)(safeBlocks * blockSz -
WOLFSSL_TLS_HMAC_INNER_SZ); WOLFSSL_TLS_HMAC_INNER_SZ));
if (ret != 0) if (ret != 0)
return ret; return ret;
} }
@ -1278,7 +1278,7 @@ int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int padSz,
#endif #endif
{ {
ret = Hmac_UpdateFinal_CT(&hmac, digest, in, ret = Hmac_UpdateFinal_CT(&hmac, digest, in,
sz + hashSz + padSz + 1, hashSz, myInner); (sz + hashSz + (word32)padSz + 1), (int)hashSz, myInner);
} }
#else #else
ret = Hmac_UpdateFinal(&hmac, digest, in, sz + hashSz + padSz + 1, ret = Hmac_UpdateFinal(&hmac, digest, in, sz + hashSz + padSz + 1,
@ -7663,7 +7663,7 @@ static int TLSX_KeyShare_GenEccKey(WOLFSSL *ssl, KeyShareEntry* kse)
#endif #endif
{ {
/* set curve info for EccMakeKey "peer" info */ /* 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) { if (ret == 0) {
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
/* Detect when private key generation is done */ /* Detect when private key generation is done */

View File

@ -7014,7 +7014,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
if (ret != 0) if (ret != 0)
goto exit_dch; goto exit_dch;
#else #else
if ((ret = HashInput(ssl, input + args->begin, helloSz)) != 0) if ((ret = HashInput(ssl, input + args->begin, (int)helloSz)) != 0)
goto exit_dch; goto exit_dch;
#endif #endif
@ -7458,7 +7458,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
} }
#endif /* WOLFSSL_DTLS13 */ #endif /* WOLFSSL_DTLS13 */
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
if (!ssl->options.groupMessages || extMsgType != server_hello) if (!ssl->options.groupMessages || extMsgType != server_hello)
ret = SendBuffered(ssl); ret = SendBuffered(ssl);
@ -7606,11 +7606,11 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
/* This handshake message is always encrypted. */ /* This handshake message is always encrypted. */
sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ, 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) if (sendSz < 0)
return sendSz; return sendSz;
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
ssl->options.buildingMsg = 0; ssl->options.buildingMsg = 0;
ssl->options.serverState = SERVER_ENCRYPTED_EXTENSIONS_COMPLETE; ssl->options.serverState = SERVER_ENCRYPTED_EXTENSIONS_COMPLETE;
@ -7636,7 +7636,7 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
* returns 0 on success, otherwise failure. * returns 0 on success, otherwise failure.
*/ */
static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx, static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
int reqCtxLen) word32 reqCtxLen)
{ {
byte* output; byte* output;
int ret; int ret;
@ -7724,7 +7724,7 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
/* Always encrypted. */ /* Always encrypted. */
sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ, 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) if (sendSz < 0)
return sendSz; return sendSz;
@ -7739,7 +7739,7 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
} }
#endif #endif
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
ssl->options.buildingMsg = 0; ssl->options.buildingMsg = 0;
if (!ssl->options.groupMessages) if (!ssl->options.groupMessages)
ret = SendBuffered(ssl); ret = SendBuffered(ssl);
@ -8510,7 +8510,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
certSz = 0; certSz = 0;
certChainSz = 0; certChainSz = 0;
headerSz = OPAQUE8_LEN + certReqCtxLen + CERT_HEADER_SZ; headerSz = OPAQUE8_LEN + certReqCtxLen + CERT_HEADER_SZ;
length = headerSz; length = (sword32)headerSz;
listSz = 0; listSz = 0;
} }
else { else {
@ -8542,7 +8542,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
} }
/* Length of message data with one certificate and extensions. */ /* 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. */ /* Length of list data with one certificate and extensions. */
listSz = CERT_HEADER_SZ + certSz + extSz; listSz = CERT_HEADER_SZ + certSz + extSz;
@ -8551,7 +8551,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
p = ssl->buffers.certChain->buffer; p = ssl->buffers.certChain->buffer;
/* Chain length including extensions. */ /* Chain length including extensions. */
certChainSz = ssl->buffers.certChain->length + certChainSz = ssl->buffers.certChain->length +
OPAQUE16_LEN * ssl->buffers.certChainCnt; OPAQUE16_LEN * (word32)ssl->buffers.certChainCnt;
length += certChainSz; length += certChainSz;
listSz += certChainSz; listSz += certChainSz;
} }
@ -8559,7 +8559,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
certChainSz = 0; certChainSz = 0;
} }
payloadSz = length; payloadSz = (word32)length;
if (ssl->fragOffset != 0) if (ssl->fragOffset != 0)
length -= (ssl->fragOffset + headerSz); length -= (ssl->fragOffset + headerSz);
@ -8703,7 +8703,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
{ {
/* This message is always encrypted. */ /* This message is always encrypted. */
sendSz = BuildTls13Message(ssl, output, sendSz, 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); 0, 0);
if (sendSz < 0) if (sendSz < 0)
return sendSz; return sendSz;
@ -8719,7 +8719,7 @@ static int SendTls13Certificate(WOLFSSL* ssl)
} }
#endif #endif
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
ssl->options.buildingMsg = 0; ssl->options.buildingMsg = 0;
if (!ssl->options.groupMessages) if (!ssl->options.groupMessages)
ret = SendBuffered(ssl); ret = SendBuffered(ssl);
@ -9150,7 +9150,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
#endif /* !NO_RSA */ #endif /* !NO_RSA */
#ifdef HAVE_ECC #ifdef HAVE_ECC
if (ssl->hsType == DYNAMIC_TYPE_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; VERIFY_HEADER;
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
if (ssl->buffers.keyType != sm2_sa_algo) if (ssl->buffers.keyType != sm2_sa_algo)
@ -9555,7 +9555,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
} }
#endif #endif
ssl->buffers.outputBuffer.length += args->sendSz; ssl->buffers.outputBuffer.length += (word32)args->sendSz;
ssl->options.buildingMsg = 0; ssl->options.buildingMsg = 0;
if (!ssl->options.groupMessages) if (!ssl->options.groupMessages)
ret = SendBuffered(ssl); ret = SendBuffered(ssl);
@ -10846,7 +10846,7 @@ static int SendTls13Finished(WOLFSSL* ssl)
input = output + Dtls13GetRlHeaderLength(ssl, 1); input = output + Dtls13GetRlHeaderLength(ssl, 1);
#endif /* WOLFSSL_DTLS13 */ #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 defined(WOLFSSL_RENESAS_TSIP_TLS)
if (ssl->options.side == WOLFSSL_CLIENT_END) { if (ssl->options.side == WOLFSSL_CLIENT_END) {
@ -10931,7 +10931,7 @@ static int SendTls13Finished(WOLFSSL* ssl)
} }
#endif #endif
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
ssl->options.buildingMsg = 0; ssl->options.buildingMsg = 0;
} }
@ -11140,7 +11140,7 @@ static int SendTls13KeyUpdate(WOLFSSL* ssl)
} }
#endif #endif
ssl->buffers.outputBuffer.length += sendSz; ssl->buffers.outputBuffer.length += (word32)sendSz;
ret = SendBuffered(ssl); ret = SendBuffered(ssl);

View File

@ -18620,7 +18620,7 @@ static int test_wc_Chacha_Process(void)
ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen), ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
0); 0);
ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (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) #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
/* test checking and using leftovers, currently just in C code */ /* 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); (word32)inlen - 2), 0);
ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2), ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
(byte*)input + (inlen - 2), 2), 0); (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 */ /* check edge cases with counter increment */
{ {
@ -20142,8 +20142,8 @@ static int test_wc_RsaPublicKeyDecodeRaw(void)
RsaKey key; RsaKey key;
const byte n = 0x23; const byte n = 0x23;
const byte e = 0x03; const byte e = 0x03;
int nSz = sizeof(n); word32 nSz = sizeof(n);
int eSz = sizeof(e); word32 eSz = sizeof(e);
ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0); ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 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); ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
key_buf[0] = '\n'; key_buf[0] = '\n';
ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz)); 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); &pDer, NULL, &info, &eccKey)), 0);
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
@ -70516,7 +70516,7 @@ static int test_wc_ParseCert_Error(void)
/* Test data */ /* Test data */
const struct testStruct { const struct testStruct {
const byte* c; const byte* c;
const int cSz; word32 cSz;
const int expRet; const int expRet;
} t[] = { } t[] = {
{c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */ {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 (i = 0; i < sizeof(data); i++) {
for (len = 1; len < sizeof(data) - i; len++) { for (len = 1; len < sizeof(data) - i; len++) {
for (j = 0; j < sizeof(data); j++) for (j = 0; j < sizeof(data); j++)
data[j] = j + 1; data[j] = ((unsigned char)j + 1);
ForceZero(data + i, len); 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) { if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
fprintf(stderr, "loading cert %s failed\n", certA); fprintf(stderr, "loading cert %s failed\n", certA);
fprintf(stderr, "Error: (%d): %s\n", ret, fprintf(stderr, "Error: (%d): %s\n", ret,
wolfSSL_ERR_reason_error_string(ret)); wolfSSL_ERR_reason_error_string((unsigned long)ret));
return -1; return -1;
} }
@ -81910,7 +81910,7 @@ static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
!= WOLFSSL_SUCCESS) { != WOLFSSL_SUCCESS) {
fprintf(stderr, "could not verify the cert: %s\n", certA); fprintf(stderr, "could not verify the cert: %s\n", certA);
fprintf(stderr, "Error: (%d): %s\n", ret, fprintf(stderr, "Error: (%d): %s\n", ret,
wolfSSL_ERR_reason_error_string(ret)); wolfSSL_ERR_reason_error_string((unsigned long)ret));
return -1; return -1;
} }
else { else {
@ -83223,7 +83223,7 @@ static int error_test(void)
break; break;
} }
} }
errStr = wolfSSL_ERR_reason_error_string(i); errStr = wolfSSL_ERR_reason_error_string((unsigned long)i);
if (! this_missing) { if (! this_missing) {
ExpectIntNE(XSTRCMP(errStr, unknownStr), 0); 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)); ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0); ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
#else #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); 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); ExpectIntEQ((*err == '\0'), 1);
/* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */ /* 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; EXPECT_DECLS;
WOLFSSL_SESSION *sess = NULL; WOLFSSL_SESSION *sess = NULL;
/* Setup the session to avoid errors */ /* Setup the session to avoid errors */
ssl->session->timeout = -1; ssl->session->timeout = (word32)-1;
ssl->session->side = WOLFSSL_CLIENT_END; ssl->session->side = WOLFSSL_CLIENT_END;
#if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \ #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
defined(HAVE_SESSION_TICKET)) defined(HAVE_SESSION_TICKET))

View File

@ -215,7 +215,9 @@
const byte* _x = (const byte*)(x); \ const byte* _x = (const byte*)(x); \
const byte* _y = (const byte*)(y); \ const byte* _y = (const byte*)(y); \
int _z = (int)(z); \ 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), \ Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \
("\"%p\" " #er " \"%p\" for \"%d\"", \ ("\"%p\" " #er " \"%p\" for \"%d\"", \
(const void *)_x, (const void *)_y, _z)); \ (const void *)_x, (const void *)_y, _z)); \