Type conversion fixes: make explicit

Changed to types and casting so that there are no implcit conversion
warnings (gcc -Wconversion) in these files.
This commit is contained in:
Sean Parkinson
2023-07-12 12:11:01 +10:00
parent 62c14e4d5b
commit 2c9609039d
15 changed files with 1260 additions and 1222 deletions

View File

@@ -329,7 +329,7 @@ int main(int argc, char* argv[])
/* Default to reading STDIN. */ /* Default to reading STDIN. */
FILE* fp = stdin; FILE* fp = stdin;
int file_format = FORMAT_DER; int file_format = FORMAT_DER;
int indent = 0; word32 indent = 0;
int pem_skip = 0; int pem_skip = 0;
/* Reset options. */ /* Reset options. */
@@ -376,7 +376,7 @@ int main(int argc, char* argv[])
argc--; argc--;
argv++; argv++;
wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_LENGTH, wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_LENGTH,
atoi(argv[0])); (word32)atoi(argv[0]));
} }
/* Do not show text representations of ASN.1 item data. */ /* Do not show text representations of ASN.1 item data. */
else if ((strcmp(argv[0], "-n") == 0) || else if ((strcmp(argv[0], "-n") == 0) ||
@@ -398,7 +398,7 @@ int main(int argc, char* argv[])
argc--; argc--;
argv++; argv++;
wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_OFFSET, wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_OFFSET,
atoi(argv[0])); (word32)atoi(argv[0]));
} }
/* Show wolfSSL OID value for all OBJECT_IDs. */ /* Show wolfSSL OID value for all OBJECT_IDs. */
else if ((strcmp(argv[0], "-O") == 0) || else if ((strcmp(argv[0], "-O") == 0) ||

View File

@@ -233,7 +233,7 @@ static int password_from_userdata(char* passwd, int sz, int rw, void* userdata)
{ {
(void)rw; (void)rw;
/* Copy user data into buffer. */ /* Copy user data into buffer. */
strncpy(passwd, (const char*)userdata, sz); strncpy(passwd, (const char*)userdata, (size_t)sz);
passwd[sz - 1] = '\0'; passwd[sz - 1] = '\0';
/* Return length of password returned. */ /* Return length of password returned. */
return (int)XSTRLEN((const char*)passwd); return (int)XSTRLEN((const char*)passwd);
@@ -397,7 +397,7 @@ static int ConvPemToDer(char* in, word32 offset, word32 len, DerBuffer** der,
/* Remove padding from encryption if requested. */ /* Remove padding from encryption if requested. */
if ((ret == 0) && padding) { if ((ret == 0) && padding) {
unsigned char pad = (*der)->buffer[(*der)->length - 1]; unsigned char pad = (*der)->buffer[(*der)->length - 1];
int i; word32 i;
/* Simple padding validation. */ /* Simple padding validation. */
if ((pad == 0) || (pad > (*der)->length)) { if ((pad == 0) || (pad > (*der)->length)) {
@@ -553,8 +553,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
if (ret == 0) { if (ret == 0) {
/* Get length of encrypted DER data. */ /* Get length of encrypted DER data. */
ret = wc_CreateEncryptedPKCS8Key(in, in_len, NULL, enc_len, password, ret = wc_CreateEncryptedPKCS8Key(in, in_len, NULL, enc_len, password,
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz, (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz,
iterations, &rng, NULL); (int)iterations, &rng, NULL);
if (ret == LENGTH_ONLY_E) { if (ret == LENGTH_ONLY_E) {
ret = 0; ret = 0;
} }
@@ -572,8 +572,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
if (ret == 0) { if (ret == 0) {
/* Encrypt DER data. */ /* Encrypt DER data. */
ret = wc_CreateEncryptedPKCS8Key(in, in_len, *enc, enc_len, password, ret = wc_CreateEncryptedPKCS8Key(in, in_len, *enc, enc_len, password,
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz, (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz,
iterations, &rng, NULL); (int)iterations, &rng, NULL);
if (ret > 0) { if (ret > 0) {
ret = 0; ret = 0;
} }
@@ -601,7 +601,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
{ {
int ret = 0; int ret = 0;
unsigned char* pem = NULL; unsigned char* pem = NULL;
int pem_len = 0; unsigned int pem_len = 0;
/* Set point to start looking and length. */ /* Set point to start looking and length. */
unsigned char* der = in + offset; unsigned char* der = in + offset;
word32 der_len = len - offset; word32 der_len = len - offset;
@@ -611,7 +611,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
if (ret <= 0) { if (ret <= 0) {
fprintf(stderr, "Could not determine length of PEM\n"); fprintf(stderr, "Could not determine length of PEM\n");
} }
pem_len = ret; pem_len = (unsigned int)ret;
if (ret > 0) { if (ret > 0) {
ret = 0; ret = 0;
} }
@@ -631,7 +631,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
} }
if (ret > 0) { if (ret > 0) {
*out = pem; *out = pem;
*out_len = ret; *out_len = (word32)ret;
ret = 0; ret = 0;
} }
} }

View File

@@ -291,15 +291,16 @@ static WC_INLINE int wolfssl_cm_get_certs_der(WOLFSSL_CERT_MANAGER* cm,
if (!err) { if (!err) {
/* Allocate memory for pointers to each DER buffer. */ /* Allocate memory for pointers to each DER buffer. */
certBuffers = (DerBuffer**)XMALLOC(sizeof(DerBuffer*) * numCerts, certBuffers = (DerBuffer**)XMALLOC(
cm->heap, DYNAMIC_TYPE_TMP_BUFFER); sizeof(DerBuffer*) * (size_t)numCerts, cm->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (certBuffers == NULL) { if (certBuffers == NULL) {
err = 1; err = 1;
} }
} }
if (!err) { if (!err) {
/* Reset pointers. */ /* Reset pointers. */
XMEMSET(certBuffers, 0, sizeof(DerBuffer*) * numCerts); XMEMSET(certBuffers, 0, sizeof(DerBuffer*) * (size_t)numCerts);
} }
/* Copy the certs locally so that we can release the caLock. If the lock /* Copy the certs locally so that we can release the caLock. If the lock
@@ -382,7 +383,7 @@ WOLFSSL_STACK* wolfSSL_CertManagerGetCerts(WOLFSSL_CERT_MANAGER* cm)
/* Get pointer to DER encoding of certificate. */ /* Get pointer to DER encoding of certificate. */
derBuffer = certBuffers[i]->buffer; derBuffer = certBuffers[i]->buffer;
/* Decode certificate. */ /* Decode certificate. */
wolfSSL_d2i_X509(&x509, &derBuffer, certBuffers[i]->length); wolfSSL_d2i_X509(&x509, &derBuffer, (int)certBuffers[i]->length);
if (x509 == NULL) { if (x509 == NULL) {
err = 1; err = 1;
} }
@@ -816,13 +817,13 @@ int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* fname,
#endif #endif
{ {
WOLFSSL_MSG("Getting dynamic buffer"); WOLFSSL_MSG("Getting dynamic buffer");
buff = (byte*)XMALLOC(sz, cm->heap, DYNAMIC_TYPE_FILE); buff = (byte*)XMALLOC((size_t)sz, cm->heap, DYNAMIC_TYPE_FILE);
if (buff == NULL) { if (buff == NULL) {
ret = WOLFSSL_BAD_FILE; ret = WOLFSSL_BAD_FILE;
} }
} }
/* Read all the file into buffer. */ /* Read all the file into buffer. */
if ((ret == WOLFSSL_SUCCESS) && ((size_t)XFREAD(buff, 1, sz, file) != if ((ret == WOLFSSL_SUCCESS) && (XFREAD(buff, 1, (size_t)sz, file) !=
(size_t)sz)) { (size_t)sz)) {
ret = WOLFSSL_BAD_FILE; ret = WOLFSSL_BAD_FILE;
} }
@@ -942,7 +943,7 @@ static WC_INLINE int cm_get_signer_memory(Signer* signer)
#endif #endif
/* Add dynamic bytes needed. */ /* Add dynamic bytes needed. */
sz += signer->pubKeySize; sz += (int)signer->pubKeySize;
sz += signer->nameLen; sz += signer->nameLen;
return sz; return sz;
@@ -1103,7 +1104,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
/* Copy in public key. */ /* Copy in public key. */
XMEMCPY(publicKey, current + idx, signer->pubKeySize); XMEMCPY(publicKey, current + idx, signer->pubKeySize);
signer->publicKey = publicKey; signer->publicKey = publicKey;
idx += signer->pubKeySize; idx += (int)signer->pubKeySize;
/* Copy in certificate name length. */ /* Copy in certificate name length. */
XMEMCPY(&signer->nameLen, current + idx, sizeof(signer->nameLen)); XMEMCPY(&signer->nameLen, current + idx, sizeof(signer->nameLen));
@@ -1117,7 +1118,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
} }
if (ret == 0) { if (ret == 0) {
/* Allocate memory for public key to be stored in. */ /* Allocate memory for public key to be stored in. */
signer->name = (char*)XMALLOC(signer->nameLen, cm->heap, signer->name = (char*)XMALLOC((size_t)signer->nameLen, cm->heap,
DYNAMIC_TYPE_SUBJECT_CN); DYNAMIC_TYPE_SUBJECT_CN);
if (signer->name == NULL) { if (signer->name == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
@@ -1126,7 +1127,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
if (ret == 0) { if (ret == 0) {
/* Copy in certificate name. */ /* Copy in certificate name. */
XMEMCPY(signer->name, current + idx, signer->nameLen); XMEMCPY(signer->name, current + idx, (size_t)signer->nameLen);
idx += signer->nameLen; idx += signer->nameLen;
/* Copy in hash of subject name. */ /* Copy in hash of subject name. */
@@ -1190,15 +1191,15 @@ static WC_INLINE int cm_store_cert_row(WOLFSSL_CERT_MANAGER* cm, byte* current,
added += (int)sizeof(list->keyOID); added += (int)sizeof(list->keyOID);
/* Public key. */ /* Public key. */
XMEMCPY(current + added, list->publicKey, list->pubKeySize); XMEMCPY(current + added, list->publicKey, (size_t)list->pubKeySize);
added += list->pubKeySize; added += (int)list->pubKeySize;
/* Certificate name length. */ /* Certificate name length. */
XMEMCPY(current + added, &list->nameLen, sizeof(list->nameLen)); XMEMCPY(current + added, &list->nameLen, sizeof(list->nameLen));
added += (int)sizeof(list->nameLen); added += (int)sizeof(list->nameLen);
/* Certificate name. */ /* Certificate name. */
XMEMCPY(current + added, list->name, list->nameLen); XMEMCPY(current + added, list->name, (size_t)list->nameLen);
added += list->nameLen; added += list->nameLen;
/* Hash of subject name. */ /* Hash of subject name. */
@@ -1287,8 +1288,6 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname)
{ {
XFILE file; XFILE file;
int ret = WOLFSSL_SUCCESS; int ret = WOLFSSL_SUCCESS;
int memSz;
byte* mem;
WOLFSSL_ENTER("CM_SaveCertCache"); WOLFSSL_ENTER("CM_SaveCertCache");
@@ -1306,17 +1305,18 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname)
} }
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
byte* mem;
/* Calculate size of memory required to store CA table. */ /* Calculate size of memory required to store CA table. */
memSz = cm_get_cert_cache_mem_size(cm); size_t memSz = (size_t)cm_get_cert_cache_mem_size(cm);
/* Allocate memory to hold CA table. */ /* Allocate memory to hold CA table. */
mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (mem == NULL) { if (mem == NULL) {
WOLFSSL_MSG("Alloc for tmp buffer failed"); WOLFSSL_MSG("Alloc for tmp buffer failed");
ret = MEMORY_E; ret = MEMORY_E;
} }
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
/* Store CA table in memory. */ /* Store CA table in memory. */
ret = cm_do_mem_save_cert_cache(cm, mem, memSz); ret = cm_do_mem_save_cert_cache(cm, mem, (int)memSz);
} }
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
/* Write memory to file. */ /* Write memory to file. */
@@ -1753,7 +1753,7 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
#endif #endif
{ {
/* Initialize decoded certificate with buffer. */ /* Initialize decoded certificate with buffer. */
InitDecodedCert(cert, der, sz, NULL); InitDecodedCert(cert, der, (word32)sz, NULL);
/* Parse certificate and perform CRL checks. */ /* Parse certificate and perform CRL checks. */
ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_CRL, cm); ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_CRL, cm);
@@ -2224,7 +2224,7 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
#endif #endif
{ {
/* Initialize decoded certificate with buffer. */ /* Initialize decoded certificate with buffer. */
InitDecodedCert(cert, der, sz, NULL); InitDecodedCert(cert, der, (word32)sz, NULL);
/* Parse certificate and perform CRL checks. */ /* Parse certificate and perform CRL checks. */
ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_OCSP, cm); ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_OCSP, cm);
@@ -2307,14 +2307,14 @@ int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER* cm,
/* Calculate size of URL string. Include terminator character. */ /* Calculate size of URL string. Include terminator character. */
int urlSz = (int)XSTRLEN(url) + 1; int urlSz = (int)XSTRLEN(url) + 1;
/* Allocate memory for URL to be copied into. */ /* Allocate memory for URL to be copied into. */
cm->ocspOverrideURL = (char*)XMALLOC(urlSz, cm->heap, cm->ocspOverrideURL = (char*)XMALLOC((size_t)urlSz, cm->heap,
DYNAMIC_TYPE_URL); DYNAMIC_TYPE_URL);
if (cm->ocspOverrideURL == NULL) { if (cm->ocspOverrideURL == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
} }
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
/* Copy URL into certificate manager. */ /* Copy URL into certificate manager. */
XMEMCPY(cm->ocspOverrideURL, url, urlSz); XMEMCPY(cm->ocspOverrideURL, url, (size_t)urlSz);
} }
} }
else { else {

View File

@@ -11975,7 +11975,7 @@ static int StoreRsaKey(DecodedCert* cert, const byte* source, word32* srcIdx,
#ifdef HAVE_OCSP #ifdef HAVE_OCSP
/* Calculate the hash of the public key for OCSP. */ /* Calculate the hash of the public key for OCSP. */
ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize, ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize,
cert->subjectKeyHash, HashIdAlg((int)cert->signatureOID)); cert->subjectKeyHash, HashIdAlg(cert->signatureOID));
#endif #endif
} }
@@ -12128,7 +12128,7 @@ static int StoreEccKey(DecodedCert* cert, const byte* source, word32* srcIdx,
/* Calculate the hash of the subject public key for OCSP. */ /* Calculate the hash of the subject public key for OCSP. */
ret = CalcHashId_ex(dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.data, ret = CalcHashId_ex(dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.data,
dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.length, dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.length,
cert->subjectKeyHash, HashIdAlg((int)cert->signatureOID)); cert->subjectKeyHash, HashIdAlg(cert->signatureOID));
} }
if (ret == 0) { if (ret == 0) {
#endif #endif
@@ -12452,7 +12452,7 @@ static int GetCertKey(DecodedCert* cert, const byte* source, word32* inOutIdx,
* @param [in] oidSum Signature id. * @param [in] oidSum Signature id.
* @return Hash algorithm id. * @return Hash algorithm id.
*/ */
int HashIdAlg(int oidSum) int HashIdAlg(word32 oidSum)
{ {
(void)oidSum; (void)oidSum;
@@ -12912,9 +12912,9 @@ static const byte rdnChoice[] = {
static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap) static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
{ {
int ret = 0; int ret = 0;
int nameSz; size_t nameSz;
char tmpName[WOLFSSL_MAX_IPSTR] = {0}; char tmpName[WOLFSSL_MAX_IPSTR] = {0};
char* ip; unsigned char* ip;
if (entry == NULL || entry->type != ASN_IP_TYPE) { if (entry == NULL || entry->type != ASN_IP_TYPE) {
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
@@ -12925,7 +12925,7 @@ static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
WOLFSSL_MSG("Unexpected IP size"); WOLFSSL_MSG("Unexpected IP size");
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
ip = entry->name; ip = (unsigned char*)entry->name;
/* store IP addresses as a string */ /* store IP addresses as a string */
if (entry->len == WOLFSSL_IP4_ADDR_LEN) { if (entry->len == WOLFSSL_IP4_ADDR_LEN) {
@@ -12939,7 +12939,7 @@ static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
} }
if (entry->len == WOLFSSL_IP6_ADDR_LEN) { if (entry->len == WOLFSSL_IP6_ADDR_LEN) {
int i; size_t i;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (XSNPRINTF(tmpName + i * 5, sizeof(tmpName) - i * 5, if (XSNPRINTF(tmpName + i * 5, sizeof(tmpName) - i * 5,
"%02X%02X%s", 0xFF & ip[2 * i], 0xFF & ip[2 * i + 1], "%02X%02X%s", 0xFF & ip[2 * i], 0xFF & ip[2 * i + 1],
@@ -12952,8 +12952,9 @@ static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
} }
} }
nameSz = (int)XSTRLEN(tmpName); nameSz = XSTRLEN(tmpName);
entry->ipString = (char*)XMALLOC(nameSz + 1, heap, DYNAMIC_TYPE_ALTNAME); entry->ipString = (char*)XMALLOC(nameSz + 1, heap,
DYNAMIC_TYPE_ALTNAME);
if (entry->ipString == NULL) { if (entry->ipString == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
} }
@@ -13951,7 +13952,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
* calculated over the entire DER encoding of the Name field, including * calculated over the entire DER encoding of the Name field, including
* the tag and length. */ * the tag and length. */
if (CalcHashId_ex(input + srcIdx, maxIdx - srcIdx, hash, if (CalcHashId_ex(input + srcIdx, maxIdx - srcIdx, hash,
HashIdAlg((int)cert->signatureOID)) != 0) { HashIdAlg(cert->signatureOID)) != 0) {
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
} }
@@ -14030,7 +14031,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
if (nid != 0) { if (nid != 0) {
/* Add an entry to the X509_NAME. */ /* Add an entry to the X509_NAME. */
if (wolfSSL_X509_NAME_add_entry_by_NID(dName, nid, enc, str, if (wolfSSL_X509_NAME_add_entry_by_NID(dName, nid, enc, str,
strLen, -1, -1) != WOLFSSL_SUCCESS) { (int)strLen, -1, -1) != WOLFSSL_SUCCESS) {
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
} }
} }
@@ -14050,15 +14051,17 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType,
#if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
defined(HAVE_LIGHTY)) && \ defined(HAVE_LIGHTY)) && \
(defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT)) (defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT))
dName->rawLen = min(cert->issuerRawLen, WC_ASN_NAME_MAX); dName->rawLen = (int)min((word32)cert->issuerRawLen,
XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen); WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->issuerRaw, (size_t)dName->rawLen);
#endif #endif
cert->issuerName = dName; cert->issuerName = dName;
} }
else { else {
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)
dName->rawLen = min(cert->subjectRawLen, WC_ASN_NAME_MAX); dName->rawLen = (int)min((word32)cert->subjectRawLen,
XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen); WC_ASN_NAME_MAX);
XMEMCPY(dName->raw, cert->subjectRaw, (size_t)dName->rawLen);
#endif #endif
cert->subjectName = dName; cert->subjectName = dName;
} }
@@ -14336,7 +14339,7 @@ int GetTimeString(byte* date, int format, char* buf, int len)
} }
idx = 4; /* use idx now for char buffer */ idx = 4; /* use idx now for char buffer */
if (XSNPRINTF(buf + idx, len - idx, "%2d %02d:%02d:%02d %d GMT", if (XSNPRINTF(buf + idx, (size_t)(len - idx), "%2d %02d:%02d:%02d %d GMT",
t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, (int)t.tm_year + 1900) t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, (int)t.tm_year + 1900)
>= len - idx) >= len - idx)
{ {
@@ -15239,7 +15242,7 @@ word32 SetOthername(void *name, byte *output)
{ {
WOLFSSL_ASN1_OTHERNAME *nm = (WOLFSSL_ASN1_OTHERNAME *)name; WOLFSSL_ASN1_OTHERNAME *nm = (WOLFSSL_ASN1_OTHERNAME *)name;
char *nameStr = NULL; char *nameStr = NULL;
int nameSz = 0; word32 nameSz = 0;
word32 len = 0; word32 len = 0;
if ((nm == NULL) || (nm->value == NULL)) { if ((nm == NULL) || (nm->value == NULL)) {
@@ -15248,7 +15251,7 @@ word32 SetOthername(void *name, byte *output)
} }
nameStr = nm->value->value.utf8string->data; nameStr = nm->value->value.utf8string->data;
nameSz = nm->value->value.utf8string->length; nameSz = (word32)nm->value->value.utf8string->length;
len = nm->type_id->objSz + len = nm->type_id->objSz +
SetHeader(ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC, nameSz + 2, NULL) + SetHeader(ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC, nameSz + 2, NULL) +
@@ -17573,7 +17576,7 @@ static int DecodeGeneralName(const byte* input, word32* inOutIdx, byte tag,
ret = SetDNSEntry(cert, (const char*)(input + idx), len, ASN_IP_TYPE, ret = SetDNSEntry(cert, (const char*)(input + idx), len, ASN_IP_TYPE,
&cert->altNames); &cert->altNames);
if (ret == 0) { if (ret == 0) {
idx += len; idx += (word32)len;
} }
} }
#endif /* WOLFSSL_QT || OPENSSL_ALL */ #endif /* WOLFSSL_QT || OPENSSL_ALL */
@@ -18757,7 +18760,7 @@ static int DecodeAuthInfo(const byte* input, word32 sz, DecodedCert* cert)
/* Set CaIssuers entry */ /* Set CaIssuers entry */
GetASN_GetConstRef(&dataASN[ACCESSDESCASN_IDX_LOC], GetASN_GetConstRef(&dataASN[ACCESSDESCASN_IDX_LOC],
&cert->extAuthInfoCaIssuer, &sz32); &cert->extAuthInfoCaIssuer, &sz32);
cert->extAuthInfoCaIssuerSz = sz32; cert->extAuthInfoCaIssuerSz = (int)sz32;
count++; count++;
} }
#endif #endif
@@ -18940,12 +18943,12 @@ static int DecodeSubjKeyId(const byte* input, word32 sz, DecodedCert* cert)
if (ret > 0) { if (ret > 0) {
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
cert->extSubjKeyIdSrc = &input[idx]; cert->extSubjKeyIdSrc = &input[idx];
cert->extSubjKeyIdSz = length; cert->extSubjKeyIdSz = (word32)length;
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
/* Get the hash or hash of the hash if wrong size. */ /* Get the hash or hash of the hash if wrong size. */
ret = GetHashId(input + idx, length, cert->extSubjKeyId, ret = GetHashId(input + idx, length, cert->extSubjKeyId,
HashIdAlg((int)cert->signatureOID)); HashIdAlg(cert->signatureOID));
} }
return ret; return ret;
@@ -19126,7 +19129,7 @@ static int DecodeExtKeyUsage(const byte* input, word32 sz, DecodedCert* cert)
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
/* Keep reference for WOLFSSL_X509. */ /* Keep reference for WOLFSSL_X509. */
cert->extExtKeyUsageSrc = input + idx; cert->extExtKeyUsageSrc = input + idx;
cert->extExtKeyUsageSz = length; cert->extExtKeyUsageSz = (word32)length;
#endif #endif
} }
@@ -19563,7 +19566,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
w = BUFFER_E; w = BUFFER_E;
goto exit; goto exit;
} }
outIdx += w; outIdx += (word32)w;
val = 0; val = 0;
while (inIdx < inSz && outIdx < outSz) { while (inIdx < inSz && outIdx < outSz) {
@@ -19581,7 +19584,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz)
w = BUFFER_E; w = BUFFER_E;
goto exit; goto exit;
} }
outIdx += w; outIdx += (word32)w;
val = 0; val = 0;
} }
inIdx++; inIdx++;
@@ -19872,7 +19875,7 @@ enum {
* @return ASN_PARSE_E when BER encoded data does not match ASN.1 items or * @return ASN_PARSE_E when BER encoded data does not match ASN.1 items or
* is invalid. * is invalid.
*/ */
static int DecodeSubjDirAttr(const byte* input, int sz, DecodedCert* cert) static int DecodeSubjDirAttr(const byte* input, word32 sz, DecodedCert* cert)
{ {
#ifndef WOLFSSL_ASN_TEMPLATE #ifndef WOLFSSL_ASN_TEMPLATE
word32 idx = 0; word32 idx = 0;
@@ -19969,7 +19972,8 @@ static int DecodeSubjDirAttr(const byte* input, int sz, DecodedCert* cert)
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
} }
if (ret == 0) { if (ret == 0) {
XMEMCPY(cert->countryOfCitizenship, setData + setIdx, cuLen); XMEMCPY(cert->countryOfCitizenship, setData + setIdx,
(size_t)cuLen);
cert->countryOfCitizenship[COUNTRY_CODE_LEN] = 0; cert->countryOfCitizenship[COUNTRY_CODE_LEN] = 0;
} }
} }
@@ -19994,7 +19998,7 @@ static int DecodeSubjDirAttr(const byte* input, int sz, DecodedCert* cert)
* is invalid. * is invalid.
* @return MEMORY_E on dynamic memory allocation failure. * @return MEMORY_E on dynamic memory allocation failure.
*/ */
static int DecodeSubjInfoAcc(const byte* input, int sz, DecodedCert* cert) static int DecodeSubjInfoAcc(const byte* input, word32 sz, DecodedCert* cert)
{ {
word32 idx = 0; word32 idx = 0;
int length = 0; int length = 0;
@@ -20047,11 +20051,11 @@ static int DecodeSubjInfoAcc(const byte* input, int sz, DecodedCert* cert)
/* Set caRepo entry */ /* Set caRepo entry */
if (b == GENERALNAME_URI && oid == AIA_CA_REPO_OID) { if (b == GENERALNAME_URI && oid == AIA_CA_REPO_OID) {
cert->extSubjInfoAccCaRepoSz = length; cert->extSubjInfoAccCaRepoSz = (word32)length;
cert->extSubjInfoAccCaRepo = input + idx; cert->extSubjInfoAccCaRepo = input + idx;
break; break;
} }
idx += length; idx += (word32)length;
} }
if (cert->extSubjInfoAccCaRepo == NULL || if (cert->extSubjInfoAccCaRepo == NULL ||
@@ -21522,7 +21526,7 @@ static Signer* GetCABySubjectAndPubKey(DecodedCert* cert, void* cm)
* is invalid. * is invalid.
* @return MEMORY_E on dynamic memory allocation failure. * @return MEMORY_E on dynamic memory allocation failure.
*/ */
static int GetAKIHash(const byte* input, word32 maxIdx, int sigOID, static int GetAKIHash(const byte* input, word32 maxIdx, word32 sigOID,
byte* hash, int* set, void* heap) byte* hash, int* set, void* heap)
{ {
/* AKI and Certificate Extenion ASN.1 templates are the same length. */ /* AKI and Certificate Extenion ASN.1 templates are the same length. */
@@ -21571,9 +21575,9 @@ static int GetAKIHash(const byte* input, word32 maxIdx, int sigOID,
*set = 1; *set = 1;
/* Get the hash or hash of the hash if wrong size. */ /* Get the hash or hash of the hash if wrong size. */
ret = GetHashId( ret = GetHashId(
dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data, dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data,
dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length, (int)dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length,
hash, HashIdAlg(sigOID)); hash, HashIdAlg(sigOID));
} }
break; break;
} }
@@ -22120,7 +22124,7 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap,
/* Extract public key information. */ /* Extract public key information. */
pubKey = ca->publicKey; pubKey = ca->publicKey;
pubKeySz = ca->pubKeySize; pubKeySz = ca->pubKeySize;
pubKeyOID = ca->keyOID; pubKeyOID = (int)ca->keyOID;
} }
else { else {
/* No public key to verify with. */ /* No public key to verify with. */
@@ -22142,7 +22146,8 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap,
/* Check signature. */ /* Check signature. */
ret = ConfirmSignature(sigCtx, tbs, tbsSz, pubKey, pubKeySz, ret = ConfirmSignature(sigCtx, tbs, tbsSz, pubKey, pubKeySz,
pubKeyOID, sig, sigSz, sigOID, sigParams, sigParamsSz, NULL); (word32)pubKeyOID, sig, sigSz, sigOID, sigParams, sigParamsSz,
NULL);
if (ret != 0) { if (ret != 0) {
WOLFSSL_MSG("Confirm signature failed"); WOLFSSL_MSG("Confirm signature failed");
} }
@@ -22281,7 +22286,7 @@ int wc_CertGetPubKey(const byte* cert, word32 certSz,
} }
/* Skip data if required. */ /* Skip data if required. */
else if (op.op == DECODE_INSTR_OVER) { else if (op.op == DECODE_INSTR_OVER) {
o += l; o += (word32)l;
} }
} }
} }
@@ -22290,7 +22295,7 @@ int wc_CertGetPubKey(const byte* cert, word32 certSz,
/* Return the public key data and length. /* Return the public key data and length.
* Skip first byte of BIT_STRING data: unused bits. */ * Skip first byte of BIT_STRING data: unused bits. */
*pubKey = cert + o + 1; *pubKey = cert + o + 1;
*pubKeySz = l - 1; *pubKeySz = (word32)(l - 1);
} }
return ret; return ret;
@@ -22601,11 +22606,11 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm)
/* TODO: GmSSL creates IDs this way but whole public key info /* TODO: GmSSL creates IDs this way but whole public key info
* block should be hashed. */ * block should be hashed. */
ret = CalcHashId_ex(cert->publicKey + cert->pubKeySize - 65, 65, ret = CalcHashId_ex(cert->publicKey + cert->pubKeySize - 65, 65,
cert->extSubjKeyId, HashIdAlg((int)cert->signatureOID)); cert->extSubjKeyId, HashIdAlg(cert->signatureOID));
} }
else { else {
ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize, ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize,
cert->extSubjKeyId, HashIdAlg((int)cert->signatureOID)); cert->extSubjKeyId, HashIdAlg(cert->signatureOID));
} }
if (ret != 0) { if (ret != 0) {
WOLFSSL_ERROR_VERBOSE(ret); WOLFSSL_ERROR_VERBOSE(ret);
@@ -23807,7 +23812,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
const char* bufferEnd = (const char*)(buff + longSz); const char* bufferEnd = (const char*)(buff + longSz);
long neededSz; long neededSz;
int ret = 0; int ret = 0;
int sz = (int)longSz; word32 sz = (word32)longSz;
int encrypted_key = 0; int encrypted_key = 0;
DerBuffer* der; DerBuffer* der;
word32 algId = 0; word32 algId = 0;
@@ -23826,7 +23831,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
/* map header if not found for type */ /* map header if not found for type */
for (;;) { for (;;) {
headerEnd = XSTRNSTR((char*)buff, header, (word32)sz); headerEnd = XSTRNSTR((char*)buff, header, sz);
if (headerEnd) { if (headerEnd) {
break; break;
} }
@@ -23909,7 +23914,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
headerEnd = XSTRNSTR((char*)buff, PRIV_KEY_SUFFIX, sz); headerEnd = XSTRNSTR((char*)buff, PRIV_KEY_SUFFIX, sz);
if (headerEnd) { if (headerEnd) {
const char* beginEnd; const char* beginEnd;
int endLen; unsigned int endLen;
beginEnd = headerEnd + XSTR_SIZEOF(PRIV_KEY_SUFFIX); beginEnd = headerEnd + XSTR_SIZEOF(PRIV_KEY_SUFFIX);
if (beginEnd >= (char*)buff + sz) { if (beginEnd >= (char*)buff + sz) {
@@ -23933,7 +23938,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
} }
/* headerEnd now points to beginning of header */ /* headerEnd now points to beginning of header */
XMEMCPY(beginBuf, headerEnd, beginEnd - headerEnd); XMEMCPY(beginBuf, headerEnd, (size_t)(beginEnd - headerEnd));
beginBuf[beginEnd - headerEnd] = '\0'; beginBuf[beginEnd - headerEnd] = '\0';
/* look for matching footer */ /* look for matching footer */
footer = XSTRNSTR(beginEnd, footer = XSTRNSTR(beginEnd,
@@ -23953,10 +23958,10 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
return BUFFER_E; return BUFFER_E;
} }
endLen = (unsigned int)(beginEnd - headerEnd - endLen = (unsigned int)((size_t)(beginEnd - headerEnd) -
(XSTR_SIZEOF(BEGIN_PRIV_KEY_PREFIX) - (XSTR_SIZEOF(BEGIN_PRIV_KEY_PREFIX) -
XSTR_SIZEOF(END_PRIV_KEY_PREFIX))); XSTR_SIZEOF(END_PRIV_KEY_PREFIX)));
XMEMCPY(endBuf, footer, endLen); XMEMCPY(endBuf, footer, (size_t)endLen);
endBuf[endLen] = '\0'; endBuf[endLen] = '\0';
header = beginBuf; header = beginBuf;
@@ -24042,7 +24047,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
/* set up der buffer */ /* set up der buffer */
neededSz = (long)(footerEnd - headerEnd); neededSz = (long)(footerEnd - headerEnd);
if (neededSz > sz || neededSz <= 0) if (neededSz > (long)sz || neededSz <= 0)
return BUFFER_E; return BUFFER_E;
ret = AllocDer(pDer, (word32)neededSz, type, heap); ret = AllocDer(pDer, (word32)neededSz, type, heap);
@@ -24679,7 +24684,7 @@ int wc_GetUUIDFromCert(struct DecodedCert* cert, byte* uuid, word32* uuidSz)
} }
if (uuid == NULL) { if (uuid == NULL) {
*uuidSz = id->len; *uuidSz = (word32)id->len;
return LENGTH_ONLY_E; return LENGTH_ONLY_E;
} }
@@ -24687,7 +24692,7 @@ int wc_GetUUIDFromCert(struct DecodedCert* cert, byte* uuid, word32* uuidSz)
return BUFFER_E; return BUFFER_E;
} }
XMEMCPY(uuid, id->name, id->len); XMEMCPY(uuid, id->name, (size_t)id->len);
ret = 0; /* success */ ret = 0; /* success */
break; break;
} }
@@ -24707,7 +24712,7 @@ int wc_GetFASCNFromCert(struct DecodedCert* cert, byte* fascn, word32* fascnSz)
id = FindAltName(cert, ASN_OTHER_TYPE, id); id = FindAltName(cert, ASN_OTHER_TYPE, id);
if (id != NULL && id->oidSum == FASCN_OID) { if (id != NULL && id->oidSum == FASCN_OID) {
if (fascn == NULL) { if (fascn == NULL) {
*fascnSz = id->len; *fascnSz = (word32)id->len;
return LENGTH_ONLY_E; return LENGTH_ONLY_E;
} }
@@ -24715,7 +24720,7 @@ int wc_GetFASCNFromCert(struct DecodedCert* cert, byte* fascn, word32* fascnSz)
return BUFFER_E; return BUFFER_E;
} }
XMEMCPY(fascn, id->name, id->len); XMEMCPY(fascn, id->name, (size_t)id->len);
ret = 0; /* success */ ret = 0; /* success */
} }
} while (id != NULL); } while (id != NULL);
@@ -27319,7 +27324,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz,
#ifdef WOLFSSL_AKID_NAME #ifdef WOLFSSL_AKID_NAME
if (cert->rawAkid) { if (cert->rawAkid) {
SetASN_Buffer(&dataASN[CERTEXTSASN_IDX_AKID_STR], SetASN_Buffer(&dataASN[CERTEXTSASN_IDX_AKID_STR],
cert->akid, cert->akidSz); cert->akid, (word32)cert->akidSz);
/* cert->akid contains the internal ext structure */ /* cert->akid contains the internal ext structure */
SetASNItem_NoOutBelow(dataASN, certExtsASN, SetASNItem_NoOutBelow(dataASN, certExtsASN,
CERTEXTSASN_IDX_AKID_STR, certExtsASN_Length); CERTEXTSASN_IDX_AKID_STR, certExtsASN_Length);
@@ -30155,7 +30160,7 @@ static int SetKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey,
/* Compute SKID by hashing public key */ /* Compute SKID by hashing public key */
if (kid_type == SKID_TYPE) { if (kid_type == SKID_TYPE) {
int hashId = HashIdAlg(cert->sigType); int hashId = HashIdAlg((word32)cert->sigType);
ret = CalcHashId_ex(buf, (word32)bufferSz, cert->skid, hashId); ret = CalcHashId_ex(buf, (word32)bufferSz, cert->skid, hashId);
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
cert->skidSz = wc_HashGetDigestSize(wc_HashTypeConvert(hashId)); cert->skidSz = wc_HashGetDigestSize(wc_HashTypeConvert(hashId));
@@ -30164,7 +30169,7 @@ static int SetKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey,
#endif #endif
} }
else if (kid_type == AKID_TYPE) { else if (kid_type == AKID_TYPE) {
int hashId = HashIdAlg(cert->sigType); int hashId = HashIdAlg((word32)cert->sigType);
ret = CalcHashId_ex(buf, (word32)bufferSz, cert->akid, hashId); ret = CalcHashId_ex(buf, (word32)bufferSz, cert->akid, hashId);
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
cert->akidSz = wc_HashGetDigestSize(wc_HashTypeConvert(hashId)); cert->akidSz = wc_HashGetDigestSize(wc_HashTypeConvert(hashId));
@@ -31318,7 +31323,7 @@ int StoreDHparams(byte* out, word32* outLen, mp_int* p, mp_int* g)
/* Encode the DH parameters into buffer. */ /* Encode the DH parameters into buffer. */
SetASN_Items(dhParamASN, dataASN, dhParamASN_Length, out); SetASN_Items(dhParamASN, dataASN, dhParamASN_Length, out);
/* Set the actual encoding size. */ /* Set the actual encoding size. */
*outLen = sz; *outLen = (word32)sz;
} }
return ret; return ret;
@@ -34116,8 +34121,8 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size,
if (ret == 0) { if (ret == 0) {
single->hashAlgoOID = single->hashAlgoOID =
dataASN[SINGLERESPONSEASN_IDX_CID_HASHALGO_OID].data.oid.sum; dataASN[SINGLERESPONSEASN_IDX_CID_HASHALGO_OID].data.oid.sum;
ocspDigestSize = wc_HashGetDigestSize( ocspDigestSize = (word32)wc_HashGetDigestSize(
wc_OidGetHash(single->hashAlgoOID)); wc_OidGetHash((int)single->hashAlgoOID));
} }
/* Validate the issuer hash length is the size required. */ /* Validate the issuer hash length is the size required. */
if ((ret == 0) && (issuerHashLen != ocspDigestSize)) { if ((ret == 0) && (issuerHashLen != ocspDigestSize)) {
@@ -34129,7 +34134,7 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size,
} }
if (ret == 0) { if (ret == 0) {
/* Store serial size. */ /* Store serial size. */
cs->serialSz = serialSz; cs->serialSz = (int)serialSz;
/* Set the hash algorithm OID */ /* Set the hash algorithm OID */
single->hashAlgoOID = single->hashAlgoOID =
dataASN[SINGLERESPONSEASN_IDX_CID_HASHALGO_OID].data.oid.sum; dataASN[SINGLERESPONSEASN_IDX_CID_HASHALGO_OID].data.oid.sum;
@@ -34163,7 +34168,7 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size,
at = &cs->thisDateParsed; at = &cs->thisDateParsed;
at->type = ASN_GENERALIZED_TIME; at->type = ASN_GENERALIZED_TIME;
XMEMCPY(at->data, cs->thisDate, thisDateLen); XMEMCPY(at->data, cs->thisDate, thisDateLen);
at->length = thisDateLen; at->length = (int)thisDateLen;
#endif #endif
} }
if ((ret == 0) && if ((ret == 0) &&
@@ -34187,7 +34192,7 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size,
at = &cs->nextDateParsed; at = &cs->nextDateParsed;
at->type = ASN_GENERALIZED_TIME; at->type = ASN_GENERALIZED_TIME;
XMEMCPY(at->data, cs->nextDate, nextDateLen); XMEMCPY(at->data, cs->nextDate, nextDateLen);
at->length = nextDateLen; at->length = (int)nextDateLen;
#endif #endif
} }
if (ret == 0) { if (ret == 0) {
@@ -34328,7 +34333,7 @@ static int DecodeOcspRespExtensions(byte* source, word32* ioIndex,
source, &idx, sz); source, &idx, sz);
if (ret == 0) { if (ret == 0) {
word32 oid = dataASN[CERTEXTASN_IDX_OID].data.oid.sum; word32 oid = dataASN[CERTEXTASN_IDX_OID].data.oid.sum;
int length = dataASN[CERTEXTASN_IDX_VAL].length; int length = (int)dataASN[CERTEXTASN_IDX_VAL].length;
if (oid == OCSP_NONCE_OID) { if (oid == OCSP_NONCE_OID) {
/* Extract nonce data. */ /* Extract nonce data. */
@@ -34343,7 +34348,7 @@ static int DecodeOcspRespExtensions(byte* source, word32* ioIndex,
/* Ignore all other extension types. */ /* Ignore all other extension types. */
/* Skip over rest of extension. */ /* Skip over rest of extension. */
idx += length; idx += (word32)length;
} }
} }
@@ -34563,8 +34568,8 @@ static int DecodeResponseData(byte* source, word32* ioIndex,
if (ret == 0) { if (ret == 0) {
/* Decode SingleResponse into OcspEntry. */ /* Decode SingleResponse into OcspEntry. */
ret = DecodeSingleResponse(source, &idx, ret = DecodeSingleResponse(source, &idx,
dataASN[OCSPRESPDATAASN_IDX_RESPEXT].offset, dataASN[OCSPRESPDATAASN_IDX_RESPEXT].offset,
dataASN[OCSPRESPDATAASN_IDX_RESP].length, single); (int)dataASN[OCSPRESPDATAASN_IDX_RESP].length, single);
/* single->used set on successful decode. */ /* single->used set on successful decode. */
} }
} }
@@ -35272,7 +35277,7 @@ word32 EncodeOcspRequestExtensions(OcspRequest* req, byte* output, word32 size)
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_OID], NonceObjId, SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_OID], NonceObjId,
sizeof(NonceObjId)); sizeof(NonceObjId));
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_NONCE], req->nonce, SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_NONCE], req->nonce,
req->nonceSz); (word32)req->nonceSz);
/* Calculate size of nonce extension. */ /* Calculate size of nonce extension. */
ret = SizeASN_Items(ocspNonceExtASN, dataASN, ocspNonceExtASN_Length, ret = SizeASN_Items(ocspNonceExtASN, dataASN, ocspNonceExtASN_Length,
&sz); &sz);
@@ -35293,7 +35298,7 @@ word32 EncodeOcspRequestExtensions(OcspRequest* req, byte* output, word32 size)
FREE_ASNSETDATA(dataASN, req->heap); FREE_ASNSETDATA(dataASN, req->heap);
} }
return ret; return (word32)ret;
#endif /* WOLFSSL_ASN_TEMPLATE */ #endif /* WOLFSSL_ASN_TEMPLATE */
} }
@@ -35429,7 +35434,7 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
word32 extSz = 0; word32 extSz = 0;
int sz = 0; int sz = 0;
int ret = 0; int ret = 0;
int keyIdSz; word32 keyIdSz;
WOLFSSL_ENTER("EncodeOcspRequest"); WOLFSSL_ENTER("EncodeOcspRequest");
@@ -35453,11 +35458,11 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_ISSUERKEY], SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_ISSUERKEY],
req->issuerKeyHash, keyIdSz); req->issuerKeyHash, keyIdSz);
SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_SERIAL], SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_SERIAL],
req->serial, req->serialSz); req->serial, (word32)req->serialSz);
/* Only extension to write is nonce - check if one to encode. */ /* Only extension to write is nonce - check if one to encode. */
if (req->nonceSz) { if (req->nonceSz) {
/* Get size of extensions and leave space for them in encoding. */ /* Get size of extensions and leave space for them in encoding. */
ret = extSz = EncodeOcspRequestExtensions(req, NULL, 0); ret = (int)(extSz = EncodeOcspRequestExtensions(req, NULL, 0));
SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQEXT], NULL, extSz); SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQEXT], NULL, extSz);
if (ret > 0) { if (ret > 0) {
ret = 0; ret = 0;
@@ -35482,7 +35487,7 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size)
SetASN_Items(ocspRequestASN, dataASN, ocspRequestASN_Length, output); SetASN_Items(ocspRequestASN, dataASN, ocspRequestASN_Length, output);
if (req->nonceSz) { if (req->nonceSz) {
/* Encode extensions into space provided. */ /* Encode extensions into space provided. */
ret = EncodeOcspRequestExtensions(req, ret = (int)EncodeOcspRequestExtensions(req,
(byte*)dataASN[OCSPREQUESTASN_IDX_TBS_REQEXT].data.buffer.data, (byte*)dataASN[OCSPREQUESTASN_IDX_TBS_REQEXT].data.buffer.data,
extSz); extSz);
if (ret > 0) { if (ret > 0) {
@@ -35519,24 +35524,24 @@ int InitOcspRequest(OcspRequest* req, DecodedCert* cert, byte useNonce,
XMEMCPY(req->issuerHash, cert->issuerHash, KEYID_SIZE); XMEMCPY(req->issuerHash, cert->issuerHash, KEYID_SIZE);
XMEMCPY(req->issuerKeyHash, cert->issuerKeyHash, KEYID_SIZE); XMEMCPY(req->issuerKeyHash, cert->issuerKeyHash, KEYID_SIZE);
req->serial = (byte*)XMALLOC(cert->serialSz, req->heap, req->serial = (byte*)XMALLOC((size_t)cert->serialSz, req->heap,
DYNAMIC_TYPE_OCSP_REQUEST); DYNAMIC_TYPE_OCSP_REQUEST);
if (req->serial == NULL) if (req->serial == NULL)
return MEMORY_E; return MEMORY_E;
XMEMCPY(req->serial, cert->serial, cert->serialSz); XMEMCPY(req->serial, cert->serial, (size_t)cert->serialSz);
req->serialSz = cert->serialSz; req->serialSz = cert->serialSz;
if (cert->extAuthInfoSz != 0 && cert->extAuthInfo != NULL) { if (cert->extAuthInfoSz != 0 && cert->extAuthInfo != NULL) {
req->url = (byte*)XMALLOC(cert->extAuthInfoSz + 1, req->heap, req->url = (byte*)XMALLOC((size_t)cert->extAuthInfoSz + 1,
DYNAMIC_TYPE_OCSP_REQUEST); req->heap, DYNAMIC_TYPE_OCSP_REQUEST);
if (req->url == NULL) { if (req->url == NULL) {
XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP); XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP);
req->serial = NULL; req->serial = NULL;
return MEMORY_E; return MEMORY_E;
} }
XMEMCPY(req->url, cert->extAuthInfo, cert->extAuthInfoSz); XMEMCPY(req->url, cert->extAuthInfo, (size_t)cert->extAuthInfoSz);
req->urlSz = cert->extAuthInfoSz; req->urlSz = cert->extAuthInfoSz;
req->url[req->urlSz] = 0; req->url[req->urlSz] = 0;
} }
@@ -35629,7 +35634,7 @@ int CompareOcspReqResp(OcspRequest* req, OcspResponse* resp)
return cmp; return cmp;
} }
cmp = XMEMCMP(req->nonce, resp->nonce, req->nonceSz); cmp = XMEMCMP(req->nonce, resp->nonce, (size_t)req->nonceSz);
if (cmp != 0) { if (cmp != 0) {
WOLFSSL_MSG("\tnonce mismatch"); WOLFSSL_MSG("\tnonce mismatch");
return cmp; return cmp;
@@ -35646,9 +35651,12 @@ int CompareOcspReqResp(OcspRequest* req, OcspResponse* resp)
#endif #endif
cmp = req->serialSz - single->status->serialSz; cmp = req->serialSz - single->status->serialSz;
if (cmp == 0) { if (cmp == 0) {
cmp = XMEMCMP(req->serial, single->status->serial, req->serialSz) cmp = XMEMCMP(req->serial, single->status->serial,
|| XMEMCMP(req->issuerHash, single->issuerHash, ocspDigestSize) (size_t)req->serialSz)
|| XMEMCMP(req->issuerKeyHash, single->issuerKeyHash, ocspDigestSize); || XMEMCMP(req->issuerHash, single->issuerHash,
(size_t)ocspDigestSize)
|| XMEMCMP(req->issuerKeyHash, single->issuerKeyHash,
(size_t)ocspDigestSize);
if (cmp == 0) { if (cmp == 0) {
/* match found */ /* match found */
if (resp->single != single && prev) { if (resp->single != single && prev) {
@@ -35700,7 +35708,7 @@ int GetNameHash(const byte* source, word32* idx, byte* hash, int maxIdx)
/* store WC_SHA hash of NAME */ /* store WC_SHA hash of NAME */
int GetNameHash_ex(const byte* source, word32* idx, byte* hash, int maxIdx, int GetNameHash_ex(const byte* source, word32* idx, byte* hash, int maxIdx,
int sigOID) word32 sigOID)
{ {
#ifndef WOLFSSL_ASN_TEMPLATE #ifndef WOLFSSL_ASN_TEMPLATE
int length; /* length of all distinguished names */ int length; /* length of all distinguished names */
@@ -35767,13 +35775,13 @@ static char* GetNameFromDer(const byte* source, int sz)
{ {
char* out; char* out;
out = (char*)XMALLOC(sz, NULL, DYNAMIC_TYPE_OPENSSL); out = (char*)XMALLOC((size_t)sz, NULL, DYNAMIC_TYPE_OPENSSL);
if (out == NULL) { if (out == NULL) {
WOLFSSL_MSG("Name malloc failed"); WOLFSSL_MSG("Name malloc failed");
return NULL; return NULL;
} }
XMEMCPY(out, source, sz); XMEMCPY(out, source, (size_t)sz);
return out; return out;
} }
@@ -35839,7 +35847,7 @@ enum {
/* Get Revoked Cert list, 0 on success */ /* Get Revoked Cert list, 0 on success */
static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx, static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx,
DecodedCRL* dcrl, int maxIdx) DecodedCRL* dcrl, word32 maxIdx)
{ {
#ifndef WOLFSSL_ASN_TEMPLATE #ifndef WOLFSSL_ASN_TEMPLATE
int ret; int ret;
@@ -35943,7 +35951,7 @@ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx,
} }
if (ret == 0) { if (ret == 0) {
/* Store size of serial number. */ /* Store size of serial number. */
rc->serialSz = serialSz; rc->serialSz = (int)serialSz;
rc->revDateFormat = (dataASN[REVOKEDASN_IDX_TIME_UTC].tag != 0) rc->revDateFormat = (dataASN[REVOKEDASN_IDX_TIME_UTC].tag != 0)
? dataASN[REVOKEDASN_IDX_TIME_UTC].tag ? dataASN[REVOKEDASN_IDX_TIME_UTC].tag
: dataASN[REVOKEDASN_IDX_TIME_GT].tag; : dataASN[REVOKEDASN_IDX_TIME_GT].tag;
@@ -36246,7 +36254,7 @@ static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
if (ret == 0) { if (ret == 0) {
/* Parse an authority key identifier. */ /* Parse an authority key identifier. */
ret = GetASN_Items(authKeyIdASN, dataASN, authKeyIdASN_Length, 1, input, ret = GetASN_Items(authKeyIdASN, dataASN, authKeyIdASN_Length, 1, input,
&idx, sz); &idx, (word32)sz);
} }
if (ret == 0) { if (ret == 0) {
/* Key id is optional. */ /* Key id is optional. */
@@ -36256,7 +36264,7 @@ static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl)
else { else {
/* Get the hash or hash of the hash if wrong size. */ /* Get the hash or hash of the hash if wrong size. */
ret = GetHashId(dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data, ret = GetHashId(dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data,
dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length, (int)dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length,
dcrl->extAuthKeyId, HashIdAlg(dcrl->signatureOID)); dcrl->extAuthKeyId, HashIdAlg(dcrl->signatureOID));
} }
} }
@@ -36447,7 +36455,7 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
/* OID in extension. */ /* OID in extension. */
word32 oid = dataASN[CERTEXTASN_IDX_OID].data.oid.sum; word32 oid = dataASN[CERTEXTASN_IDX_OID].data.oid.sum;
/* Length of extension data. */ /* Length of extension data. */
int length = dataASN[CERTEXTASN_IDX_VAL].length; int length = (int)dataASN[CERTEXTASN_IDX_VAL].length;
if (oid == AUTH_KEY_OID) { if (oid == AUTH_KEY_OID) {
#ifndef NO_SKID #ifndef NO_SKID
@@ -36462,7 +36470,7 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
/* TODO: Parse CRL Number extension */ /* TODO: Parse CRL Number extension */
/* TODO: check criticality */ /* TODO: check criticality */
/* Move index on to next extension. */ /* Move index on to next extension. */
idx += length; idx += (word32)length;
} }
} }

View File

@@ -1464,7 +1464,7 @@ static void camellia_decrypt256(const u32 *subkey, u32 *io)
* API for compatibility * API for compatibility
*/ */
static void Camellia_EncryptBlock(const int keyBitLength, static void Camellia_EncryptBlock(const word32 keyBitLength,
const unsigned char *plaintext, const unsigned char *plaintext,
const KEY_TABLE_TYPE keyTable, const KEY_TABLE_TYPE keyTable,
unsigned char *ciphertext) unsigned char *ciphertext)
@@ -1495,7 +1495,7 @@ static void Camellia_EncryptBlock(const int keyBitLength,
PUTU32(ciphertext + 12, tmp[3]); PUTU32(ciphertext + 12, tmp[3]);
} }
static void Camellia_DecryptBlock(const int keyBitLength, static void Camellia_DecryptBlock(const word32 keyBitLength,
const unsigned char *ciphertext, const unsigned char *ciphertext,
const KEY_TABLE_TYPE keyTable, const KEY_TABLE_TYPE keyTable,
unsigned char *plaintext) unsigned char *plaintext)

File diff suppressed because it is too large Load Diff

View File

@@ -609,62 +609,62 @@ void fe448_to_bytes(unsigned char* b, const sword64* a)
in4 += o; t = o << 56; in7 -= (sword64)t; in4 += o; t = o << 56; in7 -= (sword64)t;
/* Output as bytes */ /* Output as bytes */
b[ 0] = (in0 >> 0); b[ 0] = (byte)(in0 >> 0);
b[ 1] = (in0 >> 8); b[ 1] = (byte)(in0 >> 8);
b[ 2] = (in0 >> 16); b[ 2] = (byte)(in0 >> 16);
b[ 3] = (in0 >> 24); b[ 3] = (byte)(in0 >> 24);
b[ 4] = (in0 >> 32); b[ 4] = (byte)(in0 >> 32);
b[ 5] = (in0 >> 40); b[ 5] = (byte)(in0 >> 40);
b[ 6] = (in0 >> 48); b[ 6] = (byte)(in0 >> 48);
b[ 7] = (in1 >> 0); b[ 7] = (byte)(in1 >> 0);
b[ 8] = (in1 >> 8); b[ 8] = (byte)(in1 >> 8);
b[ 9] = (in1 >> 16); b[ 9] = (byte)(in1 >> 16);
b[10] = (in1 >> 24); b[10] = (byte)(in1 >> 24);
b[11] = (in1 >> 32); b[11] = (byte)(in1 >> 32);
b[12] = (in1 >> 40); b[12] = (byte)(in1 >> 40);
b[13] = (in1 >> 48); b[13] = (byte)(in1 >> 48);
b[14] = (in2 >> 0); b[14] = (byte)(in2 >> 0);
b[15] = (in2 >> 8); b[15] = (byte)(in2 >> 8);
b[16] = (in2 >> 16); b[16] = (byte)(in2 >> 16);
b[17] = (in2 >> 24); b[17] = (byte)(in2 >> 24);
b[18] = (in2 >> 32); b[18] = (byte)(in2 >> 32);
b[19] = (in2 >> 40); b[19] = (byte)(in2 >> 40);
b[20] = (in2 >> 48); b[20] = (byte)(in2 >> 48);
b[21] = (in3 >> 0); b[21] = (byte)(in3 >> 0);
b[22] = (in3 >> 8); b[22] = (byte)(in3 >> 8);
b[23] = (in3 >> 16); b[23] = (byte)(in3 >> 16);
b[24] = (in3 >> 24); b[24] = (byte)(in3 >> 24);
b[25] = (in3 >> 32); b[25] = (byte)(in3 >> 32);
b[26] = (in3 >> 40); b[26] = (byte)(in3 >> 40);
b[27] = (in3 >> 48); b[27] = (byte)(in3 >> 48);
b[28] = (in4 >> 0); b[28] = (byte)(in4 >> 0);
b[29] = (in4 >> 8); b[29] = (byte)(in4 >> 8);
b[30] = (in4 >> 16); b[30] = (byte)(in4 >> 16);
b[31] = (in4 >> 24); b[31] = (byte)(in4 >> 24);
b[32] = (in4 >> 32); b[32] = (byte)(in4 >> 32);
b[33] = (in4 >> 40); b[33] = (byte)(in4 >> 40);
b[34] = (in4 >> 48); b[34] = (byte)(in4 >> 48);
b[35] = (in5 >> 0); b[35] = (byte)(in5 >> 0);
b[36] = (in5 >> 8); b[36] = (byte)(in5 >> 8);
b[37] = (in5 >> 16); b[37] = (byte)(in5 >> 16);
b[38] = (in5 >> 24); b[38] = (byte)(in5 >> 24);
b[39] = (in5 >> 32); b[39] = (byte)(in5 >> 32);
b[40] = (in5 >> 40); b[40] = (byte)(in5 >> 40);
b[41] = (in5 >> 48); b[41] = (byte)(in5 >> 48);
b[42] = (in6 >> 0); b[42] = (byte)(in6 >> 0);
b[43] = (in6 >> 8); b[43] = (byte)(in6 >> 8);
b[44] = (in6 >> 16); b[44] = (byte)(in6 >> 16);
b[45] = (in6 >> 24); b[45] = (byte)(in6 >> 24);
b[46] = (in6 >> 32); b[46] = (byte)(in6 >> 32);
b[47] = (in6 >> 40); b[47] = (byte)(in6 >> 40);
b[48] = (in6 >> 48); b[48] = (byte)(in6 >> 48);
b[49] = (in7 >> 0); b[49] = (byte)(in7 >> 0);
b[50] = (in7 >> 8); b[50] = (byte)(in7 >> 8);
b[51] = (in7 >> 16); b[51] = (byte)(in7 >> 16);
b[52] = (in7 >> 24); b[52] = (byte)(in7 >> 24);
b[53] = (in7 >> 32); b[53] = (byte)(in7 >> 32);
b[54] = (in7 >> 40); b[54] = (byte)(in7 >> 40);
b[55] = (in7 >> 48); b[55] = (byte)(in7 >> 48);
} }
/* Set the field element to 0. /* Set the field element to 0.
@@ -1087,8 +1087,8 @@ int curve448(byte* r, const byte* n, const byte* a)
for (i = 447; i >= 0; --i) { for (i = 447; i >= 0; --i) {
unsigned int b = (n[i >> 3] >> (i & 7)) & 1; unsigned int b = (n[i >> 3] >> (i & 7)) & 1;
swap ^= b; swap ^= b;
fe448_cswap(x2, x3, swap); fe448_cswap(x2, x3, (int)swap);
fe448_cswap(z2, z3, swap); fe448_cswap(z2, z3, (int)swap);
swap = b; swap = b;
/* Montgomery Ladder - double and add */ /* Montgomery Ladder - double and add */
@@ -1434,62 +1434,62 @@ void fe448_to_bytes(unsigned char* b, const sword32* a)
in8 += o; t = o << 28; in15 -= (sword32)t; in8 += o; t = o << 28; in15 -= (sword32)t;
/* Output as bytes */ /* Output as bytes */
b[ 0] = (in0 >> 0); b[ 0] = (byte)(in0 >> 0);
b[ 1] = (in0 >> 8); b[ 1] = (byte)(in0 >> 8);
b[ 2] = (in0 >> 16); b[ 2] = (byte)(in0 >> 16);
b[ 3] = (in0 >> 24) + ((in1 >> 0) << 4); b[ 3] = (byte)(in0 >> 24) + ((in1 >> 0) << 4);
b[ 4] = (in1 >> 4); b[ 4] = (byte)(in1 >> 4);
b[ 5] = (in1 >> 12); b[ 5] = (byte)(in1 >> 12);
b[ 6] = (in1 >> 20); b[ 6] = (byte)(in1 >> 20);
b[ 7] = (in2 >> 0); b[ 7] = (byte)(in2 >> 0);
b[ 8] = (in2 >> 8); b[ 8] = (byte)(in2 >> 8);
b[ 9] = (in2 >> 16); b[ 9] = (byte)(in2 >> 16);
b[10] = (in2 >> 24) + ((in3 >> 0) << 4); b[10] = (byte)(in2 >> 24) + ((in3 >> 0) << 4);
b[11] = (in3 >> 4); b[11] = (byte)(in3 >> 4);
b[12] = (in3 >> 12); b[12] = (byte)(in3 >> 12);
b[13] = (in3 >> 20); b[13] = (byte)(in3 >> 20);
b[14] = (in4 >> 0); b[14] = (byte)(in4 >> 0);
b[15] = (in4 >> 8); b[15] = (byte)(in4 >> 8);
b[16] = (in4 >> 16); b[16] = (byte)(in4 >> 16);
b[17] = (in4 >> 24) + ((in5 >> 0) << 4); b[17] = (byte)(in4 >> 24) + ((in5 >> 0) << 4);
b[18] = (in5 >> 4); b[18] = (byte)(in5 >> 4);
b[19] = (in5 >> 12); b[19] = (byte)(in5 >> 12);
b[20] = (in5 >> 20); b[20] = (byte)(in5 >> 20);
b[21] = (in6 >> 0); b[21] = (byte)(in6 >> 0);
b[22] = (in6 >> 8); b[22] = (byte)(in6 >> 8);
b[23] = (in6 >> 16); b[23] = (byte)(in6 >> 16);
b[24] = (in6 >> 24) + ((in7 >> 0) << 4); b[24] = (byte)(in6 >> 24) + ((in7 >> 0) << 4);
b[25] = (in7 >> 4); b[25] = (byte)(in7 >> 4);
b[26] = (in7 >> 12); b[26] = (byte)(in7 >> 12);
b[27] = (in7 >> 20); b[27] = (byte)(in7 >> 20);
b[28] = (in8 >> 0); b[28] = (byte)(in8 >> 0);
b[29] = (in8 >> 8); b[29] = (byte)(in8 >> 8);
b[30] = (in8 >> 16); b[30] = (byte)(in8 >> 16);
b[31] = (in8 >> 24) + ((in9 >> 0) << 4); b[31] = (byte)(in8 >> 24) + ((in9 >> 0) << 4);
b[32] = (in9 >> 4); b[32] = (byte)(in9 >> 4);
b[33] = (in9 >> 12); b[33] = (byte)(in9 >> 12);
b[34] = (in9 >> 20); b[34] = (byte)(in9 >> 20);
b[35] = (in10 >> 0); b[35] = (byte)(in10 >> 0);
b[36] = (in10 >> 8); b[36] = (byte)(in10 >> 8);
b[37] = (in10 >> 16); b[37] = (byte)(in10 >> 16);
b[38] = (in10 >> 24) + ((in11 >> 0) << 4); b[38] = (byte)(in10 >> 24) + ((in11 >> 0) << 4);
b[39] = (in11 >> 4); b[39] = (byte)(in11 >> 4);
b[40] = (in11 >> 12); b[40] = (byte)(in11 >> 12);
b[41] = (in11 >> 20); b[41] = (byte)(in11 >> 20);
b[42] = (in12 >> 0); b[42] = (byte)(in12 >> 0);
b[43] = (in12 >> 8); b[43] = (byte)(in12 >> 8);
b[44] = (in12 >> 16); b[44] = (byte)(in12 >> 16);
b[45] = (in12 >> 24) + ((in13 >> 0) << 4); b[45] = (byte)(in12 >> 24) + ((in13 >> 0) << 4);
b[46] = (in13 >> 4); b[46] = (byte)(in13 >> 4);
b[47] = (in13 >> 12); b[47] = (byte)(in13 >> 12);
b[48] = (in13 >> 20); b[48] = (byte)(in13 >> 20);
b[49] = (in14 >> 0); b[49] = (byte)(in14 >> 0);
b[50] = (in14 >> 8); b[50] = (byte)(in14 >> 8);
b[51] = (in14 >> 16); b[51] = (byte)(in14 >> 16);
b[52] = (in14 >> 24) + ((in15 >> 0) << 4); b[52] = (byte)(in14 >> 24) + ((in15 >> 0) << 4);
b[53] = (in15 >> 4); b[53] = (byte)(in15 >> 4);
b[54] = (in15 >> 12); b[54] = (byte)(in15 >> 12);
b[55] = (in15 >> 20); b[55] = (byte)(in15 >> 20);
} }
/* Set the field element to 0. /* Set the field element to 0.
@@ -2178,8 +2178,8 @@ int curve448(byte* r, const byte* n, const byte* a)
for (i = 447; i >= 0; --i) { for (i = 447; i >= 0; --i) {
unsigned int b = (n[i >> 3] >> (i & 7)) & 1; unsigned int b = (n[i >> 3] >> (i & 7)) & 1;
swap ^= b; swap ^= b;
fe448_cswap(x2, x3, swap); fe448_cswap(x2, x3, (int)swap);
fe448_cswap(z2, z3, swap); fe448_cswap(z2, z3, (int)swap);
swap = b; swap = b;
/* Montgomery Ladder - double and add */ /* Montgomery Ladder - double and add */

File diff suppressed because it is too large Load Diff

View File

@@ -744,38 +744,38 @@ void sc_reduce(byte* s)
carry = t[ 3] >> 42; t[ 4] += carry; t[ 3] &= MASK_42; carry = t[ 3] >> 42; t[ 4] += carry; t[ 3] &= MASK_42;
carry = t[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42; carry = t[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42;
s[ 0] = (t[ 0] >> 0); s[ 0] = (byte)(t[ 0] >> 0);
s[ 1] = (t[ 0] >> 8); s[ 1] = (byte)(t[ 0] >> 8);
s[ 2] = (t[ 0] >> 16); s[ 2] = (byte)(t[ 0] >> 16);
s[ 3] = (t[ 0] >> 24); s[ 3] = (byte)(t[ 0] >> 24);
s[ 4] = (t[ 0] >> 32); s[ 4] = (byte)(t[ 0] >> 32);
s[ 5] = (t[ 0] >> 40) | (t[ 1] << 2); s[ 5] = (byte)(t[ 0] >> 40) | (byte)(t[ 1] << 2);
s[ 6] = (t[ 1] >> 6); s[ 6] = (byte)(t[ 1] >> 6);
s[ 7] = (t[ 1] >> 14); s[ 7] = (byte)(t[ 1] >> 14);
s[ 8] = (t[ 1] >> 22); s[ 8] = (byte)(t[ 1] >> 22);
s[ 9] = (t[ 1] >> 30); s[ 9] = (byte)(t[ 1] >> 30);
s[10] = (t[ 1] >> 38) | (t[ 2] << 4); s[10] = (byte)(t[ 1] >> 38) | (byte)(t[ 2] << 4);
s[11] = (t[ 2] >> 4); s[11] = (byte)(t[ 2] >> 4);
s[12] = (t[ 2] >> 12); s[12] = (byte)(t[ 2] >> 12);
s[13] = (t[ 2] >> 20); s[13] = (byte)(t[ 2] >> 20);
s[14] = (t[ 2] >> 28); s[14] = (byte)(t[ 2] >> 28);
s[15] = (t[ 2] >> 36) | (t[ 3] << 6); s[15] = (byte)(t[ 2] >> 36) | (byte)(t[ 3] << 6);
s[16] = (t[ 3] >> 2); s[16] = (byte)(t[ 3] >> 2);
s[17] = (t[ 3] >> 10); s[17] = (byte)(t[ 3] >> 10);
s[18] = (t[ 3] >> 18); s[18] = (byte)(t[ 3] >> 18);
s[19] = (t[ 3] >> 26); s[19] = (byte)(t[ 3] >> 26);
s[20] = (t[ 3] >> 34); s[20] = (byte)(t[ 3] >> 34);
s[21] = (t[ 4] >> 0); s[21] = (byte)(t[ 4] >> 0);
s[22] = (t[ 4] >> 8); s[22] = (byte)(t[ 4] >> 8);
s[23] = (t[ 4] >> 16); s[23] = (byte)(t[ 4] >> 16);
s[24] = (t[ 4] >> 24); s[24] = (byte)(t[ 4] >> 24);
s[25] = (t[ 4] >> 32); s[25] = (byte)(t[ 4] >> 32);
s[26] = (t[ 4] >> 40) | (t[ 5] << 2); s[26] = (byte)(t[ 4] >> 40) | (byte)(t[ 5] << 2);
s[27] = (t[ 5] >> 6); s[27] = (byte)(t[ 5] >> 6);
s[28] = (t[ 5] >> 14); s[28] = (byte)(t[ 5] >> 14);
s[29] = (t[ 5] >> 22); s[29] = (byte)(t[ 5] >> 22);
s[30] = (t[ 5] >> 30); s[30] = (byte)(t[ 5] >> 30);
s[31] = (t[ 5] >> 38); s[31] = (byte)(t[ 5] >> 38);
} }
/* /*
@@ -896,38 +896,38 @@ void sc_muladd(byte* s, const byte* a, const byte* b, const byte* c)
carry = t[ 3] >> 42; t[ 4] += carry; t[ 3] &= MASK_42; carry = t[ 3] >> 42; t[ 4] += carry; t[ 3] &= MASK_42;
carry = t[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42; carry = t[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42;
s[ 0] = (t[ 0] >> 0); s[ 0] = (byte)(t[ 0] >> 0);
s[ 1] = (t[ 0] >> 8); s[ 1] = (byte)(t[ 0] >> 8);
s[ 2] = (t[ 0] >> 16); s[ 2] = (byte)(t[ 0] >> 16);
s[ 3] = (t[ 0] >> 24); s[ 3] = (byte)(t[ 0] >> 24);
s[ 4] = (t[ 0] >> 32); s[ 4] = (byte)(t[ 0] >> 32);
s[ 5] = (t[ 0] >> 40) | (t[ 1] << 2); s[ 5] = (byte)(t[ 0] >> 40) | (byte)(t[ 1] << 2);
s[ 6] = (t[ 1] >> 6); s[ 6] = (byte)(t[ 1] >> 6);
s[ 7] = (t[ 1] >> 14); s[ 7] = (byte)(t[ 1] >> 14);
s[ 8] = (t[ 1] >> 22); s[ 8] = (byte)(t[ 1] >> 22);
s[ 9] = (t[ 1] >> 30); s[ 9] = (byte)(t[ 1] >> 30);
s[10] = (t[ 1] >> 38) | (t[ 2] << 4); s[10] = (byte)(t[ 1] >> 38) | (byte)(t[ 2] << 4);
s[11] = (t[ 2] >> 4); s[11] = (byte)(t[ 2] >> 4);
s[12] = (t[ 2] >> 12); s[12] = (byte)(t[ 2] >> 12);
s[13] = (t[ 2] >> 20); s[13] = (byte)(t[ 2] >> 20);
s[14] = (t[ 2] >> 28); s[14] = (byte)(t[ 2] >> 28);
s[15] = (t[ 2] >> 36) | (t[ 3] << 6); s[15] = (byte)(t[ 2] >> 36) | (byte)(t[ 3] << 6);
s[16] = (t[ 3] >> 2); s[16] = (byte)(t[ 3] >> 2);
s[17] = (t[ 3] >> 10); s[17] = (byte)(t[ 3] >> 10);
s[18] = (t[ 3] >> 18); s[18] = (byte)(t[ 3] >> 18);
s[19] = (t[ 3] >> 26); s[19] = (byte)(t[ 3] >> 26);
s[20] = (t[ 3] >> 34); s[20] = (byte)(t[ 3] >> 34);
s[21] = (t[ 4] >> 0); s[21] = (byte)(t[ 4] >> 0);
s[22] = (t[ 4] >> 8); s[22] = (byte)(t[ 4] >> 8);
s[23] = (t[ 4] >> 16); s[23] = (byte)(t[ 4] >> 16);
s[24] = (t[ 4] >> 24); s[24] = (byte)(t[ 4] >> 24);
s[25] = (t[ 4] >> 32); s[25] = (byte)(t[ 4] >> 32);
s[26] = (t[ 4] >> 40) | (t[ 5] << 2); s[26] = (byte)(t[ 4] >> 40) | (byte)(t[ 5] << 2);
s[27] = (t[ 5] >> 6); s[27] = (byte)(t[ 5] >> 6);
s[28] = (t[ 5] >> 14); s[28] = (byte)(t[ 5] >> 14);
s[29] = (t[ 5] >> 22); s[29] = (byte)(t[ 5] >> 22);
s[30] = (t[ 5] >> 30); s[30] = (byte)(t[ 5] >> 30);
s[31] = (t[ 5] >> 38); s[31] = (byte)(t[ 5] >> 38);
} }
#endif /* !HAVE___UINT128_T || NO_CURVED25519_128BIT */ #endif /* !HAVE___UINT128_T || NO_CURVED25519_128BIT */
@@ -985,11 +985,9 @@ static WC_INLINE void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
#ifndef CURVED25519_ASM #ifndef CURVED25519_ASM
/* ge_scalar mult base */ /* ge_scalar mult base */
static unsigned char equal(signed char b,signed char c) static unsigned char equal(unsigned char b,unsigned char c)
{ {
unsigned char ub = b; unsigned char x = b ^ c; /* 0: yes; 1..255: no */
unsigned char uc = c;
unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
word32 y = x; /* 0: yes; 1..255: no */ word32 y = x; /* 0: yes; 1..255: no */
y -= 1; /* 4294967295: yes; 0..254: no */ y -= 1; /* 4294967295: yes; 0..254: no */
y >>= 31; /* 1: yes; 0: no */ y >>= 31; /* 1: yes; 0: no */
@@ -9098,7 +9096,7 @@ static void ge_select(ge_precomp *t,int pos,signed char b)
#ifndef CURVED25519_ASM #ifndef CURVED25519_ASM
ge_precomp minust; ge_precomp minust;
unsigned char bnegative = negative(b); unsigned char bnegative = negative(b);
unsigned char babs = b - (((-bnegative) & b) << 1); unsigned char babs = (unsigned char)(b - (((-bnegative) & b) << 1));
ge_precomp_0(t); ge_precomp_0(t);
cmov(t,&base[pos][0],babs,1); cmov(t,&base[pos][0],babs,1);
@@ -9148,7 +9146,7 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
e[i] += carry; e[i] += carry;
carry = e[i] + 8; carry = e[i] + 8;
carry >>= 4; carry >>= 4;
e[i] -= carry << 4; e[i] -= (signed char)(carry << 4);
} }
e[63] += carry; e[63] += carry;
/* each e[i] is between -8 and 8 */ /* each e[i] is between -8 and 8 */
@@ -9209,9 +9207,9 @@ static void slide(signed char *r,const unsigned char *a)
for (b = 1;b <= 6 && i + b < SLIDE_SIZE;++b) { for (b = 1;b <= 6 && i + b < SLIDE_SIZE;++b) {
if (r[i + b]) { if (r[i + b]) {
if (r[i] + (r[i + b] << b) <= 15) { if (r[i] + (r[i + b] << b) <= 15) {
r[i] += r[i + b] << b; r[i + b] = 0; r[i] += (signed char)(r[i + b] << b); r[i + b] = 0;
} else if (r[i] - (r[i + b] << b) >= -15) { } else if (r[i] - (r[i + b] << b) >= -15) {
r[i] -= r[i + b] << b; r[i] -= (signed char)(r[i + b] << b);
for (k = i + b;k < SLIDE_SIZE;++k) { for (k = i + b;k < SLIDE_SIZE;++k) {
if (!r[k]) { if (!r[k]) {
r[k] = 1; r[k] = 1;
@@ -9797,7 +9795,7 @@ void ge_p3_tobytes(unsigned char *s,const ge_p3 *h)
fe_mul(x,h->X,recip); fe_mul(x,h->X,recip);
fe_mul(y,h->Y,recip); fe_mul(y,h->Y,recip);
fe_tobytes(s,y); fe_tobytes(s,y);
s[31] ^= fe_isnegative(x) << 7; s[31] ^= (unsigned char)(fe_isnegative(x) << 7);
} }
@@ -9850,7 +9848,7 @@ void ge_tobytes(unsigned char *s,const ge_p2 *h)
fe_mul(x,h->X,recip); fe_mul(x,h->X,recip);
fe_mul(y,h->Y,recip); fe_mul(y,h->Y,recip);
fe_tobytes(s,y); fe_tobytes(s,y);
s[31] ^= fe_isnegative(x) << 7; s[31] ^= (unsigned char)(fe_isnegative(x) << 7);
} }
#endif /* !ED25519_SMALL */ #endif /* !ED25519_SMALL */

View File

@@ -117,7 +117,7 @@ static int I2OSP(int n, int w, byte* out)
} }
/* make sure the byte string is cleared */ /* make sure the byte string is cleared */
XMEMSET( out, 0, w ); XMEMSET(out, 0, (size_t)w);
for (i = 0; i < w && n > 0; i++) { for (i = 0; i < w && n > 0; i++) {
out[w-(i + 1)] = (byte)n; out[w-(i + 1)] = (byte)n;
@@ -138,9 +138,9 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap)
} }
XMEMSET(hpke, 0, sizeof(*hpke)); XMEMSET(hpke, 0, sizeof(*hpke));
hpke->kem = kem; hpke->kem = (word32)kem;
hpke->kdf = kdf; hpke->kdf = (word32)kdf;
hpke->aead = aead; hpke->aead = (word32)aead;
hpke->heap = heap; hpke->heap = heap;
/* set kem_suite_id */ /* set kem_suite_id */
@@ -177,7 +177,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap)
hpke->curve_id = ECC_SECP256R1; hpke->curve_id = ECC_SECP256R1;
hpke->Nsecret = WC_SHA256_DIGEST_SIZE; hpke->Nsecret = WC_SHA256_DIGEST_SIZE;
hpke->Nh = WC_SHA256_DIGEST_SIZE; hpke->Nh = WC_SHA256_DIGEST_SIZE;
hpke->Ndh = wc_ecc_get_curve_size_from_id(hpke->curve_id); hpke->Ndh = (word32)wc_ecc_get_curve_size_from_id(hpke->curve_id);
hpke->Npk = 1 + hpke->Ndh * 2; hpke->Npk = 1 + hpke->Ndh * 2;
break; break;
#endif #endif
@@ -187,7 +187,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap)
hpke->curve_id = ECC_SECP384R1; hpke->curve_id = ECC_SECP384R1;
hpke->Nsecret = WC_SHA384_DIGEST_SIZE; hpke->Nsecret = WC_SHA384_DIGEST_SIZE;
hpke->Nh = WC_SHA384_DIGEST_SIZE; hpke->Nh = WC_SHA384_DIGEST_SIZE;
hpke->Ndh = wc_ecc_get_curve_size_from_id(hpke->curve_id); hpke->Ndh = (word32)wc_ecc_get_curve_size_from_id(hpke->curve_id);
hpke->Npk = 1 + hpke->Ndh * 2; hpke->Npk = 1 + hpke->Ndh * 2;
break; break;
#endif #endif
@@ -197,7 +197,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap)
hpke->curve_id = ECC_SECP521R1; hpke->curve_id = ECC_SECP521R1;
hpke->Nsecret = WC_SHA512_DIGEST_SIZE; hpke->Nsecret = WC_SHA512_DIGEST_SIZE;
hpke->Nh = WC_SHA512_DIGEST_SIZE; hpke->Nh = WC_SHA512_DIGEST_SIZE;
hpke->Ndh = wc_ecc_get_curve_size_from_id(hpke->curve_id); hpke->Ndh = (word32)wc_ecc_get_curve_size_from_id(hpke->curve_id);
hpke->Npk = 1 + hpke->Ndh * 2; hpke->Npk = 1 + hpke->Ndh * 2;
break; break;
#endif #endif
@@ -272,7 +272,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap)
} }
if ((int)hpke->Ndh < 0) { if ((int)hpke->Ndh < 0) {
return hpke->Ndh; return (int)hpke->Ndh;
} }
return ret; return ret;
@@ -332,7 +332,7 @@ int wc_HpkeGenerateKeyPair(Hpke* hpke, void** keypair, WC_RNG* rng)
ret = MEMORY_E; ret = MEMORY_E;
if (ret != 0 && *keypair != NULL) { if (ret != 0 && *keypair != NULL) {
wc_HpkeFreeKey(hpke, hpke->kem, *keypair, hpke->heap); wc_HpkeFreeKey(hpke, (word16)hpke->kem, *keypair, hpke->heap);
*keypair = NULL; *keypair = NULL;
} }
@@ -373,7 +373,7 @@ int wc_HpkeSerializePublicKey(Hpke* hpke, void* key, byte* out, word16* outSz)
break; break;
} }
*outSz = tmpOutSz; *outSz = (word16)tmpOutSz;
return ret; return ret;
} }
@@ -430,7 +430,7 @@ int wc_HpkeDeserializePublicKey(Hpke* hpke, void** key, const byte* in,
ret = MEMORY_E; ret = MEMORY_E;
if (ret != 0 && *key != NULL) { if (ret != 0 && *key != NULL) {
wc_HpkeFreeKey(hpke, hpke->kem, *key, hpke->heap); wc_HpkeFreeKey(hpke, (word16)hpke->kem, *key, hpke->heap);
*key = NULL; *key = NULL;
} }
@@ -547,7 +547,7 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len,
#endif #endif
/* copy length */ /* copy length */
ret = I2OSP(L, 2, labeled_info); ret = I2OSP((int)L, 2, labeled_info);
labeled_info_p = labeled_info + 2; labeled_info_p = labeled_info + 2;
if (ret == 0) { if (ret == 0) {
@@ -593,7 +593,7 @@ static int wc_HpkeContextComputeNonce(Hpke* hpke, HpkeBaseContext* context,
/* convert the sequence into a byte string with the same length as the /* convert the sequence into a byte string with the same length as the
* nonce */ * nonce */
ret = I2OSP(context->seq, hpke->Nn, seq_bytes); ret = I2OSP(context->seq, (int)hpke->Nn, seq_bytes);
if (ret == 0) { if (ret == 0) {
xorbufout(out, context->base_nonce, seq_bytes, hpke->Nn); xorbufout(out, context->base_nonce, seq_bytes, hpke->Nn);
} }
@@ -759,8 +759,8 @@ static int wc_HpkeEncap(Hpke* hpke, void* ephemeralKey, void* receiverKey,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
receiverPubKeySz = hpke->Npk; receiverPubKeySz = (word16)hpke->Npk;
ephemeralPubKeySz = hpke->Npk; ephemeralPubKeySz = (word16)hpke->Npk;
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
dh = (byte*)XMALLOC(hpke->Ndh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER); dh = (byte*)XMALLOC(hpke->Ndh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -990,7 +990,7 @@ static int wc_HpkeDecap(Hpke* hpke, void* receiverKey, const byte* pubKey,
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
receiverPubKeySz = hpke->Npk; receiverPubKeySz = (word16)hpke->Npk;
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
dh = (byte*)XMALLOC(hpke->Ndh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER); dh = (byte*)XMALLOC(hpke->Ndh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -1048,7 +1048,7 @@ static int wc_HpkeDecap(Hpke* hpke, void* receiverKey, const byte* pubKey,
} }
if (ephemeralKey != NULL) if (ephemeralKey != NULL)
wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap); wc_HpkeFreeKey(hpke, (word16)hpke->kem, ephemeralKey, hpke->heap);
if (ret == 0) { if (ret == 0) {
/* copy pubKey into kemContext */ /* copy pubKey into kemContext */

View File

@@ -477,7 +477,7 @@ static int get_abs_idx(int relative_idx)
return (int)((wc_errors.head_idx + wc_errors.count - 1) return (int)((wc_errors.head_idx + wc_errors.count - 1)
% ERROR_QUEUE_MAX); % ERROR_QUEUE_MAX);
} }
return (int)((wc_errors.head_idx + relative_idx) % ERROR_QUEUE_MAX); return (int)((wc_errors.head_idx + (size_t)relative_idx) % ERROR_QUEUE_MAX);
} }
/** /**
@@ -526,13 +526,13 @@ static int pass_entry(struct wc_error_entry *entry,
static void set_entry(struct wc_error_entry *entry, int error, static void set_entry(struct wc_error_entry *entry, int error,
const char *file, const char *reason, int line) const char *file, const char *reason, int line)
{ {
int sz; size_t sz;
XMEMSET(entry, 0, sizeof(struct wc_error_entry)); XMEMSET(entry, 0, sizeof(struct wc_error_entry));
entry->err = error; entry->err = error;
entry->line = line; entry->line = line;
sz = (int)XSTRLEN(reason); sz = XSTRLEN(reason);
if (sz > WOLFSSL_MAX_ERROR_SZ - 1) { if (sz > WOLFSSL_MAX_ERROR_SZ - 1) {
sz = WOLFSSL_MAX_ERROR_SZ - 1; sz = WOLFSSL_MAX_ERROR_SZ - 1;
} }
@@ -541,7 +541,7 @@ static void set_entry(struct wc_error_entry *entry, int error,
entry->reason[WOLFSSL_MAX_ERROR_SZ - 1] = '\0'; entry->reason[WOLFSSL_MAX_ERROR_SZ - 1] = '\0';
} }
sz = (int)XSTRLEN(file); sz = XSTRLEN(file);
if (sz > WOLFSSL_MAX_ERROR_SZ - 1) { if (sz > WOLFSSL_MAX_ERROR_SZ - 1) {
sz = WOLFSSL_MAX_ERROR_SZ - 1; sz = WOLFSSL_MAX_ERROR_SZ - 1;
} }
@@ -628,7 +628,7 @@ void wc_RemoveErrorNode(int relative_idx)
if (abs_idx >= (int)wc_errors.head_idx) { if (abs_idx >= (int)wc_errors.head_idx) {
/* removed entry sits "above" head (or is head), /* removed entry sits "above" head (or is head),
* move entries below it "up" */ * move entries below it "up" */
move_count = (abs_idx - (int)wc_errors.head_idx); move_count = (size_t)abs_idx - wc_errors.head_idx;
if (move_count > 0) { if (move_count > 0) {
XMEMMOVE(&wc_errors.entries[wc_errors.head_idx + 1], XMEMMOVE(&wc_errors.entries[wc_errors.head_idx + 1],
&wc_errors.entries[wc_errors.head_idx], &wc_errors.entries[wc_errors.head_idx],
@@ -642,7 +642,7 @@ void wc_RemoveErrorNode(int relative_idx)
* move entries above it "down" */ * move entries above it "down" */
int last_idx = get_abs_idx(-1); int last_idx = get_abs_idx(-1);
if (last_idx >= abs_idx) { /* this SHOULD always be true */ if (last_idx >= abs_idx) { /* this SHOULD always be true */
move_count = (last_idx - abs_idx); move_count = (size_t)(last_idx - abs_idx);
if (move_count > 0) { if (move_count > 0) {
XMEMMOVE(&wc_errors.entries[abs_idx], XMEMMOVE(&wc_errors.entries[abs_idx],
&wc_errors.entries[abs_idx + 1], &wc_errors.entries[abs_idx + 1],
@@ -746,7 +746,7 @@ unsigned long wc_GetErrorNodeErr(void)
wc_ClearErrorNodes(); wc_ClearErrorNodes();
} }
} }
return ret; return (unsigned long)ret;
} }
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
@@ -1495,7 +1495,7 @@ void WOLFSSL_ERROR(int error)
"wolfSSL error occurred, error = %d line:%u file:%s", "wolfSSL error occurred, error = %d line:%u file:%s",
error, line, file); error, line, file);
if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) { if (wc_AddErrorNode(error, (int)line, buffer, (char*)file) != 0) {
WOLFSSL_MSG("Error creating logging node"); WOLFSSL_MSG("Error creating logging node");
/* with void function there is no return here, continue on /* with void function there is no return here, continue on
* to unlock mutex and log what buffer was created. */ * to unlock mutex and log what buffer was created. */

View File

@@ -107,7 +107,7 @@ void wc_Md2Update(Md2* md2, const byte* data, word32 len)
t = md2->X[j+6] ^= S[t]; t = md2->X[j+6] ^= S[t];
t = md2->X[j+7] ^= S[t]; t = md2->X[j+7] ^= S[t];
} }
t = (t + i) & 0xFF; t = (byte)((t + i) & 0xFF);
} }
} }
} }

