From 81ae002521098197fef2a20f61feab5cf93c10dd Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 27 Nov 2024 09:41:30 -0800 Subject: [PATCH] Fix conversion on various files. Work from Reda. --- src/bio.c | 57 +++--- src/internal.c | 11 +- src/keys.c | 12 +- src/pk.c | 51 +++--- src/ssl.c | 170 +++++++++--------- src/ssl_asn1.c | 35 ++-- src/ssl_crypto.c | 20 ++- src/ssl_load.c | 21 +-- src/ssl_sess.c | 13 +- src/tls.c | 23 +-- src/tls13.c | 2 +- src/wolfio.c | 3 +- tests/api.c | 8 +- wolfcrypt/src/cmac.c | 6 +- wolfcrypt/src/evp.c | 6 +- wolfcrypt/src/kdf.c | 2 +- wolfcrypt/src/logging.c | 16 +- wolfcrypt/src/misc.c | 4 +- .../src/port/Renesas/renesas_fspsm_aes.c | 8 +- .../src/port/Renesas/renesas_fspsm_util.c | 8 +- wolfcrypt/test/test.c | 6 +- wolfssl/wolfcrypt/logging.h | 2 +- 22 files changed, 256 insertions(+), 228 deletions(-) diff --git a/src/bio.c b/src/bio.c index df177293d5..34b5861f78 100644 --- a/src/bio.c +++ b/src/bio.c @@ -80,14 +80,14 @@ static int wolfSSL_BIO_BIO_read(WOLFSSL_BIO* bio, void* buf, int len) bio->flags &= ~(WOLFSSL_BIO_FLAG_READ|WOLFSSL_BIO_FLAG_RETRY); sz1 = wolfSSL_BIO_nread(bio, &pt, len); if (sz1 > 0) { - XMEMCPY(buf, pt, sz1); + XMEMCPY(buf, pt, (size_t)sz1); buf = (char*)buf + sz1; len -= sz1; if (len > 0) { /* try again to see if maybe we wrapped around the ring buffer */ sz2 = wolfSSL_BIO_nread(bio, &pt, len); if (sz2 > 0) { - XMEMCPY(buf, pt, sz2); + XMEMCPY(buf, pt, (size_t)sz2); sz1 += sz2; } } @@ -142,7 +142,7 @@ static int wolfSSL_BIO_MEMORY_read(WOLFSSL_BIO* bio, void* buf, int len) return WOLFSSL_BIO_ERROR; } - XMEMCPY(buf, bio->mem_buf->data + bio->rdIdx, sz); + XMEMCPY(buf, bio->mem_buf->data + bio->rdIdx, (size_t)sz); bio->rdIdx += sz; if (bio->rdIdx >= bio->wrSz) { @@ -167,14 +167,14 @@ static int wolfSSL_BIO_MEMORY_read(WOLFSSL_BIO* bio, void* buf, int len) /* Resize the memory so we are not taking up more than necessary. * memmove reverts internally to memcpy if areas don't overlap */ XMEMMOVE(bio->mem_buf->data, bio->mem_buf->data + bio->rdIdx, - bio->wrSz - bio->rdIdx); + (long unsigned int)bio->wrSz - (size_t)bio->rdIdx); bio->wrSz -= bio->rdIdx; bio->rdIdx = 0; /* Resize down to WOLFSSL_BIO_RESIZE_THRESHOLD for fewer * allocations. */ if (wolfSSL_BUF_MEM_resize(bio->mem_buf, - bio->wrSz > WOLFSSL_BIO_RESIZE_THRESHOLD ? bio->wrSz : - WOLFSSL_BIO_RESIZE_THRESHOLD) == 0) { + bio->wrSz > WOLFSSL_BIO_RESIZE_THRESHOLD ? + (size_t)bio->wrSz : WOLFSSL_BIO_RESIZE_THRESHOLD) == 0) { WOLFSSL_MSG("wolfSSL_BUF_MEM_resize error"); return WOLFSSL_BIO_ERROR; } @@ -562,7 +562,7 @@ static int wolfSSL_BIO_BIO_write(WOLFSSL_BIO* bio, const void* data, WOLFSSL_MSG("Error in wolfSSL_BIO_nwrite"); return sz1; } - XMEMCPY(buf, data, sz1); + XMEMCPY(buf, data, (size_t)sz1); data = (char*)data + sz1; len -= sz1; @@ -570,7 +570,7 @@ static int wolfSSL_BIO_BIO_write(WOLFSSL_BIO* bio, const void* data, /* try again to see if maybe we wrapped around the ring buffer */ sz2 = wolfSSL_BIO_nwrite(bio, &buf, len); if (sz2 > 0) { - XMEMCPY(buf, data, sz2); + XMEMCPY(buf, data, (size_t)sz2); sz1 += sz2; if (len > sz2) bio->flags |= WOLFSSL_BIO_FLAG_WRITE|WOLFSSL_BIO_FLAG_RETRY; @@ -619,7 +619,7 @@ static int wolfSSL_BIO_MEMORY_write(WOLFSSL_BIO* bio, const void* data, return WOLFSSL_FAILURE; } - XMEMCPY(bio->mem_buf->data + bio->wrSz, data, len); + XMEMCPY(bio->mem_buf->data + bio->wrSz, data, (size_t)len); bio->ptr.mem_buf_data = (byte *)bio->mem_buf->data; bio->num.length = bio->mem_buf->max; bio->wrSz += len; @@ -1136,7 +1136,7 @@ int wolfSSL_BIO_gets(WOLFSSL_BIO* bio, char* buf, int sz) ret = wolfSSL_BIO_nread(bio, &c, cSz); if (ret > 0 && ret < sz) { - XMEMCPY(buf, c, ret); + XMEMCPY(buf, c, (size_t)ret); } break; } @@ -1254,13 +1254,13 @@ size_t wolfSSL_BIO_wpending(const WOLFSSL_BIO *bio) return 0; if (bio->type == WOLFSSL_BIO_MEMORY) { - return bio->wrSz; + return (size_t)bio->wrSz; } /* type BIO_BIO then check paired buffer */ if (bio->type == WOLFSSL_BIO_BIO && bio->pair != NULL) { WOLFSSL_BIO* pair = bio->pair; - return pair->wrIdx; + return (size_t)pair->wrIdx; } return 0; @@ -1306,12 +1306,12 @@ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio) #ifndef WOLFCRYPT_ONLY if (bio->type == WOLFSSL_BIO_SSL && bio->ptr.ssl != NULL) { - return (long)wolfSSL_pending(bio->ptr.ssl); + return (size_t)wolfSSL_pending(bio->ptr.ssl); } #endif if (bio->type == WOLFSSL_BIO_MEMORY) { - return bio->wrSz - bio->rdIdx; + return (size_t)(bio->wrSz - bio->rdIdx); } /* type BIO_BIO then check paired buffer */ @@ -1324,7 +1324,7 @@ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio) } else { /* simple case where has not wrapped around */ - return pair->wrIdx - pair->rdIdx; + return (size_t)(pair->wrIdx - pair->rdIdx); } } return 0; @@ -1421,7 +1421,7 @@ int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *bio, long size) XFREE(bio->ptr.mem_buf_data, bio->heap, DYNAMIC_TYPE_OPENSSL); } - bio->ptr.mem_buf_data = (byte*)XMALLOC(size, bio->heap, + bio->ptr.mem_buf_data = (byte*)XMALLOC((size_t)size, bio->heap, DYNAMIC_TYPE_OPENSSL); if (bio->ptr.mem_buf_data == NULL) { WOLFSSL_MSG("Memory allocation error"); @@ -1437,7 +1437,7 @@ int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *bio, long size) return WOLFSSL_FAILURE; } bio->wrSz = (int)size; - bio->num.length = size; + bio->num.length = (size_t)size; bio->wrIdx = 0; bio->rdIdx = 0; if (bio->mem_buf != NULL) { @@ -2379,10 +2379,11 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio) else port = str + XSTRLEN(str); /* point to null terminator */ - bio->ip = (char*)XMALLOC((port - str) + 1, /* +1 for null char */ + bio->ip = (char*)XMALLOC( + (size_t)(port - str) + 1, /* +1 for null char */ bio->heap, DYNAMIC_TYPE_OPENSSL); if (bio->ip != NULL) { - XMEMCPY(bio->ip, str, port - str); + XMEMCPY(bio->ip, str, (size_t)(port - str)); bio->ip[port - str] = '\0'; bio->type = WOLFSSL_BIO_SOCKET; } @@ -2922,7 +2923,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio) bio->wrSz = len; bio->ptr.mem_buf_data = (byte *)bio->mem_buf->data; if (len > 0 && bio->ptr.mem_buf_data != NULL) { - XMEMCPY(bio->ptr.mem_buf_data, buf, len); + XMEMCPY(bio->ptr.mem_buf_data, buf, (size_t)len); bio->flags |= WOLFSSL_BIO_FLAG_MEM_RDONLY; bio->wrSzReset = bio->wrSz; } @@ -3291,11 +3292,11 @@ int wolfSSL_BIO_vprintf(WOLFSSL_BIO* bio, const char* format, va_list args) count = XVSNPRINTF(NULL, 0, format, args); if (count >= 0) { - pt = (char*)XMALLOC(count + 1, bio->heap, + pt = (char*)XMALLOC((size_t)count + 1, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); if (pt != NULL) { - count = XVSNPRINTF(pt, count + 1, format, copy); + count = XVSNPRINTF(pt, (size_t)count + 1, format, copy); if (count >= 0) { ret = wolfSSL_BIO_write(bio, pt, count); @@ -3365,18 +3366,20 @@ int wolfSSL_BIO_dump(WOLFSSL_BIO *bio, const char *buf, int length) o = 7; for (i = 0; i < BIO_DUMP_LINE_LEN; i++) { if (i < length) - (void)XSNPRINTF(line + o, (int)sizeof(line) - o, + (void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), "%02x ", (unsigned char)buf[i]); else - (void)XSNPRINTF(line + o, (int)sizeof(line) - o, " "); + (void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), + " "); if (i == 7) - (void)XSNPRINTF(line + o + 2, (int)sizeof(line) - (o + 2), "-"); + (void)XSNPRINTF(line + o + 2, (size_t)((int)sizeof(line) - + (o + 2)), "-"); o += 3; } - (void)XSNPRINTF(line + o, (int)sizeof(line) - o, " "); + (void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), " "); o += 2; for (i = 0; (i < BIO_DUMP_LINE_LEN) && (i < length); i++) { - (void)XSNPRINTF(line + o, (int)sizeof(line) - o, "%c", + (void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), "%c", ((31 < buf[i]) && (buf[i] < 127)) ? buf[i] : '.'); o++; } diff --git a/src/internal.c b/src/internal.c index 756f2812fc..c491ed015a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7037,7 +7037,7 @@ void FreeHandshakeHashes(WOLFSSL* ssl) (defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \ !defined(WOLFSSL_NO_CLIENT_AUTH) if (ssl->hsHashes->messages != NULL) { - ForceZero(ssl->hsHashes->messages, ssl->hsHashes->length); + ForceZero(ssl->hsHashes->messages, (word32)ssl->hsHashes->length); XFREE(ssl->hsHashes->messages, ssl->heap, DYNAMIC_TYPE_HASHES); ssl->hsHashes->messages = NULL; } @@ -7105,8 +7105,9 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source, (defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \ !defined(WOLFSSL_NO_CLIENT_AUTH) if (ret == 0 && source->messages != NULL) { - (*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap, - DYNAMIC_TYPE_HASHES); + (*destination)->messages = (byte*)XMALLOC((size_t)source->length, + ssl->heap, + (int)DYNAMIC_TYPE_HASHES); (*destination)->length = source->length; (*destination)->prevLen = source->prevLen; @@ -7115,7 +7116,7 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source, } else { XMEMCPY((*destination)->messages, source->messages, - source->length); + (size_t)source->length); } } #endif @@ -9598,7 +9599,7 @@ int DtlsMsgPoolSend(WOLFSSL* ssl, int sendOnlyFirstPacket) WriteSEQ(ssl, epochOrder, dtls->sequence_number); DtlsSEQIncrement(ssl, epochOrder); - if ((ret = CheckAvailableSize(ssl, pool->sz)) != 0) { + if ((ret = CheckAvailableSize(ssl, (int)pool->sz)) != 0) { WOLFSSL_ERROR(ret); return ret; } diff --git a/src/keys.c b/src/keys.c index 693e6b1333..4aa274c41d 100644 --- a/src/keys.c +++ b/src/keys.c @@ -3908,7 +3908,8 @@ int DeriveKeys(WOLFSSL* ssl) XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN); if (ret == 0) { ret = wc_ShaUpdate(sha, shaInput, - (KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX + j); + (KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX + + (word32)(j)); } if (ret == 0) { ret = wc_ShaFinal(sha, shaOutput); @@ -3942,12 +3943,13 @@ int DeriveKeys(WOLFSSL* ssl) static int CleanPreMaster(WOLFSSL* ssl) { - int i, ret, sz = ssl->arrays->preMasterSz; + int i, ret, sz = (int)(ssl->arrays->preMasterSz); for (i = 0; i < sz; i++) ssl->arrays->preMasterSecret[i] = 0; - ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, sz); + ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, + (word32)(sz)); if (ret != 0) return ret; @@ -4035,8 +4037,8 @@ static int MakeSslMasterSecret(WOLFSSL* ssl) } idx = 0; - XMEMCPY(shaInput, prefix, i + 1); - idx += i + 1; + XMEMCPY(shaInput, prefix, (size_t)(i + 1)); + idx += (word32)(i + 1); XMEMCPY(shaInput + idx, ssl->arrays->preMasterSecret, pmsSz); idx += pmsSz; diff --git a/src/pk.c b/src/pk.c index 7790d98b79..410c16df92 100644 --- a/src/pk.c +++ b/src/pk.c @@ -414,7 +414,7 @@ int EncryptDerKey(byte *der, int *derSz, const WOLFSSL_EVP_CIPHER* cipher, if (ret == 0) { /* Generate a random salt. */ - if (wolfSSL_RAND_bytes(info->iv, info->ivSz) != 1) { + if (wolfSSL_RAND_bytes(info->iv, (int)info->ivSz) != 1) { WOLFSSL_MSG("generate iv failed"); ret = WOLFSSL_FATAL_ERROR; } @@ -422,7 +422,7 @@ int EncryptDerKey(byte *der, int *derSz, const WOLFSSL_EVP_CIPHER* cipher, if (ret == 0) { /* Calculate padding size - always a padding block. */ - paddingSz = info->ivSz - ((*derSz) % info->ivSz); + paddingSz = (int)info->ivSz - ((*derSz) % (int)info->ivSz); /* Check der is big enough. */ if (maxDerSz < (*derSz) + paddingSz) { WOLFSSL_MSG("not enough DER buffer allocated"); @@ -431,7 +431,7 @@ int EncryptDerKey(byte *der, int *derSz, const WOLFSSL_EVP_CIPHER* cipher, } if (ret == 0) { /* Set padding bytes to padding length. */ - XMEMSET(der + (*derSz), (byte)paddingSz, paddingSz); + XMEMSET(der + (*derSz), (byte)paddingSz, (size_t)paddingSz); /* Add padding to DER size. */ (*derSz) += (int)paddingSz; @@ -10273,7 +10273,7 @@ WOLFSSL_EC_POINT* wolfSSL_EC_POINT_hex2point(const WOLFSSL_EC_GROUP *group, key_sz = (wolfSSL_EC_GROUP_get_degree(group) + 7) / 8; if (hex[0] == '0' && hex[1] == '4') { /* uncompressed mode */ - str_sz = key_sz * 2; + str_sz = (size_t)key_sz * 2; XMEMSET(strGx, 0x0, str_sz + 1); XMEMCPY(strGx, hex + 2, str_sz); @@ -10299,7 +10299,7 @@ WOLFSSL_EC_POINT* wolfSSL_EC_POINT_hex2point(const WOLFSSL_EC_GROUP *group, if (hex_to_bytes(hex + 2, octGx + 1, sz) != sz) { goto err; } - if (wolfSSL_ECPoint_d2i(octGx, key_sz + 1, group, p) + if (wolfSSL_ECPoint_d2i(octGx, (word32)key_sz + 1, group, p) != WOLFSSL_SUCCESS) { goto err; } @@ -15473,7 +15473,7 @@ int wolfSSL_PEM_def_callback(char* buf, int num, int rwFlag, void* userData) if ((buf != NULL) && (userData != NULL)) { sz = (int)XSTRLEN((const char*)userData); sz = (int)min((word32)sz, (word32)num); - XMEMCPY(buf, userData, sz); + XMEMCPY(buf, userData, (size_t)sz); } else { WOLFSSL_MSG("Error, default password cannot be created."); @@ -15967,7 +15967,7 @@ static void pem_find_pattern(char* pem, int pemLen, int idx, const char* prefix, /* Find prefix part. */ for (; idx < pemLen - prefixLen; idx++) { if ((pem[idx] == prefix[0]) && - (XMEMCMP(pem + idx, prefix, prefixLen) == 0)) { + (XMEMCMP(pem + idx, prefix, (size_t)prefixLen) == 0)) { idx += prefixLen; *start = idx; break; @@ -15976,7 +15976,7 @@ static void pem_find_pattern(char* pem, int pemLen, int idx, const char* prefix, /* Find postfix part. */ for (; idx < pemLen - postfixLen; idx++) { if ((pem[idx] == postfix[0]) && - (XMEMCMP(pem + idx, postfix, postfixLen) == 0)) { + (XMEMCMP(pem + idx, postfix, (size_t)postfixLen) == 0)) { *len = idx - *start; break; } @@ -16012,7 +16012,7 @@ static int pem_read_data(char* pem, int pemLen, char **name, char **header, /* Find header. */ pem_find_pattern(pem, pemLen, 0, PEM_BEGIN, PEM_HDR_FIN, &start, &nameLen); /* Allocate memory for header name. */ - *name = (char*)XMALLOC(nameLen + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER); + *name = (char*)XMALLOC((size_t)nameLen + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (*name == NULL) { ret = MEMORY_E; } @@ -16023,7 +16023,7 @@ static int pem_read_data(char* pem, int pemLen, char **name, char **header, ret = ASN_NO_PEM_HEADER; } else { - XMEMCPY(*name, pem + start, nameLen); + XMEMCPY(*name, pem + start, (size_t)nameLen); } } if (ret == 0) { @@ -16035,7 +16035,8 @@ static int pem_read_data(char* pem, int pemLen, char **name, char **header, hdrLen++; } /* Allocate memory for encryption header string. */ - *header = (char*)XMALLOC(hdrLen + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER); + *header = (char*)XMALLOC((size_t)hdrLen + 1, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (*header == NULL) { ret = MEMORY_E; } @@ -16044,7 +16045,7 @@ static int pem_read_data(char* pem, int pemLen, char **name, char **header, /* Put in encryption header string. */ (*header)[hdrLen] = '\0'; if (hdrLen > 0) { - XMEMCPY(*header, pem + startHdr, hdrLen); + XMEMCPY(*header, pem + startHdr, (size_t)hdrLen); start = startHdr + hdrLen + 1; } @@ -16053,7 +16054,7 @@ static int pem_read_data(char* pem, int pemLen, char **name, char **header, &endLen); /* Validate header name and footer name are the same. */ if ((endLen != nameLen) || - (XMEMCMP(*name, pem + startEnd, nameLen) != 0)) { + (XMEMCMP(*name, pem + startEnd, (size_t)nameLen) != 0)) { ret = ASN_NO_PEM_HEADER; } } @@ -16103,13 +16104,13 @@ static int pem_write_data(const char *name, const char *header, pemLen = (derLen + 2) / 3 * 4; pemLen += (pemLen + 63) / 64; /* Header */ - pemLen += PEM_BEGIN_SZ + nameLen + PEM_HDR_FIN_EOL_SZ; + pemLen += (word32)(PEM_BEGIN_SZ + nameLen + PEM_HDR_FIN_EOL_SZ); if (headerLen > 0) { /* Encryption lines plus extra carriage return. */ - pemLen += headerLen + 1; + pemLen += (word32)headerLen + 1; } /* Trailer */ - pemLen += PEM_END_SZ + nameLen + PEM_HDR_FIN_EOL_SZ; + pemLen += (word32)(PEM_END_SZ + nameLen + PEM_HDR_FIN_EOL_SZ); pem = (char*)XMALLOC(pemLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (pem == NULL) { @@ -16121,14 +16122,14 @@ static int pem_write_data(const char *name, const char *header, /* Add header. */ XMEMCPY(p, PEM_BEGIN, PEM_BEGIN_SZ); p += PEM_BEGIN_SZ; - XMEMCPY(p, name, nameLen); + XMEMCPY(p, name, (size_t)nameLen); p += nameLen; XMEMCPY(p, PEM_HDR_FIN_EOL_NEWLINE, PEM_HDR_FIN_EOL_SZ); p += PEM_HDR_FIN_EOL_SZ; if (headerLen > 0) { /* Add encryption header. */ - XMEMCPY(p, header, headerLen); + XMEMCPY(p, header, (size_t)headerLen); p += headerLen; /* Blank line after a header and before body. */ *(p++) = '\n'; @@ -16144,7 +16145,7 @@ static int pem_write_data(const char *name, const char *header, /* Add trailer. */ XMEMCPY(p, PEM_END, PEM_END_SZ); p += PEM_END_SZ; - XMEMCPY(p, name, nameLen); + XMEMCPY(p, name, (size_t)nameLen); p += nameLen; XMEMCPY(p, PEM_HDR_FIN_EOL_NEWLINE, PEM_HDR_FIN_EOL_SZ); p += PEM_HDR_FIN_EOL_SZ; @@ -16192,13 +16193,13 @@ int wolfSSL_PEM_read_bio(WOLFSSL_BIO* bio, char **name, char **header, } if ((res == 1) && (!memAlloced)) { /* Need to return allocated memory - make sure it is allocated. */ - char* p = (char*)XMALLOC(pemLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); + char* p = (char*)XMALLOC((size_t)pemLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (p == NULL) { res = 0; } else { /* Copy the data into new buffer. */ - XMEMCPY(p, pem, pemLen); + XMEMCPY(p, pem, (size_t)pemLen); pem = p; } } @@ -16250,7 +16251,7 @@ int wolfSSL_PEM_write_bio(WOLFSSL_BIO* bio, const char *name, } XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER); - return (!err) ? pemLen : 0; + return (!err) ? (int)pemLen : 0; } #endif /* !NO_BIO */ @@ -16475,7 +16476,7 @@ int pkcs8_encrypt(WOLFSSL_EVP_PKEY* pkey, if (ret == 0) { /* Encrypt private into buffer. */ - ret = TraditionalEnc((byte*)pkey->pkey.ptr, pkey->pkey_sz, + ret = TraditionalEnc((byte*)pkey->pkey.ptr, (word32)pkey->pkey_sz, key, keySz, passwd, passwdSz, PKCS5, PBES2, encAlgId, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL); if (ret > 0) { @@ -16509,7 +16510,7 @@ int pkcs8_encode(WOLFSSL_EVP_PKEY* pkey, byte* key, word32* keySz) if (pkey->type == WC_EVP_PKEY_EC) { /* ECC private and get curve OID information. */ algId = ECDSAk; - ret = wc_ecc_get_oid(pkey->ecc->group->curve_oid, &curveOid, + ret = wc_ecc_get_oid((word32)pkey->ecc->group->curve_oid, &curveOid, &oidSz); } else @@ -16557,7 +16558,7 @@ int pkcs8_encode(WOLFSSL_EVP_PKEY* pkey, byte* key, word32* keySz) if (ret >= 0) { /* Encode private key in PKCS#8 format. */ ret = wc_CreatePKCS8Key(key, keySz, (byte*)pkey->pkey.ptr, - pkey->pkey_sz, algId, curveOid, oidSz); + (word32)pkey->pkey_sz, algId, curveOid, oidSz); } return ret; diff --git a/src/ssl.c b/src/ssl.c index b11ed59a7e..dd50545bf0 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1645,7 +1645,7 @@ int wolfSSL_get_ciphers(char* buf, int len) for (i = 0; i < ciphersSz; i++) { int cipherNameSz = (int)XSTRLEN(ciphers[i].name); if (cipherNameSz + 1 < len) { - XSTRNCPY(buf, ciphers[i].name, len); + XSTRNCPY(buf, ciphers[i].name, (size_t)len); buf += cipherNameSz; if (i < ciphersSz - 1) @@ -1682,7 +1682,7 @@ int wolfSSL_get_ciphers_iana(char* buf, int len) #endif cipherNameSz = (int)XSTRLEN(ciphers[i].name_iana); if (cipherNameSz + 1 < len) { - XSTRNCPY(buf, ciphers[i].name_iana, len); + XSTRNCPY(buf, ciphers[i].name_iana, (size_t)len); buf += cipherNameSz; if (i < ciphersSz - 1) @@ -1708,7 +1708,7 @@ const char* wolfSSL_get_shared_ciphers(WOLFSSL* ssl, char* buf, int len) cipher = wolfSSL_get_cipher_name_iana(ssl); len = (int)min((word32)len, (word32)(XSTRLEN(cipher) + 1)); - XMEMCPY(buf, cipher, len); + XMEMCPY(buf, cipher, (size_t)len); return buf; } @@ -2129,7 +2129,7 @@ int wolfSSL_export_dtls_srtp_keying_material(WOLFSSL* ssl, return BUFFER_E; } - return wolfSSL_export_keying_material(ssl, out, profile->kdfBits, + return wolfSSL_export_keying_material(ssl, out, (size_t)profile->kdfBits, DTLS_SRTP_KEYING_MATERIAL_LABEL, XSTR_SIZEOF(DTLS_SRTP_KEYING_MATERIAL_LABEL), NULL, 0, 0); } @@ -3542,7 +3542,7 @@ int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list, word16 *listSz) *list = NULL; return WOLFSSL_FAILURE; } - XMEMCPY(p, s + i, len); + XMEMCPY(p, s + i, (size_t)len); } *p = 0; @@ -6694,7 +6694,7 @@ static int d2iTryRsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem, } pkey->pkey_sz = (int)keyIdx; - pkey->pkey.ptr = (char*)XMALLOC(memSz, NULL, + pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL, priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL) { @@ -6866,7 +6866,7 @@ static int d2iTryDsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem, } pkey->pkey_sz = (int)keyIdx; - pkey->pkey.ptr = (char*)XMALLOC(memSz, NULL, + pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL, priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL) { @@ -6950,14 +6950,14 @@ static int d2iTryDhKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem, } pkey->pkey_sz = (int)memSz; - pkey->pkey.ptr = (char*)XMALLOC(memSz, NULL, + pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL, priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL) { ret = 0; } if (ret == 1) { - XMEMCPY(pkey->pkey.ptr, mem, memSz); + XMEMCPY(pkey->pkey.ptr, mem, (size_t)memSz); pkey->type = WC_EVP_PKEY_DH; pkey->ownDh = 1; @@ -7035,14 +7035,14 @@ static int d2iTryAltDhKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem, ret = 1; pkey->type = WC_EVP_PKEY_DH; pkey->pkey_sz = (int)memSz; - pkey->pkey.ptr = (char*)XMALLOC(memSz, NULL, + pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL, priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL) { ret = 0; } if (ret == 1) { - XMEMCPY(pkey->pkey.ptr, mem, memSz); + XMEMCPY(pkey->pkey.ptr, mem, (size_t)memSz); pkey->ownDh = 1; pkey->dh = wolfSSL_DH_new(); if (pkey->dh == NULL) { @@ -7524,7 +7524,8 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PUBKEY_bio(WOLFSSL_BIO* bio, return NULL; } - mem = (unsigned char*)XMALLOC(memSz, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + mem = (unsigned char*)XMALLOC((size_t)memSz, bio->heap, + DYNAMIC_TYPE_TMP_BUFFER); if (mem == NULL) { return NULL; } @@ -7583,15 +7584,16 @@ static int wolfSSL_EVP_PKEY_get_der(const WOLFSSL_EVP_PKEY* key, if (*der) { /* since this function signature has no size value passed in it is * assumed that the user has allocated a large enough buffer */ - XMEMCPY(*der, pt + pkcs8HeaderSz, sz); + XMEMCPY(*der, pt + pkcs8HeaderSz, (size_t)sz); *der += sz; } else { - *der = (unsigned char*)XMALLOC(sz, NULL, DYNAMIC_TYPE_OPENSSL); + *der = (unsigned char*)XMALLOC((size_t)sz, NULL, + DYNAMIC_TYPE_OPENSSL); if (*der == NULL) { return WOLFSSL_FATAL_ERROR; } - XMEMCPY(*der, pt + pkcs8HeaderSz, sz); + XMEMCPY(*der, pt + pkcs8HeaderSz, (size_t)sz); } } return sz; @@ -7663,14 +7665,15 @@ static WOLFSSL_EVP_PKEY* _d2i_PublicKey(int type, WOLFSSL_EVP_PKEY** out, local->type = type; local->pkey_sz = (int)inSz; local->pkcs8HeaderSz = pkcs8HeaderSz; - local->pkey.ptr = (char*)XMALLOC(inSz, NULL, DYNAMIC_TYPE_PUBLIC_KEY); + local->pkey.ptr = (char*)XMALLOC((size_t)inSz, NULL, + DYNAMIC_TYPE_PUBLIC_KEY); if (local->pkey.ptr == NULL) { wolfSSL_EVP_PKEY_free(local); local = NULL; return NULL; } else { - XMEMCPY(local->pkey.ptr, *in, inSz); + XMEMCPY(local->pkey.ptr, *in, (size_t)inSz); } switch (type) { @@ -12296,7 +12299,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl) { WOLFSSL_ENTER("wolfSSL_ERR_get_error"); #ifdef WOLFSSL_HAVE_ERROR_QUEUE - return wc_GetErrorNodeErr(); + return (unsigned long)wc_GetErrorNodeErr(); #else return (unsigned long)(0 - NOT_COMPILED_IN); #endif @@ -12367,7 +12370,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl) do { ret = wc_PeekErrorNode(0, &file, &reason, &line); if (ret >= 0) { - const char* r = wolfSSL_ERR_reason_error_string(0 - ret); + const char* r = wolfSSL_ERR_reason_error_string( + (unsigned long)(0 - ret)); if (XSNPRINTF(buf, sizeof(buf), "error:%d:wolfSSL library:%s:%s:%d\n", ret, r, file, line) @@ -14215,9 +14219,9 @@ WOLFSSL_X509* wolfSSL_get_certificate(WOLFSSL* ssl) } #ifndef WOLFSSL_X509_STORE_CERTS ssl->ourCert = wolfSSL_X509_d2i_ex(NULL, - ssl->buffers.certificate->buffer, - ssl->buffers.certificate->length, - ssl->heap); + ssl->buffers.certificate->buffer, + (int)ssl->buffers.certificate->length, + ssl->heap); #endif } return ssl->ourCert; @@ -14231,9 +14235,9 @@ WOLFSSL_X509* wolfSSL_get_certificate(WOLFSSL* ssl) } #ifndef WOLFSSL_X509_STORE_CERTS ssl->ctx->ourCert = wolfSSL_X509_d2i_ex(NULL, - ssl->ctx->certificate->buffer, - ssl->ctx->certificate->length, - ssl->heap); + ssl->ctx->certificate->buffer, + (int)ssl->ctx->certificate->length, + ssl->heap); #endif ssl->ctx->ownOurCert = 1; } @@ -14255,7 +14259,8 @@ WOLFSSL_X509* wolfSSL_CTX_get0_certificate(WOLFSSL_CTX* ctx) #ifndef WOLFSSL_X509_STORE_CERTS ctx->ourCert = wolfSSL_X509_d2i_ex(NULL, ctx->certificate->buffer, - ctx->certificate->length, ctx->heap); + (int)ctx->certificate->length, + ctx->heap); #endif ctx->ownOurCert = 1; } @@ -14998,42 +15003,42 @@ int wolfSSL_sk_CIPHER_description(WOLFSSL_CIPHER* cipher) /* Build up the string by copying onto the end. */ - XSTRNCPY(dp, name, len); + XSTRNCPY(dp, name, (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, " ", len); + XSTRNCPY(dp, " ", (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, protocol, len); + XSTRNCPY(dp, protocol, (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, " Kx=", len); + XSTRNCPY(dp, " Kx=", (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, keaStr, len); + XSTRNCPY(dp, keaStr, (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, " Au=", len); + XSTRNCPY(dp, " Au=", (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, authStr, len); + XSTRNCPY(dp, authStr, (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, " Enc=", len); + XSTRNCPY(dp, " Enc=", (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, encStr, len); + XSTRNCPY(dp, encStr, (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); len -= strLen; dp += strLen; - XSTRNCPY(dp, " Mac=", len); + XSTRNCPY(dp, " Mac=", (size_t)len); dp[len-1] = '\0'; strLen = (int)XSTRLEN(dp); - len -= strLen; dp += strLen; - XSTRNCPY(dp, macStr, len); + len -= strLen; dp += (size_t)strLen; + XSTRNCPY(dp, macStr, (size_t)len); dp[len-1] = '\0'; return WOLFSSL_SUCCESS; @@ -15291,7 +15296,7 @@ char* wolfSSL_CIPHER_description(const WOLFSSL_CIPHER* cipher, char* in, */ if (cipher->in_stack == TRUE) { wolfSSL_sk_CIPHER_description((WOLFSSL_CIPHER*)cipher); - XSTRNCPY(in,cipher->description,len); + XSTRNCPY(in,cipher->description,(size_t)len); return ret; } #endif @@ -15304,32 +15309,32 @@ char* wolfSSL_CIPHER_description(const WOLFSSL_CIPHER* cipher, char* in, macStr = wolfssl_mac_to_string(cipher->ssl->specs.mac_algorithm); /* Build up the string by copying onto the end. */ - XSTRNCPY(in, wolfSSL_CIPHER_get_name(cipher), len); + XSTRNCPY(in, wolfSSL_CIPHER_get_name(cipher), (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, " ", len); + XSTRNCPY(in, " ", (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, wolfSSL_get_version(cipher->ssl), len); + XSTRNCPY(in, wolfSSL_get_version(cipher->ssl), (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, " Kx=", len); + XSTRNCPY(in, " Kx=", (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, keaStr, len); + XSTRNCPY(in, keaStr, (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, " Au=", len); + XSTRNCPY(in, " Au=", (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, authStr, len); + XSTRNCPY(in, authStr, (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, " Enc=", len); + XSTRNCPY(in, " Enc=", (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, encStr, len); + XSTRNCPY(in, encStr, (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, " Mac=", len); + XSTRNCPY(in, " Mac=", (size_t)len); in[len-1] = '\0'; strLen = XSTRLEN(in); len -= (int)strLen; in += strLen; - XSTRNCPY(in, macStr, len); + XSTRNCPY(in, macStr, (size_t)len); in[len-1] = '\0'; return ret; @@ -16459,8 +16464,8 @@ long wolfSSL_clear_options(WOLFSSL* ssl, long opt) WOLFSSL_ENTER("wolfSSL_clear_options"); if(ssl == NULL) return WOLFSSL_FAILURE; - ssl->options.mask &= ~opt; - return ssl->options.mask; + ssl->options.mask &= (unsigned long)~opt; + return (long)ssl->options.mask; } #ifdef HAVE_PK_CALLBACKS @@ -16725,7 +16730,7 @@ long wolfSSL_get_verify_result(const WOLFSSL *ssl) return WOLFSSL_FAILURE; } - return ssl->peerVerifyRet; + return (long)ssl->peerVerifyRet; } #endif @@ -17402,7 +17407,7 @@ int wolfSSL_cmp_peer_cert_to_file(WOLFSSL* ssl, const char *fname) if (sz > (long)sizeof(staticBuffer)) { WOLFSSL_MSG("Getting dynamic buffer"); - myBuffer = (byte*)XMALLOC(sz, ctx->heap, DYNAMIC_TYPE_FILE); + myBuffer = (byte*)XMALLOC((size_t)sz, ctx->heap, DYNAMIC_TYPE_FILE); dynamic = 1; } @@ -18279,7 +18284,7 @@ WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx) #endif { InitDecodedCert(cert, chain->certs[idx].buffer, - chain->certs[idx].length, NULL); + (word32)chain->certs[idx].length, NULL); if ((ret = ParseCertRelative(cert, CERT_TYPE, 0, NULL, NULL)) != 0) { WOLFSSL_MSG("Failed to parse cert"); @@ -18341,10 +18346,11 @@ int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx, /* Null output buffer return size needed in outLen */ if(!buf) { - if(Base64_Encode(chain->certs[idx].buffer, chain->certs[idx].length, + if(Base64_Encode(chain->certs[idx].buffer, + (word32)chain->certs[idx].length, NULL, &szNeeded) != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) return WOLFSSL_FAILURE; - *outLen = szNeeded + headerLen + footerLen; + *outLen = (int)szNeeded + headerLen + footerLen; return WC_NO_ERR_TRACE(LENGTH_ONLY_E); } @@ -18353,7 +18359,7 @@ int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx, return BAD_FUNC_ARG; /* header */ - if (XMEMCPY(buf, header, headerLen) == NULL) + if (XMEMCPY(buf, header, (size_t)headerLen) == NULL) return WOLFSSL_FATAL_ERROR; i = headerLen; @@ -18361,14 +18367,15 @@ int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx, /* body */ *outLen = inLen; /* input to Base64_Encode */ if ( (err = Base64_Encode(chain->certs[idx].buffer, - chain->certs[idx].length, buf + i, (word32*)outLen)) < 0) + (word32)chain->certs[idx].length, buf + i, + (word32*)outLen)) < 0) return err; i += *outLen; /* footer */ if ( (i + footerLen) > inLen) return BAD_FUNC_ARG; - if (XMEMCPY(buf + i, footer, footerLen) == NULL) + if (XMEMCPY(buf + i, footer, (size_t)footerLen) == NULL) return WOLFSSL_FATAL_ERROR; *outLen += headerLen + footerLen; @@ -19088,7 +19095,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) obj->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA; } else { - obj->dynamic &= ~WOLFSSL_ASN1_DYNAMIC_DATA; + obj->dynamic &= (unsigned char)~WOLFSSL_ASN1_DYNAMIC_DATA; } } XMEMCPY((byte*)obj->obj, objBuf, obj->objSz); @@ -19203,7 +19210,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) bufSz = bufLen - 1; } if (bufSz) { - XMEMCPY(buf, name, bufSz); + XMEMCPY(buf, name, (size_t)bufSz); } else if (a->type == WOLFSSL_GEN_DNS || a->type == WOLFSSL_GEN_EMAIL || a->type == WOLFSSL_GEN_URI) { @@ -19214,7 +19221,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) if ((desc = oid_translate_num_to_str(buf))) { bufSz = (int)XSTRLEN(desc); bufSz = (int)min((word32)bufSz,(word32) bufLen - 1); - XMEMCPY(buf, desc, bufSz); + XMEMCPY(buf, desc, (size_t)bufSz); } } else { @@ -19370,19 +19377,21 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) if (o->nid > 0) return o->nid; - if ((ret = GetObjectId(o->obj, &idx, &oid, o->grp, o->objSz)) < 0) { + if ((ret = GetObjectId(o->obj, &idx, &oid, + (word32)o->grp, o->objSz)) < 0) { if (ret == WC_NO_ERR_TRACE(ASN_OBJECT_ID_E)) { /* Put ASN object tag in front and try again */ - int len = SetObjectId(o->objSz, NULL) + o->objSz; - byte* buf = (byte*)XMALLOC(len, NULL, DYNAMIC_TYPE_TMP_BUFFER); + int len = SetObjectId((int)o->objSz, NULL) + (int)o->objSz; + byte* buf = (byte*)XMALLOC((size_t)len, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (!buf) { WOLFSSL_MSG("malloc error"); return WOLFSSL_FATAL_ERROR; } - idx = SetObjectId(o->objSz, buf); + idx = (word32)SetObjectId((int)o->objSz, buf); XMEMCPY(buf + idx, o->obj, o->objSz); idx = 0; - ret = GetObjectId(buf, &idx, &oid, o->grp, len); + ret = GetObjectId(buf, &idx, &oid, (word32)o->grp, (word32)len); XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (ret < 0) { WOLFSSL_MSG("Issue getting OID of object"); @@ -19521,13 +19530,13 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) /* try as a short name */ len = (int)XSTRLEN(s); if ((int)XSTRLEN(wolfssl_object_info[i].sName) == len && - XSTRNCMP(wolfssl_object_info[i].sName, s, len) == 0) { + XSTRNCMP(wolfssl_object_info[i].sName, s, (word32)len) == 0) { return wolfssl_object_info[i].nid; } /* try as a long name */ if ((int)XSTRLEN(wolfssl_object_info[i].lName) == len && - XSTRNCMP(wolfssl_object_info[i].lName, s, len) == 0) { + XSTRNCMP(wolfssl_object_info[i].lName, s, (word32)len) == 0) { return wolfssl_object_info[i].nid; } } @@ -19582,7 +19591,7 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl) obj->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA; i = SetObjectId((int)outSz, (byte*)obj->obj); XMEMCPY((byte*)obj->obj + i, out, outSz); - obj->objSz = i + outSz; + obj->objSz = (word32)i + outSz; return obj; } @@ -20268,7 +20277,8 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PrivateKey_bio(WOLFSSL_BIO* bio, return NULL; } - mem = (unsigned char*)XMALLOC(memSz, bio->heap, DYNAMIC_TYPE_TMP_BUFFER); + mem = (unsigned char*)XMALLOC((size_t)memSz, bio->heap, + DYNAMIC_TYPE_TMP_BUFFER); if (mem == NULL) { WOLFSSL_MSG("Malloc failure"); return NULL; @@ -20293,7 +20303,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PrivateKey_bio(WOLFSSL_BIO* bio, int i; int j = 0; - extraBioMem = (unsigned char *)XMALLOC(extraBioMemSz, NULL, + extraBioMem = (unsigned char *)XMALLOC((size_t)extraBioMemSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (extraBioMem == NULL) { WOLFSSL_MSG("Malloc failure"); @@ -22102,13 +22112,13 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names, if (len > MAX_CURVE_NAME_SZ - 1) goto leave; - XMEMCPY(name, names + start, len); + XMEMCPY(name, names + start, (size_t)len); name[len] = 0; curve = WOLFSSL_NAMED_GROUP_INVALID; for (nist_name = kNistCurves; nist_name->name != NULL; nist_name++) { if (len == nist_name->name_len && - XSTRNCMP(name, nist_name->name, len) == 0) { + XSTRNCMP(name, nist_name->name, (size_t)len) == 0) { curve = nist_name->curve; break; } @@ -22131,7 +22141,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names, goto leave; } - curve = GetCurveByOID(eccSet->oidSum); + curve = GetCurveByOID((int)eccSet->oidSum); #else WOLFSSL_MSG("API not present to search farther using name"); goto leave; @@ -23261,7 +23271,7 @@ static int bio_get_data(WOLFSSL_BIO* bio, byte** data) ret = wolfSSL_BIO_get_len(bio); if (ret > 0) { - mem = (byte*)XMALLOC(ret, bio->heap, DYNAMIC_TYPE_OPENSSL); + mem = (byte*)XMALLOC((size_t)ret, bio->heap, DYNAMIC_TYPE_OPENSSL); if (mem == NULL) { WOLFSSL_MSG("Memory error"); ret = MEMORY_E; @@ -23354,7 +23364,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_AutoPrivateKey(WOLFSSL_EVP_PKEY** pkey, */ ret = GetSequence(der, &idx, &len, keyLen); if (ret >= 0) { - word32 end = idx + len; + word32 end = idx + (word32)len; while (ret >= 0 && idx < end) { /* Skip type */ idx++; @@ -23362,10 +23372,10 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_AutoPrivateKey(WOLFSSL_EVP_PKEY** pkey, len = 0; ret = GetLength(der, &idx, &len, keyLen); if (ret >= 0) { - if (idx + len > end) + if (idx + (word32)len > end) ret = ASN_PARSE_E; else { - idx += len; + idx += (word32)len; cnt++; } } diff --git a/src/ssl_asn1.c b/src/ssl_asn1.c index 402fcf7a4b..d99ac8dd7b 100644 --- a/src/ssl_asn1.c +++ b/src/ssl_asn1.c @@ -271,7 +271,7 @@ static int wolfssl_i2d_asn1_items(const void* obj, byte* buf, break; } innerLen = ret; - hdrLen = SetExplicit((byte)mem->tag, (word32)innerLen, buf, 0); + hdrLen = (int)SetExplicit((byte)mem->tag, (word32)innerLen, buf, 0); len += hdrLen; if (buf != NULL) buf += hdrLen; @@ -534,14 +534,14 @@ static int d2i_handle_tags(const WOLFSSL_ASN1_TEMPLATE* mem, const byte** src, WOLFSSL_MSG("asn tag error"); return WOLFSSL_FATAL_ERROR; } - *asnLen += idx; /* total buffer length */ - *impBuf = (byte*)XMALLOC(*asnLen, NULL, + *asnLen += (int)idx; /* total buffer length */ + *impBuf = (byte*)XMALLOC((size_t)*asnLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (*impBuf == NULL) { WOLFSSL_MSG("malloc error"); return WOLFSSL_FATAL_ERROR; } - XMEMCPY(*impBuf, *src, *asnLen); + XMEMCPY(*impBuf, *src, (size_t)*asnLen); (*impBuf)[0] = mem->first_byte; } } @@ -928,7 +928,7 @@ WOLFSSL_ASN1_BIT_STRING* wolfSSL_d2i_ASN1_BIT_STRING( return NULL; } - XMEMCPY(ret->data, *src + idx, length); + XMEMCPY(ret->data, *src + idx, (size_t)length); *src += idx + (word32)length; if (out != NULL) { @@ -2120,7 +2120,7 @@ int wolfssl_asn1_obj_set(WOLFSSL_ASN1_OBJECT* obj, const byte* der, word32 len, if (obj->obj != NULL) { XFREE((void*)obj->obj, obj->heap, DYNAMIC_TYPE_ASN1); obj->obj = NULL; - obj->dynamic &= ~WOLFSSL_ASN1_DYNAMIC_DATA; + obj->dynamic &= (unsigned char)~WOLFSSL_ASN1_DYNAMIC_DATA; } obj->obj =(unsigned char*)XMALLOC(idx + len, obj->heap, DYNAMIC_TYPE_ASN1); @@ -2177,12 +2177,13 @@ WOLFSSL_ASN1_OBJECT *wolfSSL_d2i_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT **a, return NULL; } - if (wolfssl_asn1_obj_set(ret, *der, idx + len, 0) != WOLFSSL_SUCCESS) { + if (wolfssl_asn1_obj_set(ret, *der, idx + (word32)len, 0) != + WOLFSSL_SUCCESS) { wolfSSL_ASN1_OBJECT_free(ret); return NULL; } - *der += idx + len; + *der += idx + (word32)len; if (a != NULL) { if (*a != NULL) wolfSSL_ASN1_OBJECT_free(*a); @@ -2830,13 +2831,14 @@ static int i2d_ASN1_STRING(WOLFSSL_ASN1_STRING* s, if (s == NULL || s->data == NULL || s->length == 0) return WOLFSSL_FATAL_ERROR; - len = SetHeader(tag, s->length, NULL, 0) + s->length; + len = (int)((word32)SetHeader(tag, (word32)s->length, NULL, 0) + + (word32)s->length); if (pp == NULL) return len; if (*pp == NULL) { - out = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1); + out = (unsigned char*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1); if (out == NULL) return WOLFSSL_FATAL_ERROR; } @@ -2844,8 +2846,8 @@ static int i2d_ASN1_STRING(WOLFSSL_ASN1_STRING* s, out = *pp; } - idx = (int)SetHeader(tag, s->length, out, 0); - XMEMCPY(out + idx, s->data, s->length); + idx = (int)SetHeader(tag, (word32)s->length, out, 0); + XMEMCPY(out + idx, s->data, (size_t)s->length); if (*pp == NULL) *pp = out; else @@ -2887,7 +2889,8 @@ int wolfSSL_i2d_ASN1_SEQUENCE(WOLFSSL_ASN1_STRING* s, return s->length; if (*pp == NULL) { - out = (unsigned char*)XMALLOC(s->length, NULL, DYNAMIC_TYPE_ASN1); + out = (unsigned char*)XMALLOC((size_t)s->length, + NULL, DYNAMIC_TYPE_ASN1); if (out == NULL) return WOLFSSL_FATAL_ERROR; } @@ -2895,7 +2898,7 @@ int wolfSSL_i2d_ASN1_SEQUENCE(WOLFSSL_ASN1_STRING* s, out = *pp; } - XMEMCPY(out, s->data, s->length); + XMEMCPY(out, s->data, (size_t)s->length); if (*pp == NULL) *pp = out; else @@ -2938,7 +2941,7 @@ static WOLFSSL_ASN1_STRING* d2i_ASN1_STRING(WOLFSSL_ASN1_STRING** out, wolfSSL_ASN1_STRING_free(*out); *out = ret; } - *src += idx + length; + *src += idx + (word32)length; return ret; } @@ -4118,7 +4121,7 @@ WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t, ret->data[0] = '2'; ret->data[1] = '0'; } /* Append rest of the data as it is the same. */ - XMEMCPY(&ret->data[2], t->data, t->length); + XMEMCPY(&ret->data[2], t->data, (size_t)t->length); } /* Check for pointer to return result through. */ diff --git a/src/ssl_crypto.c b/src/ssl_crypto.c index 6907822a64..e382b5f965 100644 --- a/src/ssl_crypto.c +++ b/src/ssl_crypto.c @@ -2543,21 +2543,23 @@ WOLFSSL_DES_LONG wolfSSL_DES_cbc_cksum(const unsigned char* in, if ((!err) && (dataSz % DES_BLOCK_SIZE)) { /* Allocate a buffer big enough to hold padded input. */ dataSz += DES_BLOCK_SIZE - (dataSz % DES_BLOCK_SIZE); - data = (unsigned char*)XMALLOC(dataSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); + data = (unsigned char*)XMALLOC((size_t)dataSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (data == NULL) { WOLFSSL_MSG("Issue creating temporary buffer"); err = 1; } else { /* Copy input and pad with 0s. */ - XMEMCPY(data, in, length); - XMEMSET(data + length, 0, dataSz - length); + XMEMCPY(data, in, (size_t)length); + XMEMSET(data + length, 0, (size_t)(dataSz - length)); } } if (!err) { /* Allocate buffer to hold encrypted data. */ - tmp = (unsigned char*)XMALLOC(dataSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); + tmp = (unsigned char*)XMALLOC((size_t)dataSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { WOLFSSL_MSG("Issue creating temporary buffer"); err = 1; @@ -2637,7 +2639,7 @@ void wolfSSL_DES_cbc_encrypt(const unsigned char* input, unsigned char* output, if (lb_sz != 0) { /* Create a 0 padded block from remaining bytes. */ XMEMSET(lastBlock, 0, DES_BLOCK_SIZE); - XMEMCPY(lastBlock, input + len, lb_sz); + XMEMCPY(lastBlock, input + len, (size_t)lb_sz); /* Encrypt last block into output. */ wc_Des_CbcEncrypt(des, output + len, lastBlock, (word32)DES_BLOCK_SIZE); @@ -2651,7 +2653,7 @@ void wolfSSL_DES_cbc_encrypt(const unsigned char* input, unsigned char* output, wc_Des_CbcDecrypt(des, lastBlock, input + len, (word32)DES_BLOCK_SIZE); /* Copy out the required amount of the decrypted block. */ - XMEMCPY(output + len, lastBlock, lb_sz); + XMEMCPY(output + len, lastBlock, (size_t)lb_sz); } } } @@ -2775,7 +2777,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input, if (lb_sz != 0) { /* Create a 0 padded block from remaining bytes. */ XMEMSET(lastBlock, 0, DES_BLOCK_SIZE); - XMEMCPY(lastBlock, input + len, lb_sz); + XMEMCPY(lastBlock, input + len, (size_t)lb_sz); /* Encrypt last block into output. */ ret = wc_Des3_CbcEncrypt(des3, output + len, lastBlock, (word32)DES_BLOCK_SIZE); @@ -2825,7 +2827,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input, (void)ret; #endif /* Copy out the required amount of the decrypted block. */ - XMEMCPY(output + len, lastBlock, lb_sz); + XMEMCPY(output + len, lastBlock, (size_t)lb_sz); } } } @@ -2940,7 +2942,7 @@ static int wolfssl_aes_set_key(const unsigned char *key, const int bits, return WOLFSSL_FATAL_ERROR; } - if (wc_AesSetKey((Aes*)aes, key, ((bits)/8), NULL, enc) != 0) { + if (wc_AesSetKey((Aes*)aes, key, (word32)((bits)/8), NULL, enc) != 0) { WOLFSSL_MSG("Error in setting AES key"); return WOLFSSL_FATAL_ERROR; } diff --git a/src/ssl_load.c b/src/ssl_load.c index a15274b23f..617c5c7cc2 100644 --- a/src/ssl_load.c +++ b/src/ssl_load.c @@ -1213,7 +1213,7 @@ static int ProcessBufferPrivPkcs8Dec(EncryptedInfo* info, DerBuffer* der, } if (ret >= 0) { /* Zero out encrypted data not overwritten. */ - ForceZero(der->buffer + ret, der->length - ret); + ForceZero(der->buffer + ret, der->length - (word32)ret); /* Set decrypted data length. */ der->length = (word32)ret; } @@ -5042,7 +5042,8 @@ int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa) if (ret == 1) { /* Allocate memory to hold DER encoding.. */ - der = (unsigned char*)XMALLOC(derSize, NULL, DYNAMIC_TYPE_TMP_BUFFER); + der = (unsigned char*)XMALLOC((size_t)derSize, NULL, + DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { WOLFSSL_MSG("Malloc failure"); ret = MEMORY_E; @@ -5284,8 +5285,8 @@ int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz, } if (ret == 1) { /* Copy p and g into allocated buffers. */ - XMEMCPY(pAlloc, p, pSz); - XMEMCPY(gAlloc, g, gSz); + XMEMCPY(pAlloc, p, (size_t)pSz); + XMEMCPY(gAlloc, g, (size_t)gSz); /* Set the buffers into SSL. */ ret = wolfssl_set_tmp_dh(ssl, pAlloc, pSz, gAlloc, gSz); } @@ -5443,8 +5444,8 @@ int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX* ctx, const unsigned char* p, int pSz, if (ret == 1) { /* Copy p and g into allocated buffers. */ - XMEMCPY(pAlloc, p, pSz); - XMEMCPY(gAlloc, g, gSz); + XMEMCPY(pAlloc, p, (size_t)pSz); + XMEMCPY(gAlloc, g, (size_t)gSz); /* Set the buffers into SSL context. */ ret = wolfssl_ctx_set_tmp_dh(ctx, pAlloc, pSz, gAlloc, gSz); } @@ -5496,8 +5497,8 @@ long wolfSSL_set_tmp_dh(WOLFSSL *ssl, WOLFSSL_DH *dh) if (ret == 1) { /* Allocate buffers for p and g to be assigned into SSL. */ - p = (byte*)XMALLOC(pSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); - g = (byte*)XMALLOC(gSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); + p = (byte*)XMALLOC((size_t)pSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); + g = (byte*)XMALLOC((size_t)gSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); if ((p == NULL) || (g == NULL)) { ret = MEMORY_E; } @@ -5562,8 +5563,8 @@ long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh) if (ret == 1) { /* Allocate buffers for p and g to be assigned into SSL. */ - p = (byte*)XMALLOC(pSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY); - g = (byte*)XMALLOC(gSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY); + p = (byte*)XMALLOC((size_t)pSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY); + g = (byte*)XMALLOC((size_t)gSz, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY); if ((p == NULL) || (g == NULL)) { ret = MEMORY_E; } diff --git a/src/ssl_sess.c b/src/ssl_sess.c index b1e03cbbbe..2f317f5ee7 100644 --- a/src/ssl_sess.c +++ b/src/ssl_sess.c @@ -375,7 +375,7 @@ int wolfSSL_SetServerID(WOLFSSL* ssl, const byte* id, int len, int newSession) WOLFSSL_MSG("Valid ServerID not cached already"); ssl->session->idLen = (word16)len; - XMEMCPY(ssl->session->serverID, id, len); + XMEMCPY(ssl->session->serverID, id, (size_t)len); } #ifdef HAVE_EXT_CACHE else { @@ -1821,7 +1821,7 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession, ticLen = addSession->ticketLen; /* Alloc Memory here to avoid syscalls during lock */ if (ticLen > SESSION_TICKET_LEN) { - ticBuff = (byte*)XMALLOC(ticLen, NULL, + ticBuff = (byte*)XMALLOC((size_t)ticLen, NULL, DYNAMIC_TYPE_SESSION_TICK); if (ticBuff == NULL) { return MEMORY_E; @@ -1980,7 +1980,7 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession, /* Copy in the certs from the session */ addSession->chain.count = cacheSession->chain.count; XMEMCPY(addSession->chain.certs, cacheSession->chain.certs, - sizeof(x509_buffer) * cacheSession->chain.count); + sizeof(x509_buffer) * (size_t)cacheSession->chain.count); } #endif /* SESSION_CERTS */ #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA) @@ -2671,7 +2671,8 @@ int wolfSSL_i2d_SSL_SESSION(WOLFSSL_SESSION* sess, unsigned char** p) unsigned char *data; if (*p == NULL) - *p = (unsigned char*)XMALLOC(size, NULL, DYNAMIC_TYPE_OPENSSL); + *p = (unsigned char*)XMALLOC((size_t)size, NULL, + DYNAMIC_TYPE_OPENSSL); if (*p == NULL) return 0; data = *p; @@ -2695,7 +2696,7 @@ int wolfSSL_i2d_SSL_SESSION(WOLFSSL_SESSION* sess, unsigned char** p) c16toa((word16)sess->chain.certs[i].length, data + idx); idx += OPAQUE16_LEN; XMEMCPY(data + idx, sess->chain.certs[i].buffer, - sess->chain.certs[i].length); + (size_t)sess->chain.certs[i].length); idx += sess->chain.certs[i].length; } #endif @@ -3522,7 +3523,7 @@ int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses, size = outSz; } - XMEMCPY(out, ses->masterSecret, size); + XMEMCPY(out, ses->masterSecret, (size_t)size); return size; } diff --git a/src/tls.c b/src/tls.c index 7618c696b6..87aedb4ef7 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1024,7 +1024,7 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, if (ret != 0) return ret; - XMEMSET(hmac->innerHash, 0, macLen); + XMEMSET(hmac->innerHash, 0, (size_t)macLen); if (safeBlocks > 0) { ret = Hmac_HashUpdate(hmac, header, headerSz); @@ -1039,7 +1039,7 @@ static int Hmac_UpdateFinal_CT(Hmac* hmac, byte* digest, const byte* in, else safeBlocks = 0; - XMEMSET(digest, 0, macLen); + XMEMSET(digest, 0, (size_t)macLen); k = (unsigned int)(safeBlocks * blockSz); for (i = safeBlocks; i < blocks; i++) { unsigned char hashBlock[WC_MAX_BLOCK_SIZE]; @@ -1190,8 +1190,8 @@ static int Hmac_UpdateFinal(Hmac* hmac, byte* digest, const byte* in, ret = wc_HmacUpdate(hmac, header, headerSz); if (ret == 0) { /* Fill the rest of the block with any available data. */ - word32 currSz = ctMaskLT((int)msgSz, blockSz) & msgSz; - currSz |= ctMaskGTE((int)msgSz, blockSz) & blockSz; + word32 currSz = ctMaskLT((int)msgSz, (int)blockSz) & msgSz; + currSz |= ctMaskGTE((int)msgSz, (int)blockSz) & blockSz; currSz -= WOLFSSL_TLS_HMAC_INNER_SZ; currSz &= ~(0 - (currSz >> 31)); ret = wc_HmacUpdate(hmac, in, currSz); @@ -1338,7 +1338,7 @@ int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in, word32 sz, int padSz, #ifdef HAVE_BLAKE2 if (wolfSSL_GetHmacType(ssl) == WC_HASH_TYPE_BLAKE2B) { ret = Hmac_UpdateFinal(&hmac, digest, in, - sz + hashSz + padSz + 1, myInner, innerSz); + sz + hashSz + (word32)padSz + 1, myInner, innerSz); } else #endif @@ -3451,7 +3451,7 @@ static int TLSX_CSR_Parse(WOLFSSL* ssl, const byte* input, word16 length, if (request) { XMEMCPY(request->nonce, csr->request.ocsp[0].nonce, - csr->request.ocsp[0].nonceSz); + (size_t)csr->request.ocsp[0].nonceSz); request->nonceSz = csr->request.ocsp[0].nonceSz; } } @@ -3655,14 +3655,14 @@ int TLSX_CSR_InitRequest_ex(TLSX* extensions, DecodedCert* cert, csr->requests--; } /* preserve nonce */ - XMEMCPY(nonce, request->nonce, nonceSz); + XMEMCPY(nonce, csr->request.ocsp->nonce, (size_t)nonceSz); if (req_cnt < MAX_CERT_EXTENSIONS) { if ((ret = InitOcspRequest(request, cert, 0, heap)) != 0) return ret; /* restore nonce */ - XMEMCPY(request->nonce, nonce, nonceSz); + XMEMCPY(csr->request.ocsp->nonce, nonce, (size_t)nonceSz); request->nonceSz = nonceSz; csr->requests++; } @@ -3977,7 +3977,7 @@ static int TLSX_CSR2_Parse(WOLFSSL* ssl, const byte* input, word16 length, if (request) { XMEMCPY(request->nonce, csr2->request.ocsp[0].nonce, - csr2->request.ocsp[0].nonceSz); + (size_t)csr2->request.ocsp[0].nonceSz); request->nonceSz = csr2->request.ocsp[0].nonceSz; @@ -4189,7 +4189,8 @@ int TLSX_CSR2_InitRequests(TLSX* extensions, DecodedCert* cert, byte isPeer, int nonceSz = csr2->request.ocsp[0].nonceSz; /* preserve nonce, replicating nonce of ocsp[0] */ - XMEMCPY(nonce, csr2->request.ocsp[0].nonce, nonceSz); + XMEMCPY(nonce, csr2->request.ocsp[0].nonce, + (size_t)nonceSz); if ((ret = InitOcspRequest( &csr2->request.ocsp[csr2->requests], cert, @@ -4198,7 +4199,7 @@ int TLSX_CSR2_InitRequests(TLSX* extensions, DecodedCert* cert, byte isPeer, /* restore nonce */ XMEMCPY(csr2->request.ocsp[csr2->requests].nonce, - nonce, nonceSz); + nonce, (size_t)nonceSz); csr2->request.ocsp[csr2->requests].nonceSz = nonceSz; csr2->requests++; } diff --git a/src/tls13.c b/src/tls13.c index 0d5a8b9365..08174467e9 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -7430,7 +7430,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType) /* replace the last 8 bytes of server random with the accept */ if (((WOLFSSL_ECH*)echX->data)->state == ECH_PARSED_INTERNAL) { ret = EchWriteAcceptance(ssl, output + RECORD_HEADER_SZ, - serverRandomOffset - RECORD_HEADER_SZ, + (int)serverRandomOffset - RECORD_HEADER_SZ, sendSz - RECORD_HEADER_SZ); /* remove ech so we don't keep sending it in write */ diff --git a/src/wolfio.c b/src/wolfio.c index 8d0b2f089b..ec793f6f52 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -1475,7 +1475,8 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec) sin = (SOCKADDR_IN *)&addr; sin->sin_family = AF_INET; sin->sin_port = XHTONS(port); - XMEMCPY(&sin->sin_addr.s_addr, entry->h_addr_list[0], entry->h_length); + XMEMCPY(&sin->sin_addr.s_addr, entry->h_addr_list[0], + (size_t)entry->h_length); #endif } diff --git a/tests/api.c b/tests/api.c index e7b64124a6..c288c676c8 100644 --- a/tests/api.c +++ b/tests/api.c @@ -844,7 +844,7 @@ static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data, if (bio->wrSz - bio->wrIdx < len) { len = bio->wrSz - bio->wrIdx; } - XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len); + XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, (size_t)len); bio->wrIdx += len; } @@ -860,7 +860,7 @@ static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len) if (bio->wrSz - bio->rdIdx < len) { len = bio->wrSz - bio->rdIdx; } - XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len); + XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, (size_t)len); bio->rdIdx += len; } @@ -2466,7 +2466,7 @@ static int test_wolfSSL_CTX_load_verify_locations(void) /* Get cert cache size */ ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0); - ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL, + ExpectNotNull(cache = (byte*)XMALLOC((size_t)cacheSz, NULL, DYNAMIC_TYPE_TMP_BUFFER)); ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL), @@ -3259,7 +3259,7 @@ static int test_wolfSSL_CertManagerNameConstraint(void) WOLFSSL_FILETYPE_ASN1)); ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz)); if (EXPECT_SUCCESS() && (der != NULL)) { - XMEMCPY(der, pt, derSz); + XMEMCPY(der, pt, (size_t)derSz); /* find the name constraint extension and alter it */ pt = der; diff --git a/wolfcrypt/src/cmac.c b/wolfcrypt/src/cmac.c index 2f5d5d40f5..ffa98e4d96 100644 --- a/wolfcrypt/src/cmac.c +++ b/wolfcrypt/src/cmac.c @@ -212,7 +212,7 @@ int wc_CmacUpdate(Cmac* cmac, const byte* in, word32 inSz) #endif { ret = wc_CryptoCb_Cmac(cmac, NULL, 0, in, inSz, - NULL, NULL, cmac->type, NULL); + NULL, NULL, (int)cmac->type, NULL); if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) return ret; /* fall-through when unavailable */ @@ -294,8 +294,8 @@ int wc_CmacFinalNoFree(Cmac* cmac, byte* out, word32* outSz) if (cmac->devId != INVALID_DEVID) #endif { - ret = wc_CryptoCb_Cmac(cmac, NULL, 0, NULL, 0, out, outSz, cmac->type, - NULL); + ret = wc_CryptoCb_Cmac(cmac, NULL, 0, NULL, 0, out, outSz, + (int)cmac->type, NULL); if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) return ret; diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 519a56ae82..6f53af9941 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -6293,14 +6293,16 @@ void wolfSSL_EVP_init(void) case WC_AES_256_OFB_TYPE: #endif wc_AesFree(&ctx->cipher.aes); - ctx->flags &= ~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED; + ctx->flags &= + (unsigned long)~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED; break; #if defined(WOLFSSL_AES_XTS) && \ (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3)) case WC_AES_128_XTS_TYPE: case WC_AES_256_XTS_TYPE: wc_AesXtsFree(&ctx->cipher.xts); - ctx->flags &= ~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED; + ctx->flags &= + (unsigned long)~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED; break; #endif #endif /* AES */ diff --git a/wolfcrypt/src/kdf.c b/wolfcrypt/src/kdf.c index 302cabc1b8..b0d1e7b57b 100644 --- a/wolfcrypt/src/kdf.c +++ b/wolfcrypt/src/kdf.c @@ -813,7 +813,7 @@ int wc_SSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz, return BAD_FUNC_ARG; } - ret = wc_HmacSizeByType(enmhashId); + ret = wc_HmacSizeByType((int)enmhashId); if (ret <= 0) { return BAD_FUNC_ARG; } diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index d548cd6149..d4c47e57f4 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -904,7 +904,7 @@ unsigned long wc_PeekErrorNodeLineData(const char **file, int *line, * Get the error value at the HEAD of the ERR queue or 0 if the queue * is empty. The HEAD entry is removed by this call. */ -unsigned long wc_GetErrorNodeErr(void) +int wc_GetErrorNodeErr(void) { int ret; @@ -923,7 +923,7 @@ unsigned long wc_GetErrorNodeErr(void) wc_ClearErrorNodes(); } } - return (unsigned long)ret; + return ret; } #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) @@ -1171,7 +1171,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file) sz = WOLFSSL_MAX_ERROR_SZ - 1; } if (sz > 0) { - XMEMCPY(err->error, buf, sz); + XMEMCPY(err->error, buf, (size_t)sz); } sz = (int)XSTRLEN(file); @@ -1179,7 +1179,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file) sz = WOLFSSL_MAX_ERROR_SZ - 1; } if (sz > 0) { - XMEMCPY(err->file, file, sz); + XMEMCPY(err->file, file, (size_t)sz); } err->value = error; @@ -1420,7 +1420,7 @@ unsigned long wc_PeekErrorNodeLineData(const char **file, int *line, } } -unsigned long wc_GetErrorNodeErr(void) +int wc_GetErrorNodeErr(void) { int ret; @@ -1428,7 +1428,7 @@ unsigned long wc_GetErrorNodeErr(void) if (ERRQ_LOCK() != 0) { WOLFSSL_MSG("Lock debug mutex failed"); - return (unsigned long)(0 - BAD_MUTEX_E); + return (0 - BAD_MUTEX_E); } ret = pullErrorNode(NULL, NULL, NULL); @@ -1595,10 +1595,10 @@ unsigned long wc_PeekErrorNodeLineData(const char **file, int *line, return (unsigned long)(0 - NOT_COMPILED_IN); } -unsigned long wc_GetErrorNodeErr(void) +int wc_GetErrorNodeErr(void) { WOLFSSL_ENTER("wc_GetErrorNodeErr"); - return (unsigned long)(0 - NOT_COMPILED_IN); + return (0 - NOT_COMPILED_IN); } #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c index 55477dfd1b..f5a524d380 100644 --- a/wolfcrypt/src/misc.c +++ b/wolfcrypt/src/misc.c @@ -118,14 +118,14 @@ masking and clearing memory logic. /* This routine performs a left circular arithmetic shift of by value */ WC_MISC_STATIC WC_INLINE word16 rotlFixed16(word16 x, word16 y) { - return (x << y) | (x >> (sizeof(x) * 8 - y)); + return (word16)((x << y) | (x >> (sizeof(x) * 8 - y))); } /* This routine performs a right circular arithmetic shift of by value */ WC_MISC_STATIC WC_INLINE word16 rotrFixed16(word16 x, word16 y) { - return (x >> y) | (x << (sizeof(x) * 8 - y)); + return (word16)((x >> y) | (x << (sizeof(x) * 8 - y))); } /* This routine performs a byte swap of 32-bit word value. */ diff --git a/wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c b/wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c index e1ec04cc5e..462cea7fc1 100644 --- a/wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c +++ b/wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c @@ -301,9 +301,9 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmEncrypt(struct Aes* aes, byte* out, * Aes.ctx.tsip_keyIdx is not used here. */ key_client_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); key_server_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); if (key_client_aes == NULL || key_server_aes == NULL) { XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES); XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES); @@ -505,9 +505,9 @@ WOLFSSL_LOCAL int wc_fspsm_AesGcmDecrypt(struct Aes* aes, byte* out, * Aes.ctx.tsip_keyIdx is not used here. */ key_client_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); key_server_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); if (key_client_aes == NULL || key_server_aes == NULL) { XFREE(plainBuf, aes->heap, DYNAMIC_TYPE_AES); XFREE(cipherBuf, aes->heap, DYNAMIC_TYPE_AES); diff --git a/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c b/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c index ab0082e1e6..da1ff1aaf8 100644 --- a/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c +++ b/wolfcrypt/src/port/Renesas/renesas_fspsm_util.c @@ -749,9 +749,9 @@ WOLFSSL_LOCAL int wc_fspsm_generateSessionKey(WOLFSSL *ssl, } else { key_client_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); key_server_aes = (FSPSM_AES_PWKEY)XMALLOC(sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); if (key_client_aes == NULL || key_server_aes == NULL) { return MEMORY_E; } @@ -790,7 +790,7 @@ WOLFSSL_LOCAL int wc_fspsm_generateSessionKey(WOLFSSL *ssl, XMEMSET(enc->aes, 0, sizeof(Aes)); enc->aes->ctx.wrapped_key = (FSPSM_AES_PWKEY)XMALLOC (sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); if (enc->aes->ctx.wrapped_key == NULL) return MEMORY_E; } @@ -808,7 +808,7 @@ WOLFSSL_LOCAL int wc_fspsm_generateSessionKey(WOLFSSL *ssl, dec->aes->ctx.wrapped_key = (FSPSM_AES_PWKEY)XMALLOC (sizeof(FSPSM_AES_WKEY), - aes->heap, DYNAMIC_TYPE_AE); + aes->heap, DYNAMIC_TYPE_AES); if (dec->aes->ctx.wrapped_key == NULL) return MEMORY_E; } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index cfc618afa3..0c877ef301 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -845,7 +845,7 @@ static void render_error_message(const char* msg, wc_test_ret_t es) #else err_sys_printf("%s error L=%d code=%d (%s)\n", msg, WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es), - wolfSSL_ERR_reason_error_string(-WC_TEST_RET_DEC_I(es)) + wolfSSL_ERR_reason_error_string((unsigned long)-WC_TEST_RET_DEC_I(es)) ); #endif break; @@ -9134,7 +9134,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, return MEMORY_E; #endif - cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + cipher = (byte*)XMALLOC((size_t)plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (cipher == NULL) { ret = WC_TEST_RET_ENC_ERRNO; goto EVP_TEST_END; @@ -9160,7 +9160,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key, } cipherSz += idx; - if (XMEMCMP(cipher, expected, plainSz)) { + if (XMEMCMP(cipher, expected, (size_t)plainSz)) { ret = WC_TEST_RET_ENC_NC; goto EVP_TEST_END; } diff --git a/wolfssl/wolfcrypt/logging.h b/wolfssl/wolfcrypt/logging.h index a60f70b499..354fa5e4c4 100644 --- a/wolfssl/wolfcrypt/logging.h +++ b/wolfssl/wolfcrypt/logging.h @@ -135,7 +135,7 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix); WOLFSSL_LOCAL unsigned long wc_PeekErrorNodeLineData( const char **file, int *line, const char **data, int *flags, int (*ignore_err)(int err)); - WOLFSSL_LOCAL unsigned long wc_GetErrorNodeErr(void); + WOLFSSL_LOCAL int wc_GetErrorNodeErr(void); #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) WOLFSSL_API void wc_ERR_print_errors_fp(XFILE fp); WOLFSSL_API void wc_ERR_print_errors_cb(int (*cb)(const char *str,