View File

@@ -681,7 +681,7 @@ static void scryptROMix(byte* x, byte* v, byte* y, int r, word32 n)
word32 i; word32 i;
word32 j; word32 j;
word32 k; word32 k;
word32 bSz = 128 * r; word32 bSz = (word32)(128 * r);
#ifdef WORD64_AVAILABLE #ifdef WORD64_AVAILABLE
word64* x64 = (word64*)x; word64* x64 = (word64*)x;
word64* v64 = (word64*)v; word64* v64 = (word64*)v;
@@ -703,7 +703,7 @@ static void scryptROMix(byte* x, byte* v, byte* y, int r, word32 n)
{ {
#ifdef LITTLE_ENDIAN_ORDER #ifdef LITTLE_ENDIAN_ORDER
#ifdef WORD64_AVAILABLE #ifdef WORD64_AVAILABLE
j = *(word64*)(x + (2*r - 1) * 64) & (n-1); j = (word32)(*(word64*)(x + (2*r - 1) * 64) & (n-1));
#else #else
j = *(word32*)(x + (2*r - 1) * 64) & (n-1); j = *(word32*)(x + (2*r - 1) * 64) & (n-1);
#endif #endif
@@ -764,43 +764,45 @@ int wc_scrypt(byte* output, const byte* passwd, int passLen,
* the comparison is greater than parallel's type. It wouldn't promote * the comparison is greater than parallel's type. It wouldn't promote
* both sides to word64. What follows is just arithmetic simplification. * both sides to word64. What follows is just arithmetic simplification.
*/ */
if ((word32)parallel > (SCRYPT_WORD32_MAX / (4 * blockSize))) if (parallel > (int)((SCRYPT_WORD32_MAX / 4) / (word32)blockSize))
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
bSz = 128 * blockSize; bSz = 128 * (word32)blockSize;
if ((word32)parallel > (SCRYPT_WORD32_MAX / bSz)) if (parallel > (int)(SCRYPT_WORD32_MAX / bSz))
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
blocksSz = bSz * parallel; blocksSz = bSz * (word32)parallel;
blocks = (byte*)XMALLOC(blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); blocks = (byte*)XMALLOC((size_t)blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (blocks == NULL) { if (blocks == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
goto end; goto end;
} }
/* Temporary for scryptROMix. */ /* Temporary for scryptROMix. */
v = (byte*)XMALLOC((1 << cost) * bSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); v = (byte*)XMALLOC((size_t)((1 << cost) * bSz), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (v == NULL) { if (v == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
goto end; goto end;
} }
/* Temporary for scryptBlockMix. */ /* Temporary for scryptBlockMix. */
y = (byte*)XMALLOC(blockSize * 128, NULL, DYNAMIC_TYPE_TMP_BUFFER); y = (byte*)XMALLOC((size_t)(blockSize * 128), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (y == NULL) { if (y == NULL) {
ret = MEMORY_E; ret = MEMORY_E;
goto end; goto end;
} }
/* Step 1. */ /* Step 1. */
ret = wc_PBKDF2(blocks, passwd, passLen, salt, saltLen, 1, blocksSz, ret = wc_PBKDF2(blocks, passwd, passLen, salt, saltLen, 1, (int)blocksSz,
WC_SHA256); WC_SHA256);
if (ret != 0) if (ret != 0)
goto end; goto end;
/* Step 2. */ /* Step 2. */
for (i = 0; i < parallel; i++) for (i = 0; i < parallel; i++)
scryptROMix(blocks + i * bSz, v, y, blockSize, 1 << cost); scryptROMix(blocks + i * (int)bSz, v, y, (int)blockSize, 1 << cost);
/* Step 3. */ /* Step 3. */
ret = wc_PBKDF2(output, passwd, passLen, blocks, blocksSz, 1, dkLen, ret = wc_PBKDF2(output, passwd, passLen, blocks, (int)blocksSz, 1, dkLen,
WC_SHA256); WC_SHA256);
end: end:
if (blocks != NULL) if (blocks != NULL)

View File

@@ -59,7 +59,7 @@ int wolf_test_task(void);
#define WC_TEST_RET_TAG_I 3L #define WC_TEST_RET_TAG_I 3L
#define WC_TEST_RET_ENC(line, i, tag) \ #define WC_TEST_RET_ENC(line, i, tag) \
(-((wc_test_ret_t)(line) + ((wc_test_ret_t)((word32)(i) & 0x7ffL) * 100000L) + ((wc_test_ret_t)(tag) << 29L))) ((wc_test_ret_t)(-((wc_test_ret_t)(line) + ((wc_test_ret_t)((word32)(i) & 0x7ffL) * 100000L) + ((wc_test_ret_t)(tag) << 29L))))
#ifndef WC_TEST_RET_LN #ifndef WC_TEST_RET_LN
#define WC_TEST_RET_LN __LINE__ #define WC_TEST_RET_LN __LINE__

View File

@@ -2043,7 +2043,7 @@ typedef enum MimeStatus
#endif /* HAVE_SMIME */ #endif /* HAVE_SMIME */
WOLFSSL_LOCAL int HashIdAlg(int oidSum); WOLFSSL_LOCAL int HashIdAlg(word32 oidSum);
WOLFSSL_LOCAL int CalcHashId(const byte* data, word32 len, byte* hash); WOLFSSL_LOCAL int CalcHashId(const byte* data, word32 len, byte* hash);
WOLFSSL_LOCAL int CalcHashId_ex(const byte* data, word32 len, byte* hash, WOLFSSL_LOCAL int CalcHashId_ex(const byte* data, word32 len, byte* hash,
int hashAlg); int hashAlg);
@@ -2233,7 +2233,7 @@ WOLFSSL_LOCAL int wc_GetSerialNumber(const byte* input, word32* inOutIdx,
WOLFSSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash, WOLFSSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash,
int maxIdx); int maxIdx);
WOLFSSL_LOCAL int GetNameHash_ex(const byte* source, word32* idx, byte* hash, WOLFSSL_LOCAL int GetNameHash_ex(const byte* source, word32* idx, byte* hash,
int maxIdx, int sigOID); int maxIdx, word32 sigOID);
WOLFSSL_LOCAL int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der); WOLFSSL_LOCAL int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der);
WOLFSSL_LOCAL int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz, WOLFSSL_LOCAL int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
const byte* pubKey, word32 pubKeySz, enum Key_Sum ks); const byte* pubKey, word32 pubKeySz, enum Key_Sum ks);