From 2c9609039ddf5c003f5140664509a7a2e03a92ad Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 12 Jul 2023 12:11:01 +1000 Subject: [PATCH] Type conversion fixes: make explicit Changed to types and casting so that there are no implcit conversion warnings (gcc -Wconversion) in these files. --- examples/asn1/asn1.c | 6 +- examples/pem/pem.c | 18 +- src/ssl_certman.c | 44 +- wolfcrypt/src/asn.c | 184 +++--- wolfcrypt/src/camellia.c | 4 +- wolfcrypt/src/evp.c | 661 ++++++++++---------- wolfcrypt/src/fe_448.c | 232 +++---- wolfcrypt/src/ge_448.c | 1103 +++++++++++++++++---------------- wolfcrypt/src/ge_operations.c | 146 +++-- wolfcrypt/src/hpke.c | 34 +- wolfcrypt/src/logging.c | 16 +- wolfcrypt/src/md2.c | 2 +- wolfcrypt/src/pwdbased.c | 26 +- wolfcrypt/test/test.h | 2 +- wolfssl/wolfcrypt/asn.h | 4 +- 15 files changed, 1260 insertions(+), 1222 deletions(-) diff --git a/examples/asn1/asn1.c b/examples/asn1/asn1.c index 4d8d0c30e8..0a2f74378a 100644 --- a/examples/asn1/asn1.c +++ b/examples/asn1/asn1.c @@ -329,7 +329,7 @@ int main(int argc, char* argv[]) /* Default to reading STDIN. */ FILE* fp = stdin; int file_format = FORMAT_DER; - int indent = 0; + word32 indent = 0; int pem_skip = 0; /* Reset options. */ @@ -376,7 +376,7 @@ int main(int argc, char* argv[]) argc--; argv++; 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. */ else if ((strcmp(argv[0], "-n") == 0) || @@ -398,7 +398,7 @@ int main(int argc, char* argv[]) argc--; argv++; wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_OFFSET, - atoi(argv[0])); + (word32)atoi(argv[0])); } /* Show wolfSSL OID value for all OBJECT_IDs. */ else if ((strcmp(argv[0], "-O") == 0) || diff --git a/examples/pem/pem.c b/examples/pem/pem.c index 0929cdfb53..87ee4f78d2 100644 --- a/examples/pem/pem.c +++ b/examples/pem/pem.c @@ -233,7 +233,7 @@ static int password_from_userdata(char* passwd, int sz, int rw, void* userdata) { (void)rw; /* Copy user data into buffer. */ - strncpy(passwd, (const char*)userdata, sz); + strncpy(passwd, (const char*)userdata, (size_t)sz); passwd[sz - 1] = '\0'; /* Return length of password returned. */ 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. */ if ((ret == 0) && padding) { unsigned char pad = (*der)->buffer[(*der)->length - 1]; - int i; + word32 i; /* Simple padding validation. */ if ((pad == 0) || (pad > (*der)->length)) { @@ -553,8 +553,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password, if (ret == 0) { /* Get length of encrypted DER data. */ ret = wc_CreateEncryptedPKCS8Key(in, in_len, NULL, enc_len, password, - (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz, - iterations, &rng, NULL); + (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz, + (int)iterations, &rng, NULL); if (ret == LENGTH_ONLY_E) { ret = 0; } @@ -572,8 +572,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password, if (ret == 0) { /* Encrypt DER data. */ ret = wc_CreateEncryptedPKCS8Key(in, in_len, *enc, enc_len, password, - (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz, - iterations, &rng, NULL); + (int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz, + (int)iterations, &rng, NULL); if (ret > 0) { ret = 0; } @@ -601,7 +601,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len, { int ret = 0; unsigned char* pem = NULL; - int pem_len = 0; + unsigned int pem_len = 0; /* Set point to start looking and length. */ unsigned char* der = in + offset; word32 der_len = len - offset; @@ -611,7 +611,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len, if (ret <= 0) { fprintf(stderr, "Could not determine length of PEM\n"); } - pem_len = ret; + pem_len = (unsigned int)ret; if (ret > 0) { ret = 0; } @@ -631,7 +631,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len, } if (ret > 0) { *out = pem; - *out_len = ret; + *out_len = (word32)ret; ret = 0; } } diff --git a/src/ssl_certman.c b/src/ssl_certman.c index ac3a26ff24..9b421caae3 100644 --- a/src/ssl_certman.c +++ b/src/ssl_certman.c @@ -291,15 +291,16 @@ static WC_INLINE int wolfssl_cm_get_certs_der(WOLFSSL_CERT_MANAGER* cm, if (!err) { /* Allocate memory for pointers to each DER buffer. */ - certBuffers = (DerBuffer**)XMALLOC(sizeof(DerBuffer*) * numCerts, - cm->heap, DYNAMIC_TYPE_TMP_BUFFER); + certBuffers = (DerBuffer**)XMALLOC( + sizeof(DerBuffer*) * (size_t)numCerts, cm->heap, + DYNAMIC_TYPE_TMP_BUFFER); if (certBuffers == NULL) { err = 1; } } if (!err) { /* 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 @@ -382,7 +383,7 @@ WOLFSSL_STACK* wolfSSL_CertManagerGetCerts(WOLFSSL_CERT_MANAGER* cm) /* Get pointer to DER encoding of certificate. */ derBuffer = certBuffers[i]->buffer; /* Decode certificate. */ - wolfSSL_d2i_X509(&x509, &derBuffer, certBuffers[i]->length); + wolfSSL_d2i_X509(&x509, &derBuffer, (int)certBuffers[i]->length); if (x509 == NULL) { err = 1; } @@ -816,13 +817,13 @@ int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* fname, #endif { 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) { ret = WOLFSSL_BAD_FILE; } } /* 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)) { ret = WOLFSSL_BAD_FILE; } @@ -942,7 +943,7 @@ static WC_INLINE int cm_get_signer_memory(Signer* signer) #endif /* Add dynamic bytes needed. */ - sz += signer->pubKeySize; + sz += (int)signer->pubKeySize; sz += signer->nameLen; return sz; @@ -1103,7 +1104,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm, /* Copy in public key. */ XMEMCPY(publicKey, current + idx, signer->pubKeySize); signer->publicKey = publicKey; - idx += signer->pubKeySize; + idx += (int)signer->pubKeySize; /* Copy in certificate name length. */ 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) { /* 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); if (signer->name == NULL) { ret = MEMORY_E; @@ -1126,7 +1127,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm, if (ret == 0) { /* Copy in certificate name. */ - XMEMCPY(signer->name, current + idx, signer->nameLen); + XMEMCPY(signer->name, current + idx, (size_t)signer->nameLen); idx += signer->nameLen; /* 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); /* Public key. */ - XMEMCPY(current + added, list->publicKey, list->pubKeySize); - added += list->pubKeySize; + XMEMCPY(current + added, list->publicKey, (size_t)list->pubKeySize); + added += (int)list->pubKeySize; /* Certificate name length. */ XMEMCPY(current + added, &list->nameLen, sizeof(list->nameLen)); added += (int)sizeof(list->nameLen); /* Certificate name. */ - XMEMCPY(current + added, list->name, list->nameLen); + XMEMCPY(current + added, list->name, (size_t)list->nameLen); added += list->nameLen; /* Hash of subject name. */ @@ -1287,8 +1288,6 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname) { XFILE file; int ret = WOLFSSL_SUCCESS; - int memSz; - byte* mem; WOLFSSL_ENTER("CM_SaveCertCache"); @@ -1306,17 +1305,18 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname) } if (ret == WOLFSSL_SUCCESS) { + byte* mem; /* 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. */ - mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); + mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER); if (mem == NULL) { WOLFSSL_MSG("Alloc for tmp buffer failed"); ret = MEMORY_E; } if (ret == WOLFSSL_SUCCESS) { /* 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) { /* Write memory to file. */ @@ -1753,7 +1753,7 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm, #endif { /* Initialize decoded certificate with buffer. */ - InitDecodedCert(cert, der, sz, NULL); + InitDecodedCert(cert, der, (word32)sz, NULL); /* Parse certificate and perform CRL checks. */ ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_CRL, cm); @@ -2224,7 +2224,7 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm, #endif { /* Initialize decoded certificate with buffer. */ - InitDecodedCert(cert, der, sz, NULL); + InitDecodedCert(cert, der, (word32)sz, NULL); /* Parse certificate and perform CRL checks. */ 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. */ int urlSz = (int)XSTRLEN(url) + 1; /* 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); if (cm->ocspOverrideURL == NULL) { ret = MEMORY_E; } if (ret == WOLFSSL_SUCCESS) { /* Copy URL into certificate manager. */ - XMEMCPY(cm->ocspOverrideURL, url, urlSz); + XMEMCPY(cm->ocspOverrideURL, url, (size_t)urlSz); } } else { diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index b810638f60..6c037b7922 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -11975,7 +11975,7 @@ static int StoreRsaKey(DecodedCert* cert, const byte* source, word32* srcIdx, #ifdef HAVE_OCSP /* Calculate the hash of the public key for OCSP. */ ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize, - cert->subjectKeyHash, HashIdAlg((int)cert->signatureOID)); + cert->subjectKeyHash, HashIdAlg(cert->signatureOID)); #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. */ ret = CalcHashId_ex(dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.data, dataASN[ECCCERTKEYASN_IDX_SUBJPUBKEY].data.ref.length, - cert->subjectKeyHash, HashIdAlg((int)cert->signatureOID)); + cert->subjectKeyHash, HashIdAlg(cert->signatureOID)); } if (ret == 0) { #endif @@ -12452,7 +12452,7 @@ static int GetCertKey(DecodedCert* cert, const byte* source, word32* inOutIdx, * @param [in] oidSum Signature id. * @return Hash algorithm id. */ -int HashIdAlg(int oidSum) +int HashIdAlg(word32 oidSum) { (void)oidSum; @@ -12912,9 +12912,9 @@ static const byte rdnChoice[] = { static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap) { int ret = 0; - int nameSz; + size_t nameSz; char tmpName[WOLFSSL_MAX_IPSTR] = {0}; - char* ip; + unsigned char* ip; if (entry == NULL || entry->type != ASN_IP_TYPE) { return BAD_FUNC_ARG; @@ -12925,7 +12925,7 @@ static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap) WOLFSSL_MSG("Unexpected IP size"); return BAD_FUNC_ARG; } - ip = entry->name; + ip = (unsigned char*)entry->name; /* store IP addresses as a string */ 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) { - int i; + size_t i; for (i = 0; i < 8; i++) { if (XSNPRINTF(tmpName + i * 5, sizeof(tmpName) - i * 5, "%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); - entry->ipString = (char*)XMALLOC(nameSz + 1, heap, DYNAMIC_TYPE_ALTNAME); + nameSz = XSTRLEN(tmpName); + entry->ipString = (char*)XMALLOC(nameSz + 1, heap, + DYNAMIC_TYPE_ALTNAME); if (entry->ipString == NULL) { 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 * the tag and length. */ if (CalcHashId_ex(input + srcIdx, maxIdx - srcIdx, hash, - HashIdAlg((int)cert->signatureOID)) != 0) { + HashIdAlg(cert->signatureOID)) != 0) { ret = ASN_PARSE_E; } @@ -14030,7 +14031,7 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType, if (nid != 0) { /* Add an entry to the X509_NAME. */ 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; } } @@ -14050,15 +14051,17 @@ static int GetCertName(DecodedCert* cert, char* full, byte* hash, int nameType, #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ defined(HAVE_LIGHTY)) && \ (defined(HAVE_PKCS7) || defined(WOLFSSL_CERT_EXT)) - dName->rawLen = min(cert->issuerRawLen, WC_ASN_NAME_MAX); - XMEMCPY(dName->raw, cert->issuerRaw, dName->rawLen); + dName->rawLen = (int)min((word32)cert->issuerRawLen, + WC_ASN_NAME_MAX); + XMEMCPY(dName->raw, cert->issuerRaw, (size_t)dName->rawLen); #endif cert->issuerName = dName; } else { #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) - dName->rawLen = min(cert->subjectRawLen, WC_ASN_NAME_MAX); - XMEMCPY(dName->raw, cert->subjectRaw, dName->rawLen); + dName->rawLen = (int)min((word32)cert->subjectRawLen, + WC_ASN_NAME_MAX); + XMEMCPY(dName->raw, cert->subjectRaw, (size_t)dName->rawLen); #endif 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 */ - 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) >= len - idx) { @@ -15239,7 +15242,7 @@ word32 SetOthername(void *name, byte *output) { WOLFSSL_ASN1_OTHERNAME *nm = (WOLFSSL_ASN1_OTHERNAME *)name; char *nameStr = NULL; - int nameSz = 0; + word32 nameSz = 0; word32 len = 0; if ((nm == NULL) || (nm->value == NULL)) { @@ -15248,7 +15251,7 @@ word32 SetOthername(void *name, byte *output) } nameStr = nm->value->value.utf8string->data; - nameSz = nm->value->value.utf8string->length; + nameSz = (word32)nm->value->value.utf8string->length; len = nm->type_id->objSz + 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, &cert->altNames); if (ret == 0) { - idx += len; + idx += (word32)len; } } #endif /* WOLFSSL_QT || OPENSSL_ALL */ @@ -18757,7 +18760,7 @@ static int DecodeAuthInfo(const byte* input, word32 sz, DecodedCert* cert) /* Set CaIssuers entry */ GetASN_GetConstRef(&dataASN[ACCESSDESCASN_IDX_LOC], &cert->extAuthInfoCaIssuer, &sz32); - cert->extAuthInfoCaIssuerSz = sz32; + cert->extAuthInfoCaIssuerSz = (int)sz32; count++; } #endif @@ -18940,12 +18943,12 @@ static int DecodeSubjKeyId(const byte* input, word32 sz, DecodedCert* cert) if (ret > 0) { #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) cert->extSubjKeyIdSrc = &input[idx]; - cert->extSubjKeyIdSz = length; + cert->extSubjKeyIdSz = (word32)length; #endif /* OPENSSL_EXTRA */ /* Get the hash or hash of the hash if wrong size. */ ret = GetHashId(input + idx, length, cert->extSubjKeyId, - HashIdAlg((int)cert->signatureOID)); + HashIdAlg(cert->signatureOID)); } 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) /* Keep reference for WOLFSSL_X509. */ cert->extExtKeyUsageSrc = input + idx; - cert->extExtKeyUsageSz = length; + cert->extExtKeyUsageSz = (word32)length; #endif } @@ -19563,7 +19566,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz) w = BUFFER_E; goto exit; } - outIdx += w; + outIdx += (word32)w; val = 0; while (inIdx < inSz && outIdx < outSz) { @@ -19581,7 +19584,7 @@ int DecodePolicyOID(char *out, word32 outSz, const byte *in, word32 inSz) w = BUFFER_E; goto exit; } - outIdx += w; + outIdx += (word32)w; val = 0; } inIdx++; @@ -19872,7 +19875,7 @@ enum { * @return ASN_PARSE_E when BER encoded data does not match ASN.1 items or * 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 word32 idx = 0; @@ -19969,7 +19972,8 @@ static int DecodeSubjDirAttr(const byte* input, int sz, DecodedCert* cert) ret = ASN_PARSE_E; } if (ret == 0) { - XMEMCPY(cert->countryOfCitizenship, setData + setIdx, cuLen); + XMEMCPY(cert->countryOfCitizenship, setData + setIdx, + (size_t)cuLen); cert->countryOfCitizenship[COUNTRY_CODE_LEN] = 0; } } @@ -19994,7 +19998,7 @@ static int DecodeSubjDirAttr(const byte* input, int sz, DecodedCert* cert) * is invalid. * @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; int length = 0; @@ -20047,11 +20051,11 @@ static int DecodeSubjInfoAcc(const byte* input, int sz, DecodedCert* cert) /* Set caRepo entry */ if (b == GENERALNAME_URI && oid == AIA_CA_REPO_OID) { - cert->extSubjInfoAccCaRepoSz = length; + cert->extSubjInfoAccCaRepoSz = (word32)length; cert->extSubjInfoAccCaRepo = input + idx; break; } - idx += length; + idx += (word32)length; } if (cert->extSubjInfoAccCaRepo == NULL || @@ -21522,7 +21526,7 @@ static Signer* GetCABySubjectAndPubKey(DecodedCert* cert, void* cm) * is invalid. * @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) { /* 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; /* Get the hash or hash of the hash if wrong size. */ ret = GetHashId( - dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data, - dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length, - hash, HashIdAlg(sigOID)); + dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.data, + (int)dataASN[AUTHKEYIDASN_IDX_KEYID].data.ref.length, + hash, HashIdAlg(sigOID)); } break; } @@ -22120,7 +22124,7 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap, /* Extract public key information. */ pubKey = ca->publicKey; pubKeySz = ca->pubKeySize; - pubKeyOID = ca->keyOID; + pubKeyOID = (int)ca->keyOID; } else { /* No public key to verify with. */ @@ -22142,7 +22146,8 @@ static int CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap, /* Check signature. */ 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) { WOLFSSL_MSG("Confirm signature failed"); } @@ -22281,7 +22286,7 @@ int wc_CertGetPubKey(const byte* cert, word32 certSz, } /* Skip data if required. */ 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. * Skip first byte of BIT_STRING data: unused bits. */ *pubKey = cert + o + 1; - *pubKeySz = l - 1; + *pubKeySz = (word32)(l - 1); } 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 * block should be hashed. */ ret = CalcHashId_ex(cert->publicKey + cert->pubKeySize - 65, 65, - cert->extSubjKeyId, HashIdAlg((int)cert->signatureOID)); + cert->extSubjKeyId, HashIdAlg(cert->signatureOID)); } else { ret = CalcHashId_ex(cert->publicKey, cert->pubKeySize, - cert->extSubjKeyId, HashIdAlg((int)cert->signatureOID)); + cert->extSubjKeyId, HashIdAlg(cert->signatureOID)); } if (ret != 0) { 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); long neededSz; int ret = 0; - int sz = (int)longSz; + word32 sz = (word32)longSz; int encrypted_key = 0; DerBuffer* der; word32 algId = 0; @@ -23826,7 +23831,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type, /* map header if not found for type */ for (;;) { - headerEnd = XSTRNSTR((char*)buff, header, (word32)sz); + headerEnd = XSTRNSTR((char*)buff, header, sz); if (headerEnd) { break; } @@ -23909,7 +23914,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type, headerEnd = XSTRNSTR((char*)buff, PRIV_KEY_SUFFIX, sz); if (headerEnd) { const char* beginEnd; - int endLen; + unsigned int endLen; beginEnd = headerEnd + XSTR_SIZEOF(PRIV_KEY_SUFFIX); 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 */ - XMEMCPY(beginBuf, headerEnd, beginEnd - headerEnd); + XMEMCPY(beginBuf, headerEnd, (size_t)(beginEnd - headerEnd)); beginBuf[beginEnd - headerEnd] = '\0'; /* look for matching footer */ footer = XSTRNSTR(beginEnd, @@ -23953,10 +23958,10 @@ int PemToDer(const unsigned char* buff, long longSz, int type, return BUFFER_E; } - endLen = (unsigned int)(beginEnd - headerEnd - + endLen = (unsigned int)((size_t)(beginEnd - headerEnd) - (XSTR_SIZEOF(BEGIN_PRIV_KEY_PREFIX) - XSTR_SIZEOF(END_PRIV_KEY_PREFIX))); - XMEMCPY(endBuf, footer, endLen); + XMEMCPY(endBuf, footer, (size_t)endLen); endBuf[endLen] = '\0'; header = beginBuf; @@ -24042,7 +24047,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type, /* set up der buffer */ neededSz = (long)(footerEnd - headerEnd); - if (neededSz > sz || neededSz <= 0) + if (neededSz > (long)sz || neededSz <= 0) return BUFFER_E; ret = AllocDer(pDer, (word32)neededSz, type, heap); @@ -24679,7 +24684,7 @@ int wc_GetUUIDFromCert(struct DecodedCert* cert, byte* uuid, word32* uuidSz) } if (uuid == NULL) { - *uuidSz = id->len; + *uuidSz = (word32)id->len; return LENGTH_ONLY_E; } @@ -24687,7 +24692,7 @@ int wc_GetUUIDFromCert(struct DecodedCert* cert, byte* uuid, word32* uuidSz) return BUFFER_E; } - XMEMCPY(uuid, id->name, id->len); + XMEMCPY(uuid, id->name, (size_t)id->len); ret = 0; /* success */ break; } @@ -24707,7 +24712,7 @@ int wc_GetFASCNFromCert(struct DecodedCert* cert, byte* fascn, word32* fascnSz) id = FindAltName(cert, ASN_OTHER_TYPE, id); if (id != NULL && id->oidSum == FASCN_OID) { if (fascn == NULL) { - *fascnSz = id->len; + *fascnSz = (word32)id->len; return LENGTH_ONLY_E; } @@ -24715,7 +24720,7 @@ int wc_GetFASCNFromCert(struct DecodedCert* cert, byte* fascn, word32* fascnSz) return BUFFER_E; } - XMEMCPY(fascn, id->name, id->len); + XMEMCPY(fascn, id->name, (size_t)id->len); ret = 0; /* success */ } } while (id != NULL); @@ -27319,7 +27324,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz, #ifdef WOLFSSL_AKID_NAME if (cert->rawAkid) { SetASN_Buffer(&dataASN[CERTEXTSASN_IDX_AKID_STR], - cert->akid, cert->akidSz); + cert->akid, (word32)cert->akidSz); /* cert->akid contains the internal ext structure */ SetASNItem_NoOutBelow(dataASN, certExtsASN, 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 */ 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); #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) cert->skidSz = wc_HashGetDigestSize(wc_HashTypeConvert(hashId)); @@ -30164,7 +30169,7 @@ static int SetKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey, ecc_key *eckey, #endif } 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); #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) 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. */ SetASN_Items(dhParamASN, dataASN, dhParamASN_Length, out); /* Set the actual encoding size. */ - *outLen = sz; + *outLen = (word32)sz; } return ret; @@ -34116,8 +34121,8 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size, if (ret == 0) { single->hashAlgoOID = dataASN[SINGLERESPONSEASN_IDX_CID_HASHALGO_OID].data.oid.sum; - ocspDigestSize = wc_HashGetDigestSize( - wc_OidGetHash(single->hashAlgoOID)); + ocspDigestSize = (word32)wc_HashGetDigestSize( + wc_OidGetHash((int)single->hashAlgoOID)); } /* Validate the issuer hash length is the size required. */ if ((ret == 0) && (issuerHashLen != ocspDigestSize)) { @@ -34129,7 +34134,7 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size, } if (ret == 0) { /* Store serial size. */ - cs->serialSz = serialSz; + cs->serialSz = (int)serialSz; /* Set the hash algorithm OID */ single->hashAlgoOID = 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->type = ASN_GENERALIZED_TIME; XMEMCPY(at->data, cs->thisDate, thisDateLen); - at->length = thisDateLen; + at->length = (int)thisDateLen; #endif } if ((ret == 0) && @@ -34187,7 +34192,7 @@ static int DecodeSingleResponse(byte* source, word32* ioIndex, word32 size, at = &cs->nextDateParsed; at->type = ASN_GENERALIZED_TIME; XMEMCPY(at->data, cs->nextDate, nextDateLen); - at->length = nextDateLen; + at->length = (int)nextDateLen; #endif } if (ret == 0) { @@ -34328,7 +34333,7 @@ static int DecodeOcspRespExtensions(byte* source, word32* ioIndex, source, &idx, sz); if (ret == 0) { 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) { /* Extract nonce data. */ @@ -34343,7 +34348,7 @@ static int DecodeOcspRespExtensions(byte* source, word32* ioIndex, /* Ignore all other extension types. */ /* Skip over rest of extension. */ - idx += length; + idx += (word32)length; } } @@ -34563,8 +34568,8 @@ static int DecodeResponseData(byte* source, word32* ioIndex, if (ret == 0) { /* Decode SingleResponse into OcspEntry. */ ret = DecodeSingleResponse(source, &idx, - dataASN[OCSPRESPDATAASN_IDX_RESPEXT].offset, - dataASN[OCSPRESPDATAASN_IDX_RESP].length, single); + dataASN[OCSPRESPDATAASN_IDX_RESPEXT].offset, + (int)dataASN[OCSPRESPDATAASN_IDX_RESP].length, single); /* 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, sizeof(NonceObjId)); SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_NONCE], req->nonce, - req->nonceSz); + (word32)req->nonceSz); /* Calculate size of nonce extension. */ ret = SizeASN_Items(ocspNonceExtASN, dataASN, ocspNonceExtASN_Length, &sz); @@ -35293,7 +35298,7 @@ word32 EncodeOcspRequestExtensions(OcspRequest* req, byte* output, word32 size) FREE_ASNSETDATA(dataASN, req->heap); } - return ret; + return (word32)ret; #endif /* WOLFSSL_ASN_TEMPLATE */ } @@ -35429,7 +35434,7 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size) word32 extSz = 0; int sz = 0; int ret = 0; - int keyIdSz; + word32 keyIdSz; WOLFSSL_ENTER("EncodeOcspRequest"); @@ -35453,11 +35458,11 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size) SetASN_Buffer(&dataASN[OCSPREQUESTASN_IDX_TBS_REQ_ISSUERKEY], req->issuerKeyHash, keyIdSz); 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. */ if (req->nonceSz) { /* 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); if (ret > 0) { ret = 0; @@ -35482,7 +35487,7 @@ int EncodeOcspRequest(OcspRequest* req, byte* output, word32 size) SetASN_Items(ocspRequestASN, dataASN, ocspRequestASN_Length, output); if (req->nonceSz) { /* Encode extensions into space provided. */ - ret = EncodeOcspRequestExtensions(req, + ret = (int)EncodeOcspRequestExtensions(req, (byte*)dataASN[OCSPREQUESTASN_IDX_TBS_REQEXT].data.buffer.data, extSz); if (ret > 0) { @@ -35519,24 +35524,24 @@ int InitOcspRequest(OcspRequest* req, DecodedCert* cert, byte useNonce, XMEMCPY(req->issuerHash, cert->issuerHash, 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); if (req->serial == NULL) return MEMORY_E; - XMEMCPY(req->serial, cert->serial, cert->serialSz); + XMEMCPY(req->serial, cert->serial, (size_t)cert->serialSz); req->serialSz = cert->serialSz; if (cert->extAuthInfoSz != 0 && cert->extAuthInfo != NULL) { - req->url = (byte*)XMALLOC(cert->extAuthInfoSz + 1, req->heap, - DYNAMIC_TYPE_OCSP_REQUEST); + req->url = (byte*)XMALLOC((size_t)cert->extAuthInfoSz + 1, + req->heap, DYNAMIC_TYPE_OCSP_REQUEST); if (req->url == NULL) { XFREE(req->serial, req->heap, DYNAMIC_TYPE_OCSP); req->serial = NULL; return MEMORY_E; } - XMEMCPY(req->url, cert->extAuthInfo, cert->extAuthInfoSz); + XMEMCPY(req->url, cert->extAuthInfo, (size_t)cert->extAuthInfoSz); req->urlSz = cert->extAuthInfoSz; req->url[req->urlSz] = 0; } @@ -35629,7 +35634,7 @@ int CompareOcspReqResp(OcspRequest* req, OcspResponse* resp) return cmp; } - cmp = XMEMCMP(req->nonce, resp->nonce, req->nonceSz); + cmp = XMEMCMP(req->nonce, resp->nonce, (size_t)req->nonceSz); if (cmp != 0) { WOLFSSL_MSG("\tnonce mismatch"); return cmp; @@ -35646,9 +35651,12 @@ int CompareOcspReqResp(OcspRequest* req, OcspResponse* resp) #endif cmp = req->serialSz - single->status->serialSz; if (cmp == 0) { - cmp = XMEMCMP(req->serial, single->status->serial, req->serialSz) - || XMEMCMP(req->issuerHash, single->issuerHash, ocspDigestSize) - || XMEMCMP(req->issuerKeyHash, single->issuerKeyHash, ocspDigestSize); + cmp = XMEMCMP(req->serial, single->status->serial, + (size_t)req->serialSz) + || XMEMCMP(req->issuerHash, single->issuerHash, + (size_t)ocspDigestSize) + || XMEMCMP(req->issuerKeyHash, single->issuerKeyHash, + (size_t)ocspDigestSize); if (cmp == 0) { /* match found */ 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 */ int GetNameHash_ex(const byte* source, word32* idx, byte* hash, int maxIdx, - int sigOID) + word32 sigOID) { #ifndef WOLFSSL_ASN_TEMPLATE int length; /* length of all distinguished names */ @@ -35767,13 +35775,13 @@ static char* GetNameFromDer(const byte* source, int sz) { char* out; - out = (char*)XMALLOC(sz, NULL, DYNAMIC_TYPE_OPENSSL); + out = (char*)XMALLOC((size_t)sz, NULL, DYNAMIC_TYPE_OPENSSL); if (out == NULL) { WOLFSSL_MSG("Name malloc failed"); return NULL; } - XMEMCPY(out, source, sz); + XMEMCPY(out, source, (size_t)sz); return out; } @@ -35839,7 +35847,7 @@ enum { /* Get Revoked Cert list, 0 on success */ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx, - DecodedCRL* dcrl, int maxIdx) + DecodedCRL* dcrl, word32 maxIdx) { #ifndef WOLFSSL_ASN_TEMPLATE int ret; @@ -35943,7 +35951,7 @@ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx, } if (ret == 0) { /* Store size of serial number. */ - rc->serialSz = serialSz; + rc->serialSz = (int)serialSz; rc->revDateFormat = (dataASN[REVOKEDASN_IDX_TIME_UTC].tag != 0) ? dataASN[REVOKEDASN_IDX_TIME_UTC].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) { /* Parse an authority key identifier. */ ret = GetASN_Items(authKeyIdASN, dataASN, authKeyIdASN_Length, 1, input, - &idx, sz); + &idx, (word32)sz); } if (ret == 0) { /* Key id is optional. */ @@ -36256,7 +36264,7 @@ static int ParseCRL_AuthKeyIdExt(const byte* input, int sz, DecodedCRL* dcrl) else { /* Get the hash or hash of the hash if wrong size. */ 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)); } } @@ -36447,7 +36455,7 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx, /* OID in extension. */ word32 oid = dataASN[CERTEXTASN_IDX_OID].data.oid.sum; /* Length of extension data. */ - int length = dataASN[CERTEXTASN_IDX_VAL].length; + int length = (int)dataASN[CERTEXTASN_IDX_VAL].length; if (oid == AUTH_KEY_OID) { #ifndef NO_SKID @@ -36462,7 +36470,7 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx, /* TODO: Parse CRL Number extension */ /* TODO: check criticality */ /* Move index on to next extension. */ - idx += length; + idx += (word32)length; } } diff --git a/wolfcrypt/src/camellia.c b/wolfcrypt/src/camellia.c index 76912b1eb9..9f2897f281 100644 --- a/wolfcrypt/src/camellia.c +++ b/wolfcrypt/src/camellia.c @@ -1464,7 +1464,7 @@ static void camellia_decrypt256(const u32 *subkey, u32 *io) * API for compatibility */ -static void Camellia_EncryptBlock(const int keyBitLength, +static void Camellia_EncryptBlock(const word32 keyBitLength, const unsigned char *plaintext, const KEY_TABLE_TYPE keyTable, unsigned char *ciphertext) @@ -1495,7 +1495,7 @@ static void Camellia_EncryptBlock(const int keyBitLength, PUTU32(ciphertext + 12, tmp[3]); } -static void Camellia_DecryptBlock(const int keyBitLength, +static void Camellia_DecryptBlock(const word32 keyBitLength, const unsigned char *ciphertext, const KEY_TABLE_TYPE keyTable, unsigned char *plaintext) diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 0fc7b85d7d..4fd5ac4cf5 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -430,7 +430,7 @@ int wolfSSL_EVP_DecryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx, WOLFSSL_EVP_CIPHER_CTX *wolfSSL_EVP_CIPHER_CTX_new(void) { - WOLFSSL_EVP_CIPHER_CTX *ctx = (WOLFSSL_EVP_CIPHER_CTX*)XMALLOC(sizeof *ctx, + WOLFSSL_EVP_CIPHER_CTX *ctx = (WOLFSSL_EVP_CIPHER_CTX*)XMALLOC(sizeof(*ctx), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (ctx) { WOLFSSL_ENTER("wolfSSL_EVP_CIPHER_CTX_new"); @@ -548,7 +548,7 @@ static int fillBuff(WOLFSSL_EVP_CIPHER_CTX *ctx, const unsigned char *in, int sz } else { fill = sz; } - XMEMCPY(&(ctx->buf[ctx->bufUsed]), in, fill); + XMEMCPY(&(ctx->buf[ctx->bufUsed]), in, (size_t)fill); ctx->bufUsed += fill; return fill; } else return 0; @@ -556,9 +556,10 @@ static int fillBuff(WOLFSSL_EVP_CIPHER_CTX *ctx, const unsigned char *in, int sz static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, int inl) + const unsigned char *in, int inLen) { int ret = 0; + word32 inl = (word32)inLen; switch (ctx->cipherType) { #if !defined(NO_AES) @@ -636,10 +637,10 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx, case AES_256_XTS_TYPE: if (ctx->enc) ret = wc_AesXtsEncrypt(&ctx->cipher.xts, out, in, inl, - ctx->iv, ctx->ivSz); + ctx->iv, (word32)ctx->ivSz); else ret = wc_AesXtsDecrypt(&ctx->cipher.xts, out, in, inl, - ctx->iv, ctx->ivSz); + ctx->iv, (word32)ctx->ivSz); break; #endif #endif /* !NO_AES */ @@ -709,10 +710,10 @@ static int wolfSSL_EVP_CipherUpdate_GCM_AAD(WOLFSSL_EVP_CIPHER_CTX *ctx, const unsigned char *in, int inl) { if (in && inl > 0) { byte* tmp = (byte*)XREALLOC(ctx->authIn, - ctx->authInSz + inl, NULL, DYNAMIC_TYPE_OPENSSL); + (size_t)(ctx->authInSz + inl), NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { ctx->authIn = tmp; - XMEMCPY(ctx->authIn + ctx->authInSz, in, inl); + XMEMCPY(ctx->authIn + ctx->authInSz, in, (size_t)inl); ctx->authInSz += inl; } else { @@ -726,8 +727,10 @@ static int wolfSSL_EVP_CipherUpdate_GCM_AAD(WOLFSSL_EVP_CIPHER_CTX *ctx, static int wolfSSL_EVP_CipherUpdate_GCM(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, - const unsigned char *in, int inl) + const unsigned char *in, int inLen) { + word32 inl = (word32)inLen; + #if defined(WOLFSSL_SM4_GCM) || !defined(WOLFSSL_AESGCM_STREAM) #if defined(WOLFSSL_SM4_GCM) && defined(WOLFSSL_AESGCM_STREAM) if (ctx->cipherType == SM4_GCM_TYPE) @@ -741,10 +744,10 @@ static int wolfSSL_EVP_CipherUpdate_GCM(WOLFSSL_EVP_CIPHER_CTX *ctx, if (inl > 0) { byte* tmp; tmp = (byte*)XREALLOC(ctx->authBuffer, - ctx->authBufferLen + inl, NULL, + (size_t)(ctx->authBufferLen + inl), NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { - XMEMCPY(tmp + ctx->authBufferLen, in, inl); + XMEMCPY(tmp + ctx->authBufferLen, in, (size_t)inl); ctx->authBufferLen += inl; ctx->authBuffer = tmp; *outl = 0; @@ -795,7 +798,7 @@ static int wolfSSL_EVP_CipherUpdate_GCM(WOLFSSL_EVP_CIPHER_CTX *ctx, NULL, 0); } } - *outl = inl; + *outl = (int)inl; if (ret == 0) { ret = WOLFSSL_SUCCESS; } @@ -813,10 +816,10 @@ static int wolfSSL_EVP_CipherUpdate_CCM_AAD(WOLFSSL_EVP_CIPHER_CTX *ctx, const unsigned char *in, int inl) { if (in && inl > 0) { byte* tmp = (byte*)XREALLOC(ctx->authIn, - ctx->authInSz + inl, NULL, DYNAMIC_TYPE_OPENSSL); + (size_t)(ctx->authInSz + inl), NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { ctx->authIn = tmp; - XMEMCPY(ctx->authIn + ctx->authInSz, in, inl); + XMEMCPY(ctx->authIn + ctx->authInSz, in, (size_t)inl); ctx->authInSz += inl; } else { @@ -839,10 +842,10 @@ static int wolfSSL_EVP_CipherUpdate_CCM(WOLFSSL_EVP_CIPHER_CTX *ctx, if (inl > 0) { byte* tmp; tmp = (byte*)XREALLOC(ctx->authBuffer, - ctx->authBufferLen + inl, NULL, + (size_t)(ctx->authBufferLen + inl), NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { - XMEMCPY(tmp + ctx->authBufferLen, in, inl); + XMEMCPY(tmp + ctx->authBufferLen, in, (size_t)inl); ctx->authBufferLen += inl; ctx->authBuffer = tmp; *outl = 0; @@ -871,10 +874,10 @@ static int wolfSSL_EVP_CipherUpdate_AriaGCM_AAD(WOLFSSL_EVP_CIPHER_CTX *ctx, { if (in && inl > 0) { byte* tmp = (byte*)XREALLOC(ctx->authIn, - ctx->authInSz + inl, NULL, DYNAMIC_TYPE_OPENSSL); + (size_t)ctx->authInSz + inl, NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { ctx->authIn = tmp; - XMEMCPY(ctx->authIn + ctx->authInSz, in, inl); + XMEMCPY(ctx->authIn + ctx->authInSz, in, (size_t)inl); ctx->authInSz += inl; } else { @@ -901,10 +904,10 @@ static int wolfSSL_EVP_CipherUpdate_AriaGCM(WOLFSSL_EVP_CIPHER_CTX *ctx, size = WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(size); } tmp = (byte*)XREALLOC(ctx->authBuffer, - size, NULL, + (size_t)size, NULL, DYNAMIC_TYPE_OPENSSL); if (tmp) { - XMEMCPY(tmp + ctx->authBufferLen, in, inl); + XMEMCPY(tmp + ctx->authBufferLen, in, (size_t)inl); ctx->authBufferLen += inl; ctx->authBuffer = tmp; *outl = 0; @@ -980,7 +983,7 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, case CHACHA20_POLY1305_TYPE: if (out == NULL) { if (wc_ChaCha20Poly1305_UpdateAad(&ctx->cipher.chachaPoly, in, - inl) != 0) { + (word32)inl) != 0) { WOLFSSL_MSG("wc_ChaCha20Poly1305_UpdateAad failed"); return WOLFSSL_FAILURE; } @@ -991,7 +994,7 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, } else { if (wc_ChaCha20Poly1305_UpdateData(&ctx->cipher.chachaPoly, in, - out, inl) != 0) { + out, (word32)inl) != 0) { WOLFSSL_MSG("wc_ChaCha20Poly1305_UpdateData failed"); return WOLFSSL_FAILURE; } @@ -1003,7 +1006,8 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, #endif #ifdef HAVE_CHACHA case CHACHA20_TYPE: - if (wc_Chacha_Process(&ctx->cipher.chacha, out, in, inl) != 0) { + if (wc_Chacha_Process(&ctx->cipher.chacha, out, in, (word32)inl) != + 0) { WOLFSSL_MSG("wc_ChaCha_Process failed"); return WOLFSSL_FAILURE; } @@ -1048,7 +1052,7 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, * Update the last block stored if one has already been stored */ if (ctx->enc == 0) { if (ctx->lastUsed == 1) { - XMEMCPY(out, ctx->lastBlock, ctx->block_size); + XMEMCPY(out, ctx->lastBlock, (size_t)ctx->block_size); *outl+= ctx->block_size; out += ctx->block_size; } @@ -1077,7 +1081,7 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, * Update the last block stored if one has already been stored */ if ((ctx->enc == 0) && (ctx->lastUsed == 1)) { PRINT_BUF(ctx->lastBlock, ctx->block_size); - XMEMCPY(out, ctx->lastBlock, ctx->block_size); + XMEMCPY(out, ctx->lastBlock, (size_t)ctx->block_size); *outl += ctx->block_size; out += ctx->block_size; ctx->lastUsed = 0; @@ -1104,7 +1108,7 @@ int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx, blocks = blocks - 1; /* save last block to check padding in * EVP_CipherFinal call */ XMEMCPY(ctx->lastBlock, &out[ctx->block_size * blocks], - ctx->block_size); + (size_t)ctx->block_size); } *outl += ctx->block_size * blocks; } @@ -1150,7 +1154,7 @@ static int checkPad(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *buff) static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz) { int i; - for (i = ctrSz-1; i >= 0; i--) { + for (i = (int)ctrSz-1; i >= 0; i--) { if (++ctr[i]) break; } @@ -1212,11 +1216,11 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, *outl = 0; if (ctx->enc) { ret = wc_AesGcmEncryptFinal(&ctx->cipher.aes, ctx->authTag, - ctx->authTagSz); + (word32)ctx->authTagSz); } else { ret = wc_AesGcmDecryptFinal(&ctx->cipher.aes, ctx->authTag, - ctx->authTagSz); + (word32)ctx->authTagSz); if (ctx->authIncIv) { IncCtr((byte*)ctx->cipher.aes.reg, ctx->cipher.aes.nonceSz); } @@ -1225,7 +1229,7 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, /* Reinitialize for subsequent wolfSSL_EVP_Cipher calls. */ if (wc_AesGcmInit(&ctx->cipher.aes, NULL, 0, (byte*)ctx->cipher.aes.reg, - ctx->ivSz) != 0) { + (word32)ctx->ivSz) != 0) { WOLFSSL_MSG("wc_AesGcmInit failed"); ret = WOLFSSL_FAILURE; } @@ -1259,16 +1263,20 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, case AES_256_CCM_TYPE: if ((ctx->authBuffer && ctx->authBufferLen > 0) || (ctx->authBufferLen == 0)) { - if (ctx->enc) + if (ctx->enc) { ret = wc_AesCcmEncrypt(&ctx->cipher.aes, out, - ctx->authBuffer, ctx->authBufferLen, - ctx->iv, ctx->ivSz, ctx->authTag, ctx->authTagSz, - ctx->authIn, ctx->authInSz); - else + ctx->authBuffer, (word32)ctx->authBufferLen, + ctx->iv, (word32)ctx->ivSz, ctx->authTag, + (word32)ctx->authTagSz, ctx->authIn, + (word32)ctx->authInSz); + } + else { ret = wc_AesCcmDecrypt(&ctx->cipher.aes, out, - ctx->authBuffer, ctx->authBufferLen, - ctx->iv, ctx->ivSz, ctx->authTag, ctx->authTagSz, - ctx->authIn, ctx->authInSz); + ctx->authBuffer, (word32)ctx->authBufferLen, + ctx->iv, (word32)ctx->ivSz, ctx->authTag, + (word32)ctx->authTagSz, ctx->authIn, + (word32)ctx->authInSz); + } if (ret == 0) { ret = WOLFSSL_SUCCESS; @@ -1516,7 +1524,7 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int fl; PRINT_BUF(ctx->lastBlock, ctx->block_size); if ((fl = checkPad(ctx, ctx->lastBlock)) >= 0) { - XMEMCPY(out, ctx->lastBlock, fl); + XMEMCPY(out, ctx->lastBlock, (size_t)fl); *outl = fl; if (ctx->lastUsed == 0 && ctx->bufUsed == 0) { /* return error in cases where the block length is @@ -1596,7 +1604,7 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, || ctx->cipherType == SM4_CCM_TYPE #endif ) { - ctx->authIvGenEnable = tmp; + ctx->authIvGenEnable = (tmp == 1); } #endif } @@ -1641,7 +1649,7 @@ int wolfSSL_EVP_DecryptFinal_legacy(WOLFSSL_EVP_CIPHER_CTX *ctx, fl = ctx->block_size; } else { - XMEMCPY(out, ctx->lastBlock, fl); + XMEMCPY(out, ctx->lastBlock, (size_t)fl); } *outl = fl; } @@ -2174,14 +2182,14 @@ unsigned long WOLFSSL_EVP_CIPHER_mode(const WOLFSSL_EVP_CIPHER *cipher) void wolfSSL_EVP_CIPHER_CTX_set_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags) { if (ctx != NULL) { - ctx->flags |= flags; + ctx->flags |= (unsigned long)flags; } } void wolfSSL_EVP_CIPHER_CTX_clear_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags) { if (ctx != NULL) { - ctx->flags &= ~flags; + ctx->flags &= (unsigned long)~flags; } } @@ -2198,7 +2206,7 @@ int wolfSSL_EVP_CIPHER_CTX_set_padding(WOLFSSL_EVP_CIPHER_CTX *ctx, if (ctx == NULL) return BAD_FUNC_ARG; if (padding) { - ctx->flags &= ~WOLFSSL_EVP_CIPH_NO_PADDING; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_NO_PADDING; } else { ctx->flags |= WOLFSSL_EVP_CIPH_NO_PADDING; @@ -2541,7 +2549,7 @@ int wolfSSL_EVP_PKEY_derive(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *key, size_ return WOLFSSL_FAILURE; } /* Length of extract only is always the length of the hash. */ - *keylen = hkdfHashSz; + *keylen = (size_t)hkdfHashSz; } } else if (ctx->pkey->hkdfMode == EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) { @@ -2609,14 +2617,15 @@ int wolfSSL_EVP_PKEY_CTX_set1_hkdf_salt(WOLFSSL_EVP_PKEY_CTX* ctx, if (ctx->pkey->hkdfSalt != NULL) { XFREE(ctx->pkey->hkdfSalt, NULL, DYNAMIC_TYPE_SALT); } - ctx->pkey->hkdfSalt = (byte*)XMALLOC(saltSz, NULL, DYNAMIC_TYPE_SALT); + ctx->pkey->hkdfSalt = (byte*)XMALLOC((size_t)saltSz, NULL, + DYNAMIC_TYPE_SALT); if (ctx->pkey->hkdfSalt == NULL) { WOLFSSL_MSG("Failed to allocate HKDF salt buffer."); ret = WOLFSSL_FAILURE; } else { - XMEMCPY(ctx->pkey->hkdfSalt, salt, saltSz); - ctx->pkey->hkdfSaltSz = saltSz; + XMEMCPY(ctx->pkey->hkdfSalt, salt, (size_t)saltSz); + ctx->pkey->hkdfSaltSz = (word32)saltSz; } } @@ -2645,14 +2654,15 @@ int wolfSSL_EVP_PKEY_CTX_set1_hkdf_key(WOLFSSL_EVP_PKEY_CTX* ctx, if (ctx->pkey->hkdfKey != NULL) { XFREE(ctx->pkey->hkdfKey, NULL, DYNAMIC_TYPE_KEY); } - ctx->pkey->hkdfKey = (byte*)XMALLOC(keySz, NULL, DYNAMIC_TYPE_KEY); + ctx->pkey->hkdfKey = (byte*)XMALLOC((size_t)keySz, NULL, + DYNAMIC_TYPE_KEY); if (ctx->pkey->hkdfKey == NULL) { WOLFSSL_MSG("Failed to allocate HKDF key buffer."); ret = WOLFSSL_FAILURE; } else { - XMEMCPY(ctx->pkey->hkdfKey, key, keySz); - ctx->pkey->hkdfKeySz = keySz; + XMEMCPY(ctx->pkey->hkdfKey, key, (size_t)keySz); + ctx->pkey->hkdfKeySz = (word32)keySz; } } @@ -2680,8 +2690,9 @@ int wolfSSL_EVP_PKEY_CTX_add1_hkdf_info(WOLFSSL_EVP_PKEY_CTX* ctx, if (ret == WOLFSSL_SUCCESS && info != NULL && infoSz > 0) { unsigned char* p; /* If there's already info in the buffer, append. */ - p = (byte*)XREALLOC(ctx->pkey->hkdfInfo, ctx->pkey->hkdfInfoSz + infoSz, - NULL, DYNAMIC_TYPE_INFO); + p = (byte*)XREALLOC(ctx->pkey->hkdfInfo, + (size_t)(ctx->pkey->hkdfInfoSz + (word32)infoSz), NULL, + DYNAMIC_TYPE_INFO); if (p == NULL) { WOLFSSL_MSG("Failed to reallocate larger HKDF info buffer."); ret = WOLFSSL_FAILURE; @@ -2689,8 +2700,8 @@ int wolfSSL_EVP_PKEY_CTX_add1_hkdf_info(WOLFSSL_EVP_PKEY_CTX* ctx, else { ctx->pkey->hkdfInfo = p; XMEMCPY(ctx->pkey->hkdfInfo + ctx->pkey->hkdfInfoSz, info, - infoSz); - ctx->pkey->hkdfInfoSz += infoSz; + (size_t)infoSz); + ctx->pkey->hkdfInfoSz += (word32)infoSz; } } @@ -2777,7 +2788,7 @@ int wolfSSL_EVP_PKEY_decrypt(WOLFSSL_EVP_PKEY_CTX *ctx, return WOLFSSL_FAILURE; } - *outLen = len; + *outLen = (size_t)len; return WOLFSSL_SUCCESS; } @@ -2785,7 +2796,7 @@ int wolfSSL_EVP_PKEY_decrypt(WOLFSSL_EVP_PKEY_CTX *ctx, ctx->pkey->rsa, ctx->padding); if (len < 0) break; else { - *outLen = len; + *outLen = (size_t)len; return WOLFSSL_SUCCESS; } #endif /* NO_RSA */ @@ -2880,7 +2891,7 @@ int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx, return WOLFSSL_FAILURE; } - *outLen = len; + *outLen = (size_t)len; return WOLFSSL_SUCCESS; } @@ -2889,7 +2900,7 @@ int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx, if (len < 0) break; else { - *outLen = len; + *outLen = (size_t)len; return WOLFSSL_SUCCESS; } #endif /* NO_RSA */ @@ -3028,7 +3039,7 @@ int wolfSSL_EVP_PKEY_sign(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *sig, return WOLFSSL_FAILURE; bytes *= 2; if (!sig) { - *siglen = bytes; + *siglen = (size_t)bytes; return WOLFSSL_SUCCESS; } if ((int)*siglen < bytes) @@ -3039,7 +3050,7 @@ int wolfSSL_EVP_PKEY_sign(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *sig, return ret; if (bytes == WOLFSSL_FAILURE) return WOLFSSL_FAILURE; - *siglen = bytes; + *siglen = (size_t)bytes; return WOLFSSL_SUCCESS; } #endif /* NO_DSA */ @@ -3062,7 +3073,7 @@ int wolfSSL_EVP_PKEY_sign(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *sig, ret = wc_ecc_sig_size(eckey); if (ret == 0) return WOLFSSL_FAILURE; - *siglen = ret; + *siglen = (size_t)ret; return WOLFSSL_SUCCESS; } ecdsaSig = wolfSSL_ECDSA_do_sign(tbs, (int)tbslen, ctx->pkey->ecc); @@ -3077,7 +3088,7 @@ int wolfSSL_EVP_PKEY_sign(WOLFSSL_EVP_PKEY_CTX *ctx, unsigned char *sig, wolfSSL_ECDSA_SIG_free(ecdsaSig); if (ret == 0) return WOLFSSL_FAILURE; - *siglen = ret; + *siglen = (size_t)ret; return WOLFSSL_SUCCESS; } #endif /* HAVE_ECC */ @@ -3650,7 +3661,7 @@ int wolfSSL_EVP_PKEY_cmp(const WOLFSSL_EVP_PKEY *a, const WOLFSSL_EVP_PKEY *b) /* check public key */ if (a->pkey.ptr && b->pkey.ptr) { - if (XMEMCMP(a->pkey.ptr, b->pkey.ptr, a->pkey_sz) != 0) { + if (XMEMCMP(a->pkey.ptr, b->pkey.ptr, (size_t)a->pkey_sz) != 0) { return WS_RETURN_CODE(ret, WOLFSSL_FAILURE); } } @@ -3904,7 +3915,7 @@ int wolfSSL_EVP_SignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sigret, bytes = wolfSSL_BN_num_bytes(pkey->dsa->q); if (bytes == WOLFSSL_FAILURE || (int)*siglen < bytes * 2) return WOLFSSL_FAILURE; - *siglen = bytes * 2; + *siglen = (unsigned int)(bytes * 2); return WOLFSSL_SUCCESS; } #endif @@ -4016,14 +4027,15 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_mac_key(int type, WOLFSSL_ENGINE* e, pkey = wolfSSL_EVP_PKEY_new(); if (pkey != NULL) { - pkey->pkey.ptr = (char*)XMALLOC(keylen, NULL, DYNAMIC_TYPE_PUBLIC_KEY); + pkey->pkey.ptr = (char*)XMALLOC((size_t)keylen, NULL, + DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL && keylen > 0) { wolfSSL_EVP_PKEY_free(pkey); pkey = NULL; } else { if (keylen) { - XMEMCPY(pkey->pkey.ptr, key, keylen); + XMEMCPY(pkey->pkey.ptr, key, (size_t)keylen); } pkey->pkey_sz = keylen; pkey->type = pkey->save_type = type; @@ -4064,7 +4076,8 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_CMAC_key(WOLFSSL_ENGINE* e, pkey = wolfSSL_EVP_PKEY_new(); if (pkey != NULL) { - pkey->pkey.ptr = (char*)XMALLOC(len, NULL, DYNAMIC_TYPE_PUBLIC_KEY); + pkey->pkey.ptr = (char*)XMALLOC((size_t)len, NULL, + DYNAMIC_TYPE_PUBLIC_KEY); if (pkey->pkey.ptr == NULL && len > 0) { wolfSSL_EVP_PKEY_free(pkey); pkey = NULL; @@ -4072,7 +4085,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_CMAC_key(WOLFSSL_ENGINE* e, } else { if (len) { - XMEMCPY(pkey->pkey.ptr, priv, len); + XMEMCPY(pkey->pkey.ptr, priv, (size_t)len); } pkey->pkey_sz = (int)len; pkey->type = pkey->save_type = EVP_PKEY_CMAC; @@ -4259,9 +4272,9 @@ static int wolfssl_evp_digest_pk_final(WOLFSSL_EVP_MD_CTX *ctx, } /* Get the length of the mac based on the digest algorithm. */ -static int wolfssl_mac_len(unsigned char macType) +static unsigned int wolfssl_mac_len(unsigned char macType) { - int hashLen; + unsigned int hashLen; switch (macType) { #ifndef NO_MD5 @@ -4391,7 +4404,7 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig, #ifndef NO_RSA else if (ctx->pctx->pkey->type == EVP_PKEY_RSA) { if (sig == NULL) { - *siglen = wolfSSL_RSA_size(ctx->pctx->pkey->rsa); + *siglen = (size_t)wolfSSL_RSA_size(ctx->pctx->pkey->rsa); return WOLFSSL_SUCCESS; } } @@ -4400,8 +4413,8 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig, else if (ctx->pctx->pkey->type == EVP_PKEY_EC) { if (sig == NULL) { /* SEQ + INT + INT */ - *siglen = ecc_sets[ctx->pctx->pkey->ecc->group->curve_idx].size * 2 - + 8; + *siglen = (size_t)ecc_sets[ctx->pctx->pkey->ecc->group->curve_idx]. + size * 2 + 8; return WOLFSSL_SUCCESS; } } @@ -4416,7 +4429,7 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig, *siglen = hashLen; /* May be a truncated signature. */ - XMEMCPY(sig, digest, *siglen); + XMEMCPY(sig, digest, (size_t)*siglen); ret = WOLFSSL_SUCCESS; } else { @@ -4444,7 +4457,7 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig, case EVP_PKEY_EC: { int len; WOLFSSL_ECDSA_SIG *ecdsaSig; - ecdsaSig = wolfSSL_ECDSA_do_sign(digest, hashLen, + ecdsaSig = wolfSSL_ECDSA_do_sign(digest, (int)hashLen, ctx->pctx->pkey->ecc); if (ecdsaSig == NULL) break; @@ -4452,7 +4465,7 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig, wolfSSL_ECDSA_SIG_free(ecdsaSig); if (len == 0) break; - *siglen = len; + *siglen = (size_t)len; ret = WOLFSSL_SUCCESS; break; } @@ -4518,7 +4531,7 @@ int wolfSSL_EVP_DigestVerifyFinal(WOLFSSL_EVP_MD_CTX *ctx, if (ctx->isHMAC) { /* Check HMAC result matches the signature. */ - if (XMEMCMP(sig, digest, siglen) == 0) + if (XMEMCMP(sig, digest, (size_t)siglen) == 0) return WOLFSSL_SUCCESS; return WOLFSSL_FAILURE; } @@ -4547,7 +4560,7 @@ int wolfSSL_EVP_DigestVerifyFinal(WOLFSSL_EVP_MD_CTX *ctx, ecdsaSig = wolfSSL_d2i_ECDSA_SIG(NULL, &sig, (long)siglen); if (ecdsaSig == NULL) return WOLFSSL_FAILURE; - ret = wolfSSL_ECDSA_do_verify(digest, hashLen, ecdsaSig, + ret = wolfSSL_ECDSA_do_verify(digest, (int)hashLen, ecdsaSig, ctx->pctx->pkey->ecc); wolfSSL_ECDSA_SIG_free(ecdsaSig); return ret; @@ -5862,13 +5875,13 @@ void wolfSSL_EVP_init(void) break; } /* arg is 4...(ctx->ivSz - 8) */ - XMEMCPY(ctx->iv, ptr, arg); + XMEMCPY(ctx->iv, ptr, (size_t)arg); if (wc_InitRng(&rng) != 0) { WOLFSSL_MSG("wc_InitRng failed"); break; } - if (wc_RNG_GenerateBlock(&rng, ctx->iv + arg, - ctx->ivSz - arg) == 0) { + if (wc_RNG_GenerateBlock(&rng, ctx->iv + arg, + (word32)(ctx->ivSz - arg)) == 0) { ret = WOLFSSL_SUCCESS; } else { /* rng is freed immediately after if block so no need @@ -5920,14 +5933,14 @@ void wolfSSL_EVP_init(void) break; } if (arg <= 0 || arg > ctx->ivSz) { - XMEMCPY(ptr, ctx->iv, ctx->ivSz); + XMEMCPY(ptr, ctx->iv, (size_t)ctx->ivSz); } else { /* * Copy the last "arg" bytes of ctx->iv into the buffer at * "ptr." Not sure why OpenSSL does this, but it does. */ - XMEMCPY(ptr, ctx->iv + ctx->ivSz - arg, arg); + XMEMCPY(ptr, ctx->iv + ctx->ivSz - arg, (size_t)arg); } /* @@ -5950,7 +5963,7 @@ void wolfSSL_EVP_init(void) ctx->authTagSz = arg; ret = WOLFSSL_SUCCESS; if (ptr != NULL) { - XMEMCPY(ctx->authTag, ptr, arg); + XMEMCPY(ctx->authTag, ptr, (size_t)arg); } break; } @@ -5962,7 +5975,7 @@ void wolfSSL_EVP_init(void) break; } - XMEMCPY(ctx->authTag, ptr, arg); + XMEMCPY(ctx->authTag, ptr, (size_t)arg); ctx->authTagSz = arg; ret = WOLFSSL_SUCCESS; break; @@ -5975,7 +5988,7 @@ void wolfSSL_EVP_init(void) break; } - XMEMCPY(ctx->authTag, ptr, arg); + XMEMCPY(ctx->authTag, ptr, (size_t)arg); ctx->authTagSz = arg; ret = WOLFSSL_SUCCESS; break; @@ -5986,7 +5999,7 @@ void wolfSSL_EVP_init(void) if(arg <= 0 || arg > 16 || (ptr == NULL)) break; - XMEMCPY(ctx->authTag, ptr, arg); + XMEMCPY(ctx->authTag, ptr, (size_t)arg); ctx->authTagSz = arg; ret = WOLFSSL_SUCCESS; break; @@ -6025,7 +6038,7 @@ void wolfSSL_EVP_init(void) } if (ptr != NULL) { - XMEMCPY(ptr, ctx->authTag, arg); + XMEMCPY(ptr, ctx->authTag, (size_t)arg); ret = WOLFSSL_SUCCESS; } break; @@ -6145,7 +6158,7 @@ void wolfSSL_EVP_init(void) ctx->cipherType = WOLFSSL_EVP_CIPH_TYPE_INIT; /* not yet initialized */ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) if (ctx->key) { - ForceZero(ctx->key, ctx->keyLen); + ForceZero(ctx->key, (word32)ctx->keyLen); XFREE(ctx->key, NULL, DYNAMIC_TYPE_OPENSSL); ctx->key = NULL; } @@ -6211,7 +6224,7 @@ void wolfSSL_EVP_init(void) goto end; if (data == NULL) { - ret = info->keySz; + ret = (int)info->keySz; goto end; } @@ -6219,10 +6232,10 @@ void wolfSSL_EVP_init(void) if (ret == WOLFSSL_FAILURE) goto end; - ret = wc_PBKDF1_ex(key, info->keySz, iv, info->ivSz, data, sz, salt, - EVP_SALT_SIZE, count, hashType, NULL); + ret = wc_PBKDF1_ex(key, (int)info->keySz, iv, (int)info->ivSz, data, sz, + salt, EVP_SALT_SIZE, count, hashType, NULL); if (ret == 0) - ret = info->keySz; + ret = (int)info->keySz; end: #ifdef WOLFSSL_SMALL_STACK @@ -6294,7 +6307,7 @@ void wolfSSL_EVP_init(void) if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_GCM_MODE | WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; if (enc == 0 || enc == 1) { @@ -6334,7 +6347,7 @@ void wolfSSL_EVP_init(void) } #endif /* !WOLFSSL_AESGCM_STREAM */ if (ret == WOLFSSL_SUCCESS && iv && - wc_AesGcmSetExtIV(&ctx->cipher.aes, iv, ctx->ivSz)) { + wc_AesGcmSetExtIV(&ctx->cipher.aes, iv, (word32)ctx->ivSz)) { WOLFSSL_MSG("wc_AesGcmSetExtIV() failed"); ret = WOLFSSL_FAILURE; } @@ -6346,8 +6359,8 @@ void wolfSSL_EVP_init(void) if (ret == WOLFSSL_SUCCESS && (key || (iv && ctx->cipher.aes.gcmKeySet)) && wc_AesGcmInit(&ctx->cipher.aes, key, - (key == NULL) ? 0 : ctx->keyLen, iv, - (iv == NULL) ? 0 : ctx->ivSz) != 0) { + (key == NULL) ? 0 : (word32)ctx->keyLen, iv, + (iv == NULL) ? 0 : (word32)ctx->ivSz) != 0) { WOLFSSL_MSG("wc_AesGcmInit() failed"); ret = WOLFSSL_FAILURE; } @@ -6430,7 +6443,7 @@ void wolfSSL_EVP_init(void) if (ctx->enc) { /* Calculate authentication tag. */ ret = wc_AesGcmEncryptFinal(&ctx->cipher.aes, - ctx->authTag, ctx->authTagSz); + ctx->authTag, (word32)ctx->authTagSz); /* * wc_AesGcmEncryptFinal increments the IV in * ctx->cipher.aes.reg, so we don't call IncCtr here. @@ -6439,7 +6452,7 @@ void wolfSSL_EVP_init(void) else { /* Calculate authentication tag and compare. */ ret = wc_AesGcmDecryptFinal(&ctx->cipher.aes, - ctx->authTag, ctx->authTagSz); + ctx->authTag, (word32)ctx->authTagSz); if (ctx->authIncIv) { IncCtr((byte*)ctx->cipher.aes.reg, ctx->cipher.aes.nonceSz); @@ -6448,7 +6461,7 @@ void wolfSSL_EVP_init(void) /* Reinitialize for subsequent wolfSSL_EVP_Cipher calls. */ if (wc_AesGcmInit(&ctx->cipher.aes, NULL, 0, (byte*)ctx->cipher.aes.reg, - ctx->ivSz) != 0) { + (word32)ctx->ivSz) != 0) { WOLFSSL_MSG("wc_AesGcmInit failed"); return WOLFSSL_FATAL_ERROR; } @@ -6461,12 +6474,12 @@ void wolfSSL_EVP_init(void) * NULL). */ if (ctx->authIn != NULL) { - XMEMSET(ctx->authIn, 0, ctx->authInSz); + XMEMSET(ctx->authIn, 0, (size_t)ctx->authInSz); } ctx->authInSz = 0; } if (ret == 0) { - ret = len; + ret = (int)len; } return ret; @@ -6494,7 +6507,7 @@ void wolfSSL_EVP_init(void) if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CCM_MODE | WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; if (enc == 0 || enc == 1) { @@ -6527,12 +6540,12 @@ void wolfSSL_EVP_init(void) #endif if (ret == WOLFSSL_SUCCESS && key && - wc_AesCcmSetKey(&ctx->cipher.aes, key, ctx->keyLen)) { + wc_AesCcmSetKey(&ctx->cipher.aes, key, (word32)ctx->keyLen)) { WOLFSSL_MSG("wc_AesCcmSetKey() failed"); ret = WOLFSSL_FAILURE; } if (ret == WOLFSSL_SUCCESS && iv && - wc_AesCcmSetNonce(&ctx->cipher.aes, iv, ctx->ivSz)) { + wc_AesCcmSetNonce(&ctx->cipher.aes, iv, (word32)ctx->ivSz)) { WOLFSSL_MSG("wc_AesCcmSetNonce() failed"); ret = WOLFSSL_FAILURE; } @@ -6556,20 +6569,20 @@ void wolfSSL_EVP_init(void) /* No destination means only AAD. */ if (src != NULL && dst == NULL) { - ret = wolfSSL_EVP_CipherUpdate_CCM_AAD(ctx, src, len); + ret = wolfSSL_EVP_CipherUpdate_CCM_AAD(ctx, src, (int)len); } else if (src != NULL && dst != NULL) { if (ctx->enc) { ret = wc_AesCcmEncrypt(&ctx->cipher.aes, dst, src, - len, ctx->iv, ctx->ivSz, ctx->authTag, - ctx->authTagSz, ctx->authIn, - ctx->authInSz); + len, ctx->iv, (word32)ctx->ivSz, ctx->authTag, + (word32)ctx->authTagSz, ctx->authIn, + (word32)ctx->authInSz); } else { ret = wc_AesCcmDecrypt(&ctx->cipher.aes, dst, src, - len, ctx->iv, ctx->ivSz, ctx->authTag, - ctx->authTagSz, ctx->authIn, - ctx->authInSz); + len, ctx->iv, (word32)ctx->ivSz, ctx->authTag, + (word32)ctx->authTagSz, ctx->authIn, + (word32)ctx->authInSz); } if (ctx->authIncIv) { IncCtr((byte*)ctx->cipher.aes.reg, @@ -6583,12 +6596,12 @@ void wolfSSL_EVP_init(void) * NULL). */ if (ctx->authIn != NULL) { - XMEMSET(ctx->authIn, 0, ctx->authInSz); + XMEMSET(ctx->authIn, 0, (size_t)ctx->authInSz); } ctx->authInSz = 0; } if (ret == 0) { - ret = len; + ret = (int)len; } return ret; @@ -6635,7 +6648,7 @@ void wolfSSL_EVP_init(void) if (ctx->ivSz == 0) { ctx->ivSz = GCM_NONCE_MID_SZ; } - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_GCM_MODE | WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; if (enc == 0 || enc == 1) { @@ -6718,7 +6731,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_CBC))) { WOLFSSL_MSG("EVP_AES_128_CBC"); ctx->cipherType = AES_128_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 16; ctx->block_size = AES_BLOCK_SIZE; @@ -6726,8 +6739,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -6743,7 +6756,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_CBC))) { WOLFSSL_MSG("EVP_AES_192_CBC"); ctx->cipherType = AES_192_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 24; ctx->block_size = AES_BLOCK_SIZE; @@ -6751,8 +6764,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -6768,7 +6781,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CBC))) { WOLFSSL_MSG("EVP_AES_256_CBC"); ctx->cipherType = AES_256_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 32; ctx->block_size = AES_BLOCK_SIZE; @@ -6776,8 +6789,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0); if (ret != 0){ WOLFSSL_MSG("AesSetKey() failed"); return WOLFSSL_FAILURE; @@ -6845,7 +6858,7 @@ void wolfSSL_EVP_init(void) if (ctx->cipherType == AES_128_CTR_TYPE || (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_CTR))) { WOLFSSL_MSG("EVP_AES_128_CTR"); - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->cipherType = AES_128_CTR_TYPE; ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 16; @@ -6857,8 +6870,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 1); if (ret != 0) return WOLFSSL_FAILURE; } @@ -6874,7 +6887,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_CTR))) { WOLFSSL_MSG("EVP_AES_192_CTR"); ctx->cipherType = AES_192_CTR_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 24; ctx->block_size = NO_PADDING_BLOCK_SIZE; @@ -6885,8 +6898,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 1); if (ret != 0) return WOLFSSL_FAILURE; } @@ -6902,7 +6915,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CTR))) { WOLFSSL_MSG("EVP_AES_256_CTR"); ctx->cipherType = AES_256_CTR_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = 32; ctx->block_size = NO_PADDING_BLOCK_SIZE; @@ -6913,8 +6926,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 1); if (ret != 0) return WOLFSSL_FAILURE; } @@ -6932,15 +6945,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_ECB))) { WOLFSSL_MSG("EVP_AES_128_ECB"); ctx->cipherType = AES_128_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 16; ctx->block_size = AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, NULL, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); } if (ret != 0) return WOLFSSL_FAILURE; @@ -6951,15 +6964,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_ECB))) { WOLFSSL_MSG("EVP_AES_192_ECB"); ctx->cipherType = AES_192_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 24; ctx->block_size = AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, NULL, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); } if (ret != 0) return WOLFSSL_FAILURE; @@ -6970,15 +6983,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_ECB))) { WOLFSSL_MSG("EVP_AES_256_ECB"); ctx->cipherType = AES_256_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 32; ctx->block_size = AES_BLOCK_SIZE; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, NULL, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1); } if (ret != 0) return WOLFSSL_FAILURE; @@ -6991,15 +7004,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_CFB1))) { WOLFSSL_MSG("EVP_AES_128_CFB1"); ctx->cipherType = AES_128_CFB1_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 16; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7015,15 +7028,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_CFB1))) { WOLFSSL_MSG("EVP_AES_192_CFB1"); ctx->cipherType = AES_192_CFB1_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 24; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7039,15 +7052,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CFB1))) { WOLFSSL_MSG("EVP_AES_256_CFB1"); ctx->cipherType = AES_256_CFB1_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 32; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0){ WOLFSSL_MSG("AesSetKey() failed"); return WOLFSSL_FAILURE; @@ -7067,15 +7080,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_CFB8))) { WOLFSSL_MSG("EVP_AES_128_CFB8"); ctx->cipherType = AES_128_CFB8_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 16; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7091,15 +7104,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_CFB8))) { WOLFSSL_MSG("EVP_AES_192_CFB8"); ctx->cipherType = AES_192_CFB8_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 24; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7115,15 +7128,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CFB8))) { WOLFSSL_MSG("EVP_AES_256_CFB8"); ctx->cipherType = AES_256_CFB8_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 32; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0){ WOLFSSL_MSG("AesSetKey() failed"); return WOLFSSL_FAILURE; @@ -7143,15 +7156,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_CFB128))) { WOLFSSL_MSG("EVP_AES_128_CFB128"); ctx->cipherType = AES_128_CFB128_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 16; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7167,15 +7180,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_CFB128))) { WOLFSSL_MSG("EVP_AES_192_CFB128"); ctx->cipherType = AES_192_CFB128_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 24; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7191,15 +7204,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CFB128))) { WOLFSSL_MSG("EVP_AES_256_CFB128"); ctx->cipherType = AES_256_CFB128_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CFB_MODE; ctx->keyLen = 32; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0){ WOLFSSL_MSG("AesSetKey() failed"); return WOLFSSL_FAILURE; @@ -7221,15 +7234,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_OFB))) { WOLFSSL_MSG("EVP_AES_128_OFB"); ctx->cipherType = AES_128_OFB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_OFB_MODE; ctx->keyLen = 16; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7245,15 +7258,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_192_OFB))) { WOLFSSL_MSG("EVP_AES_192_OFB"); ctx->cipherType = AES_192_OFB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_OFB_MODE; ctx->keyLen = 24; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0) return WOLFSSL_FAILURE; } @@ -7269,15 +7282,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_OFB))) { WOLFSSL_MSG("EVP_AES_256_OFB"); ctx->cipherType = AES_256_OFB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_OFB_MODE; ctx->keyLen = 32; ctx->block_size = 1; if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = AesSetKey_ex(&ctx->cipher.aes, key, ctx->keyLen, iv, - AES_ENCRYPTION, 0); + ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen, + iv, AES_ENCRYPTION, 0); if (ret != 0){ WOLFSSL_MSG("AesSetKey() failed"); return WOLFSSL_FAILURE; @@ -7299,7 +7312,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_128_XTS))) { WOLFSSL_MSG("EVP_AES_128_XTS"); ctx->cipherType = AES_128_XTS_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->keyLen = 32; ctx->block_size = 1; @@ -7307,7 +7320,7 @@ void wolfSSL_EVP_init(void) if (iv != NULL) { if (iv != ctx->iv) /* Valgrind error when src == dst */ - XMEMCPY(ctx->iv, iv, ctx->ivSz); + XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } else XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); @@ -7315,7 +7328,8 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen, + ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, + (word32)ctx->keyLen, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, NULL, 0); if (ret != 0) { WOLFSSL_MSG("wc_AesXtsSetKey() failed"); @@ -7329,7 +7343,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_XTS))) { WOLFSSL_MSG("EVP_AES_256_XTS"); ctx->cipherType = AES_256_XTS_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_XTS_MODE; ctx->keyLen = 64; ctx->block_size = 1; @@ -7337,7 +7351,7 @@ void wolfSSL_EVP_init(void) if (iv != NULL) { if (iv != ctx->iv) /* Valgrind error when src == dst */ - XMEMCPY(ctx->iv, iv, ctx->ivSz); + XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } else XMEMSET(ctx->iv, 0, AES_BLOCK_SIZE); @@ -7345,8 +7359,9 @@ void wolfSSL_EVP_init(void) if (enc == 0 || enc == 1) ctx->enc = enc ? 1 : 0; if (key) { - ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, ctx->keyLen, - ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, NULL, 0); + ret = wc_AesXtsSetKey(&ctx->cipher.xts, key, + (word32)ctx->keyLen, + ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, NULL, 0); if (ret != 0) { WOLFSSL_MSG("wc_AesXtsSetKey() failed"); return WOLFSSL_FAILURE; @@ -7378,7 +7393,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_CHACHA20_POLY1305))) { WOLFSSL_MSG("EVP_CHACHA20_POLY1305"); ctx->cipherType = CHACHA20_POLY1305_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; ctx->keyLen = CHACHA20_POLY1305_AEAD_KEYSIZE; ctx->block_size = CHACHA_CHUNK_BYTES; @@ -7395,13 +7410,13 @@ void wolfSSL_EVP_init(void) * since wc_ChaCha20Poly1305_Init() does not. */ if (key != NULL) { if (!ctx->key) { - ctx->key = (byte*)XMALLOC(ctx->keyLen, NULL, + ctx->key = (byte*)XMALLOC((size_t)ctx->keyLen, NULL, DYNAMIC_TYPE_OPENSSL); if (!ctx->key) { return MEMORY_E; } } - XMEMCPY(ctx->key, key, ctx->keyLen); + XMEMCPY(ctx->key, key, (size_t)ctx->keyLen); } if ((ctx->key != NULL && iv != NULL) && wc_ChaCha20Poly1305_Init( &ctx->cipher.chachaPoly, ctx->key, iv, ctx->enc) != 0) { @@ -7415,15 +7430,15 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_CHACHA20))) { WOLFSSL_MSG("EVP_CHACHA20"); ctx->cipherType = CHACHA20_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->keyLen = CHACHA_MAX_KEY_SZ; ctx->block_size = 1; ctx->ivSz = WOLFSSL_EVP_CHACHA_IV_BYTES; if (enc == 0 || enc == 1) { ctx->enc = (byte) enc; } - if (key != NULL && wc_Chacha_SetKey(&ctx->cipher.chacha, - key, ctx->keyLen) != 0) { + if (key != NULL && wc_Chacha_SetKey(&ctx->cipher.chacha, key, + (word32)ctx->keyLen) != 0) { WOLFSSL_MSG("wc_Chacha_SetKey() failed"); return WOLFSSL_FAILURE; } @@ -7448,7 +7463,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_SM4_ECB))) { WOLFSSL_MSG("EVP_SM4_ECB"); ctx->cipherType = SM4_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = SM4_KEY_SIZE; ctx->block_size = SM4_BLOCK_SIZE; @@ -7467,7 +7482,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_SM4_CBC))) { WOLFSSL_MSG("EVP_SM4_CBC"); ctx->cipherType = SM4_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = SM4_KEY_SIZE; ctx->block_size = SM4_BLOCK_SIZE; @@ -7493,7 +7508,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_SM4_CTR))) { WOLFSSL_MSG("EVP_SM4_CTR"); ctx->cipherType = SM4_CTR_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CTR_MODE; ctx->keyLen = SM4_KEY_SIZE; ctx->block_size = NO_PADDING_BLOCK_SIZE; @@ -7519,7 +7534,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_SM4_GCM))) { WOLFSSL_MSG("EVP_SM4_GCM"); ctx->cipherType = SM4_GCM_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_GCM_MODE | WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; ctx->block_size = NO_PADDING_BLOCK_SIZE; @@ -7542,7 +7557,7 @@ void wolfSSL_EVP_init(void) } } if (iv != NULL) { - XMEMCPY(ctx->iv, iv, ctx->ivSz); + XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } } #endif @@ -7551,7 +7566,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_SM4_CCM))) { WOLFSSL_MSG("EVP_SM4_CCM"); ctx->cipherType = SM4_CCM_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CCM_MODE | WOLFSSL_EVP_CIPH_FLAG_AEAD_CIPHER; ctx->block_size = NO_PADDING_BLOCK_SIZE; @@ -7574,7 +7589,7 @@ void wolfSSL_EVP_init(void) } } if (iv != NULL) { - XMEMCPY(ctx->iv, iv, ctx->ivSz); + XMEMCPY(ctx->iv, iv, (size_t)ctx->ivSz); } } #endif @@ -7583,7 +7598,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_DES_CBC))) { WOLFSSL_MSG("EVP_DES_CBC"); ctx->cipherType = DES_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 8; ctx->block_size = DES_BLOCK_SIZE; @@ -7605,7 +7620,7 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_DES_ECB))) { WOLFSSL_MSG("EVP_DES_ECB"); ctx->cipherType = DES_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 8; ctx->block_size = DES_BLOCK_SIZE; @@ -7625,7 +7640,7 @@ void wolfSSL_EVP_init(void) EVP_CIPHER_TYPE_MATCHES(type, EVP_DES_EDE3_CBC))) { WOLFSSL_MSG("EVP_DES_EDE3_CBC"); ctx->cipherType = DES_EDE3_CBC_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_CBC_MODE; ctx->keyLen = 24; ctx->block_size = DES_BLOCK_SIZE; @@ -7650,7 +7665,7 @@ void wolfSSL_EVP_init(void) EVP_CIPHER_TYPE_MATCHES(type, EVP_DES_EDE3_ECB))) { WOLFSSL_MSG("EVP_DES_EDE3_ECB"); ctx->cipherType = DES_EDE3_ECB_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_ECB_MODE; ctx->keyLen = 24; ctx->block_size = DES_BLOCK_SIZE; @@ -7669,13 +7684,13 @@ void wolfSSL_EVP_init(void) (type && EVP_CIPHER_TYPE_MATCHES(type, EVP_ARC4))) { WOLFSSL_MSG("ARC4"); ctx->cipherType = ARC4_TYPE; - ctx->flags &= ~WOLFSSL_EVP_CIPH_MODE; + ctx->flags &= (unsigned long)~WOLFSSL_EVP_CIPH_MODE; ctx->flags |= WOLFSSL_EVP_CIPH_STREAM_CIPHER; ctx->block_size = 1; if (ctx->keyLen == 0) /* user may have already set */ ctx->keyLen = 16; /* default to 128 */ if (key) - wc_Arc4SetKey(&ctx->cipher.arc4, key, ctx->keyLen); + wc_Arc4SetKey(&ctx->cipher.arc4, key, (word32)ctx->keyLen); } #endif /* NO_RC4 */ if (ctx->cipherType == NULL_CIPHER_TYPE || @@ -7901,7 +7916,7 @@ void wolfSSL_EVP_init(void) return WOLFSSL_FAILURE; } - XMEMCPY(iv, ctx->iv, ivLen); + XMEMCPY(iv, ctx->iv, (size_t)ivLen); return WOLFSSL_SUCCESS; } @@ -7962,7 +7977,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesCbcDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = (len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE; + ret = (int)((len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE); break; #endif /* HAVE_AES_CBC */ @@ -7977,7 +7992,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesCfb1Decrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; case AES_128_CFB8_TYPE: case AES_192_CFB8_TYPE: @@ -7988,7 +8003,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesCfb8Decrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif /* !HAVE_SELFTEST && !HAVE_FIPS */ case AES_128_CFB128_TYPE: @@ -8000,7 +8015,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesCfbDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif /* WOLFSSL_AES_CFB */ #if defined(WOLFSSL_AES_OFB) @@ -8013,7 +8028,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesOfbDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif /* WOLFSSL_AES_OFB */ #if defined(WOLFSSL_AES_XTS) @@ -8022,12 +8037,12 @@ void wolfSSL_EVP_init(void) WOLFSSL_MSG("AES XTS"); if (ctx->enc) ret = wc_AesXtsEncrypt(&ctx->cipher.xts, dst, src, len, - ctx->iv, ctx->ivSz); + ctx->iv, (word32)ctx->ivSz); else ret = wc_AesXtsDecrypt(&ctx->cipher.xts, dst, src, len, - ctx->iv, ctx->ivSz); + ctx->iv, (word32)ctx->ivSz); if (ret == 0) - ret = len; + ret = (int)len; break; #endif /* WOLFSSL_AES_XTS */ @@ -8061,7 +8076,7 @@ void wolfSSL_EVP_init(void) else ret = wc_AesEcbDecrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = (len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE; + ret = (int)((len / AES_BLOCK_SIZE) * AES_BLOCK_SIZE); break; #endif #ifdef WOLFSSL_AES_COUNTER @@ -8071,7 +8086,7 @@ void wolfSSL_EVP_init(void) WOLFSSL_MSG("AES CTR"); ret = wc_AesCtrEncrypt(&ctx->cipher.aes, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif /* WOLFSSL_AES_COUNTER */ #endif /* NO_AES */ @@ -8104,7 +8119,7 @@ void wolfSSL_EVP_init(void) else wc_Des_CbcDecrypt(&ctx->cipher.des, dst, src, len); if (ret == 0) - ret = (len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE; + ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; case DES_EDE3_CBC_TYPE : WOLFSSL_MSG("DES3 CBC"); @@ -8113,20 +8128,20 @@ void wolfSSL_EVP_init(void) else ret = wc_Des3_CbcDecrypt(&ctx->cipher.des3, dst, src, len); if (ret == 0) - ret = (len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE; + ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; #ifdef WOLFSSL_DES_ECB case DES_ECB_TYPE : WOLFSSL_MSG("DES ECB"); ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len); if (ret == 0) - ret = (len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE; + ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; case DES_EDE3_ECB_TYPE : WOLFSSL_MSG("DES3 ECB"); ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len); if (ret == 0) - ret = (len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE; + ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; #endif #endif /* !NO_DES3 */ @@ -8136,7 +8151,7 @@ void wolfSSL_EVP_init(void) WOLFSSL_MSG("ARC4"); wc_Arc4Process(&ctx->cipher.arc4, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif @@ -8150,7 +8165,7 @@ void wolfSSL_EVP_init(void) else ret = wc_Sm4EcbDecrypt(&ctx->cipher.sm4, dst, src, len); if (ret == 0) - ret = (len / SM4_BLOCK_SIZE) * SM4_BLOCK_SIZE; + ret = (int)((len / SM4_BLOCK_SIZE) * SM4_BLOCK_SIZE); break; #endif #ifdef WOLFSSL_SM4_CBC @@ -8161,7 +8176,7 @@ void wolfSSL_EVP_init(void) else ret = wc_Sm4CbcDecrypt(&ctx->cipher.sm4, dst, src, len); if (ret == 0) - ret = (len / SM4_BLOCK_SIZE) * SM4_BLOCK_SIZE; + ret = (int)((len / SM4_BLOCK_SIZE) * SM4_BLOCK_SIZE); break; #endif #ifdef WOLFSSL_SM4_CTR @@ -8169,7 +8184,7 @@ void wolfSSL_EVP_init(void) WOLFSSL_MSG("AES CTR"); ret = wc_Sm4CtrEncrypt(&ctx->cipher.sm4, dst, src, len); if (ret == 0) - ret = len; + ret = (int)len; break; #endif #ifdef WOLFSSL_SM4_GCM @@ -8232,20 +8247,20 @@ void wolfSSL_EVP_init(void) * NULL). */ if (ctx->authIn != NULL) { - XMEMSET(ctx->authIn, 0, ctx->authInSz); + XMEMSET(ctx->authIn, 0, (size_t)ctx->authInSz); } ctx->authInSz = 0; } if (ret == 0) { - ret = len; + ret = (int)len; } break; #endif case NULL_CIPHER_TYPE : WOLFSSL_MSG("NULL CIPHER"); - XMEMCPY(dst, src, len); - ret = len; + XMEMCPY(dst, src, (size_t)len); + ret = (int)len; break; default: { @@ -8331,7 +8346,7 @@ static int PopulateRSAEvpPkeyDer(WOLFSSL_EVP_PKEY *pkey) derSz = ret; #ifdef HAVE_PKCS8 if (key->pkcs8HeaderSz) { - ret = wc_CreatePKCS8Key(NULL, &pkcs8Sz, NULL, derSz, + ret = wc_CreatePKCS8Key(NULL, &pkcs8Sz, NULL, (word32)derSz, RSAk, NULL, 0); if (ret == LENGTH_ONLY_E) ret = 0; @@ -8351,14 +8366,14 @@ static int PopulateRSAEvpPkeyDer(WOLFSSL_EVP_PKEY *pkey) } #ifdef WOLFSSL_NO_REALLOC - derBuf = (byte*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_DER); + derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, DYNAMIC_TYPE_DER); if (derBuf != NULL) { - XMEMCPY(derBuf, pkey->pkey.ptr, pkey->pkey_sz); + XMEMCPY(derBuf, pkey->pkey.ptr, (size_t)pkey->pkey_sz); XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_DER); pkey->pkey.ptr = NULL; } #else - derBuf = (byte*)XREALLOC(pkey->pkey.ptr, derSz, + derBuf = (byte*)XREALLOC(pkey->pkey.ptr, (size_t)derSz, pkey->heap, DYNAMIC_TYPE_DER); #endif if (derBuf == NULL) { @@ -8370,33 +8385,35 @@ static int PopulateRSAEvpPkeyDer(WOLFSSL_EVP_PKEY *pkey) pkey->pkey.ptr = (char*)derBuf; if (rsa->type == RSA_PRIVATE) { - ret = wc_RsaKeyToDer(rsa, derBuf, derSz); + ret = wc_RsaKeyToDer(rsa, derBuf, (word32)derSz); if (ret > 0) { derSz = ret; #ifdef HAVE_PKCS8 if (key->pkcs8HeaderSz) { byte* keyBuf = derBuf; int keySz = derSz; - derSz = pkcs8Sz; + word32 sz = pkcs8Sz; /* Need new buffer for PKCS8 since we can't * do this in-place */ - derBuf = (byte*)XMALLOC(pkcs8Sz, pkey->heap, + derBuf = (byte*)XMALLOC((size_t)pkcs8Sz, pkey->heap, DYNAMIC_TYPE_DER); if (derBuf != NULL) { - ret = wc_CreatePKCS8Key(derBuf, (word32*)&derSz, keyBuf, - keySz, RSAk, NULL, 0); + ret = wc_CreatePKCS8Key(derBuf, &sz, keyBuf, (word32)keySz, + RSAk, NULL, 0); XFREE(keyBuf, pkey->heap, DYNAMIC_TYPE_DER); pkey->pkey.ptr = (char*)derBuf; } - else + else { ret = MEMORY_E; + } + derSz = (int)sz; } #endif } } else { /* Public key to DER */ - ret = wc_RsaKeyToPublicDer(rsa, derBuf, derSz); + ret = wc_RsaKeyToPublicDer(rsa, derBuf, (word32)derSz); if (ret > 0) derSz = ret; } @@ -8511,7 +8528,8 @@ int wolfSSL_EVP_PKEY_set1_DSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DSA *key) /* 4 > size of pub, priv, p, q, g + ASN.1 additional information */ derMax = 4 * wolfSSL_BN_num_bytes(key->g) + AES_BLOCK_SIZE; - derBuf = (byte*)XMALLOC(derMax, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = (byte*)XMALLOC((size_t)derMax, pkey->heap, + DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { WOLFSSL_MSG("malloc failed"); return WOLFSSL_FAILURE; @@ -8519,11 +8537,11 @@ int wolfSSL_EVP_PKEY_set1_DSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DSA *key) if (dsa->type == DSA_PRIVATE) { /* Private key to DER */ - derSz = wc_DsaKeyToDer(dsa, derBuf, derMax); + derSz = wc_DsaKeyToDer(dsa, derBuf, (word32)derMax); } else { /* Public key to DER */ - derSz = wc_DsaKeyToPublicDer(dsa, derBuf, derMax); + derSz = wc_DsaKeyToPublicDer(dsa, derBuf, (word32)derMax); } if (derSz < 0) { @@ -8537,14 +8555,15 @@ int wolfSSL_EVP_PKEY_set1_DSA(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DSA *key) return WOLFSSL_FAILURE; } - pkey->pkey.ptr = (char*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_DER); + pkey->pkey.ptr = (char*)XMALLOC((size_t)derSz, pkey->heap, + DYNAMIC_TYPE_DER); if (pkey->pkey.ptr == NULL) { WOLFSSL_MSG("key malloc failed"); XFREE(derBuf, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); return WOLFSSL_FAILURE; } pkey->pkey_sz = derSz; - XMEMCPY(pkey->pkey.ptr, derBuf, derSz); + XMEMCPY(pkey->pkey.ptr, derBuf, (size_t)derSz); XFREE(derBuf, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); return WOLFSSL_SUCCESS; @@ -8708,7 +8727,7 @@ int wolfSSL_EVP_PKEY_set1_DH(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DH *key) return WOLFSSL_FAILURE; } - derBuf = (byte*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { WOLFSSL_MSG("malloc failed"); return WOLFSSL_FAILURE; @@ -8731,7 +8750,7 @@ int wolfSSL_EVP_PKEY_set1_DH(WOLFSSL_EVP_PKEY *pkey, WOLFSSL_DH *key) /* Store DH key into pkey (DER format) */ pkey->pkey.ptr = (char*)derBuf; - pkey->pkey_sz = derSz; + pkey->pkey_sz = (int)derSz; return WOLFSSL_SUCCESS; } @@ -8847,7 +8866,8 @@ static int ECC_populate_EVP_PKEY(EVP_PKEY* pkey, WOLFSSL_EC_KEY *key) if (key->pkcs8HeaderSz) { /* when key has pkcs8 header the pkey should too */ if (wc_EccKeyToPKCS8(ecc, NULL, (word32*)&derSz) == LENGTH_ONLY_E) { - derBuf = (byte*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_OPENSSL); + derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, + DYNAMIC_TYPE_OPENSSL); if (derBuf) { if (wc_EccKeyToPKCS8(ecc, derBuf, (word32*)&derSz) >= 0) { if (pkey->pkey.ptr) { @@ -8876,9 +8896,10 @@ static int ECC_populate_EVP_PKEY(EVP_PKEY* pkey, WOLFSSL_EC_KEY *key) /* if not, the pkey will be traditional ecc key */ if ((derSz = wc_EccKeyDerSize(ecc, 1)) > 0) { - derBuf = (byte*)XMALLOC(derSz, pkey->heap, DYNAMIC_TYPE_OPENSSL); + derBuf = (byte*)XMALLOC((size_t)derSz, pkey->heap, + DYNAMIC_TYPE_OPENSSL); if (derBuf) { - if (wc_EccKeyToDer(ecc, derBuf, derSz) >= 0) { + if (wc_EccKeyToDer(ecc, derBuf, (word32)derSz) >= 0) { if (pkey->pkey.ptr) { XFREE(pkey->pkey.ptr, pkey->heap, DYNAMIC_TYPE_OPENSSL); } @@ -8895,12 +8916,13 @@ static int ECC_populate_EVP_PKEY(EVP_PKEY* pkey, WOLFSSL_EC_KEY *key) } } else if (ecc->type == ECC_PUBLICKEY) { - if ((derSz = (word32)wc_EccPublicKeyDerSize(ecc, 1)) > 0) { - derBuf = (byte*)XREALLOC(pkey->pkey.ptr, derSz, NULL, + if ((derSz = wc_EccPublicKeyDerSize(ecc, 1)) > 0) { + derBuf = (byte*)XREALLOC(pkey->pkey.ptr, (size_t)derSz, NULL, DYNAMIC_TYPE_OPENSSL); if (derBuf != NULL) { pkey->pkey.ptr = (char*)derBuf; - if ((derSz = wc_EccPublicKeyToDer(ecc, derBuf, derSz, 1)) < 0) { + if ((derSz = wc_EccPublicKeyToDer(ecc, derBuf, (word32)derSz, + 1)) < 0) { XFREE(derBuf, NULL, DYNAMIC_TYPE_OPENSSL); derBuf = NULL; } @@ -9441,9 +9463,10 @@ int wolfSSL_EVP_PKEY_assign_RSA(EVP_PKEY* pkey, WOLFSSL_RSA* key) RsaKey* rsa = (RsaKey*)key->internal; int ret = wc_RsaKeyToDer(rsa, NULL, 0); if (ret > 0) { - int derSz = ret; - byte* derBuf = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); - if (derBuf) { + word32 derSz = (word32)ret; + byte* derBuf = (byte*)XMALLOC((size_t)derSz, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (derBuf != NULL) { ret = wc_RsaKeyToDer(rsa, derBuf, derSz); if (ret >= 0) { pkey->pkey_sz = ret; @@ -9536,12 +9559,13 @@ int wolfSSL_EVP_Digest(const unsigned char* in, int inSz, unsigned char* out, if (err != WOLFSSL_SUCCESS) return err; - if (wc_Hash((enum wc_HashType)hashType, in, inSz, out, hashSz) != 0) { + if (wc_Hash((enum wc_HashType)hashType, in, (word32)inSz, out, + (word32)hashSz) != 0) { return WOLFSSL_FAILURE; } if (outSz != NULL) - *outSz = hashSz; + *outSz = (unsigned int)hashSz; (void)eng; return WOLFSSL_SUCCESS; @@ -9807,7 +9831,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type) { WOLFSSL_EVP_MD_CTX* ctx; WOLFSSL_ENTER("EVP_MD_CTX_new"); - ctx = (WOLFSSL_EVP_MD_CTX*)XMALLOC(sizeof *ctx, NULL, + ctx = (WOLFSSL_EVP_MD_CTX*)XMALLOC(sizeof(*ctx), NULL, DYNAMIC_TYPE_OPENSSL); if (ctx){ wolfSSL_EVP_MD_CTX_init(ctx); @@ -11001,7 +11025,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, int wsz; /* parse key to get modulus and exponent */ - if (wc_RsaPublicKeyDecode_ex(pkey, &inOutIdx, pkeySz, + if (wc_RsaPublicKeyDecode_ex(pkey, &inOutIdx, (word32)pkeySz, &n, &nSz, &e, &eSz) != 0) { break; } @@ -11014,7 +11038,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) { break; } - if (mp_set_int(a, bitlen) != 0) { + if (mp_set_int(a, (unsigned long)bitlen) != 0) { break; } if (mp_todecimal(a, (char*)buff) != 0) { @@ -11042,7 +11066,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, nSz++; } - if (PrintHexWithColon(out, n, nSz, + if (PrintHexWithColon(out, n, (int)nSz, indent + 4, 1/* lower case */) != WOLFSSL_SUCCESS) { break; } @@ -11177,7 +11201,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, } if (res == WOLFSSL_SUCCESS) { - res = wc_EccPublicKeyDecode(pkey, &inOutIdx, key, pkeySz) == 0; + res = wc_EccPublicKeyDecode(pkey, &inOutIdx, key, (word32)pkeySz) == 0; } if (res == WOLFSSL_SUCCESS) { @@ -11221,7 +11245,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, res = wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) > 0; } if (res == WOLFSSL_SUCCESS) { - res = mp_set_int(a, bitlen) == 0; + res = mp_set_int(a, (unsigned long)bitlen) == 0; } if (res == WOLFSSL_SUCCESS) { res = mp_todecimal(a, (char*)buff) == 0; @@ -11245,7 +11269,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, res = wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) > 0; } if (res == WOLFSSL_SUCCESS) { - res = PrintHexWithColon(out, pub, pubSz, indent + 4, 0/* upper case */); + /* upper case */ + res = PrintHexWithColon(out, pub, (int)pubSz, indent + 4, 0); } if (res == WOLFSSL_SUCCESS) { res = Indent(out, indent) >= 0; @@ -11353,26 +11378,27 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, int idx; int wsz; - if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, &length, (word32)pkeySz) < 0) { break; } - if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, &length, (word32)pkeySz) < 0) { break; } - if (GetObjectId(pkey, &inOutIdx, &oid, oidIgnoreType, pkeySz) != 0) { + if (GetObjectId(pkey, &inOutIdx, &oid, oidIgnoreType, (word32)pkeySz) != + 0) { break; } - if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, &length, (word32)pkeySz) < 0) { break; } /* find P */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, &length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, &length, (word32)pkeySz) <= 0) { break; } p = (byte*)(pkey + inOutIdx); @@ -11387,53 +11413,53 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, } } - inOutIdx += length; + inOutIdx += (word32)length; /* find Q */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, &length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, &length, (word32)pkeySz) <= 0) { break; } q = (byte*)(pkey + inOutIdx); qSz = length; - inOutIdx += length; + inOutIdx += (word32)length; /* find G */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, &length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, &length, (word32)pkeySz) <= 0) { break; } g = (byte*)(pkey + inOutIdx); gSz = length; - inOutIdx += length; + inOutIdx += (word32)length; /* find Y */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_BIT_STRING) { break; } - if (GetLength(pkey, &inOutIdx, &length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, &length, (word32)pkeySz) <= 0) { break; } inOutIdx++; /* skip the first byte( unused byte number)*/ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, &length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, &length, (word32)pkeySz) <= 0) { break; } y = (byte*)(pkey + inOutIdx); @@ -11446,7 +11472,7 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) { break; } - if (mp_set_int(a, bitlen) != 0) { + if (mp_set_int(a, (unsigned long)bitlen) != 0) { break; } if (mp_todecimal(a, (char*)buff) != 0) { @@ -11576,40 +11602,41 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, int idx; int wsz; - if (GetSequence(pkey, &inOutIdx, (int*)&length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) < 0) { break; } - if (GetSequence(pkey, &inOutIdx, (int*)&length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) < 0) { break; } - if (GetObjectId(pkey, &inOutIdx, &oid, oidIgnoreType, pkeySz) < 0) { + if (GetObjectId(pkey, &inOutIdx, &oid, oidIgnoreType, (word32)pkeySz) < + 0) { break; } - if (GetSequence(pkey, &inOutIdx, (int*)&length, pkeySz) < 0) { + if (GetSequence(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) < 0) { break; } /* get prime element */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, (int*)&length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) <= 0) { break; } prime = (byte*)(pkey + inOutIdx); - primeSz = length; + primeSz = (int)length; inOutIdx += length; /* get generator element */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, (int*)&length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) <= 0) { break; } if (length != 1) { @@ -11619,26 +11646,26 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, inOutIdx += length; /* get public-key element */ - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_BIT_STRING) { break; } - if (GetLength(pkey, &inOutIdx, (int*)&length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) <= 0) { break; } inOutIdx ++; - if (GetASNTag(pkey, &inOutIdx, &tagFound, pkeySz) != 0) { + if (GetASNTag(pkey, &inOutIdx, &tagFound, (word32)pkeySz) != 0) { break; } if (tagFound != ASN_INTEGER) { break; } - if (GetLength(pkey, &inOutIdx, (int*)&length, pkeySz) <= 0) { + if (GetLength(pkey, &inOutIdx, (int*)&length, (word32)pkeySz) <= 0) { break; } - publicKeySz = length; + publicKeySz = (int)length; publicKey = (byte*)(pkey + inOutIdx); if (bitlen == 0) { @@ -11657,7 +11684,7 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, if (wolfSSL_BIO_write(out, line, (int)XSTRLEN(line)) <= 0) { break; } - if (mp_set_int(a, bitlen) != 0) { + if (mp_set_int(a, (unsigned long)bitlen) != 0) { break; } if (mp_todecimal(a, (char*)buff) != 0) { @@ -11970,7 +11997,7 @@ struct WOLFSSL_EVP_ENCODE_CTX* wolfSSL_EVP_ENCODE_CTX_new(void) { WOLFSSL_EVP_ENCODE_CTX* ctx = NULL; WOLFSSL_ENTER("wolfSSL_EVP_ENCODE_CTX_new"); - ctx = (WOLFSSL_EVP_ENCODE_CTX*)XMALLOC( sizeof(WOLFSSL_EVP_ENCODE_CTX), + ctx = (WOLFSSL_EVP_ENCODE_CTX*)XMALLOC(sizeof(WOLFSSL_EVP_ENCODE_CTX), NULL, DYNAMIC_TYPE_OPENSSL ); if (ctx != NULL) { @@ -12002,7 +12029,7 @@ int wolfSSL_EVP_EncodeBlock(unsigned char *out, const unsigned char *in, if (out == NULL || in == NULL) return WOLFSSL_FATAL_ERROR; - if (Base64_Encode(in, inLen, out, &ret) == 0) + if (Base64_Encode(in, (word32)inLen, out, &ret) == 0) return (int)ret; else return WOLFSSL_FATAL_ERROR; @@ -12018,7 +12045,7 @@ int wolfSSL_EVP_DecodeBlock(unsigned char *out, const unsigned char *in, if (out == NULL || in == NULL) return WOLFSSL_FATAL_ERROR; - if (Base64_Decode(in, inLen, out, &ret) == 0) + if (Base64_Decode(in, (word32)inLen, out, &ret) == 0) return (int)ret; else return WOLFSSL_FATAL_ERROR; @@ -12061,8 +12088,9 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, * to create a block(48bytes) for encoding */ if (ctx->remaining > 0 && inl > 0) { - int cpysz = min((BASE64_ENCODE_BLOCK_SIZE - ctx->remaining), inl); - XMEMCPY(ctx->data + ctx->remaining, in, cpysz); + int cpysz = (int)min( + (word32)(BASE64_ENCODE_BLOCK_SIZE - ctx->remaining), (word32)inl); + XMEMCPY(ctx->data + ctx->remaining, in, (size_t)cpysz); ctx->remaining += cpysz; in += cpysz; inl -= cpysz; @@ -12072,10 +12100,10 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, /* Base64_Encode asks the out buff size via the 4th param*/ outsz = BASE64_ENCODE_RESULT_BLOCK_SIZE + 1; res = Base64_Encode(ctx->data, BASE64_ENCODE_BLOCK_SIZE, out, - &outsz); + &outsz); if (res == 0) { ctx->remaining = 0; - *outl = outsz; + *outl = (int)outsz; } else return 0; /* return with error */ @@ -12097,7 +12125,7 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, in += BASE64_ENCODE_BLOCK_SIZE; inl -= BASE64_ENCODE_BLOCK_SIZE; out += outsz; - *outl += outsz; + *outl += (int)outsz; } else { *outl = 0; @@ -12108,7 +12136,7 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, /* if remaining data exists, copy them into ctx for the next call*/ if (inl > 0) { XMEMSET(ctx->data, 0, sizeof(ctx->data)); - XMEMCPY(ctx->data, in, inl); + XMEMCPY(ctx->data, in, (size_t)inl); ctx->remaining = inl; } @@ -12137,9 +12165,9 @@ void wolfSSL_EVP_EncodeFinal(WOLFSSL_EVP_ENCODE_CTX* ctx, } /* process remaining data in ctx */ outsz = BASE64_ENCODE_RESULT_BLOCK_SIZE + 1; /* 64 byte and one for LF*/ - res = Base64_Encode(ctx->data, ctx->remaining ,out, &outsz); + res = Base64_Encode(ctx->data, (word32)ctx->remaining, out, &outsz); if (res == 0) - *outl = outsz; + *outl = (int)outsz; else *outl = 0; @@ -12199,14 +12227,15 @@ int wolfSSL_EVP_DecodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, return 1; } - inLen = inl; + inLen = (word32)inl; *outl = 0; /* if the remaining data exist in the ctx, add input data to them to create a block(4bytes) for decoding*/ - if ( ctx->remaining > 0 && inl > 0) { + if (ctx->remaining > 0 && inl > 0) { - int cpySz = min((BASE64_DECODE_BLOCK_SIZE - ctx->remaining), inl); + int cpySz = (int)min( + (word32)(BASE64_DECODE_BLOCK_SIZE - ctx->remaining), (word32)inl); for ( i = 0; cpySz > 0 && inLen > 0; i++) { if (Base64_SkipNewline(in, &inLen, &j) == ASN_INPUT_E) { @@ -12225,7 +12254,7 @@ int wolfSSL_EVP_DecodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, outsz = sizeof(ctx->data); res = Base64_Decode( ctx->data, BASE64_DECODE_BLOCK_SIZE, out, &outsz); if (res == 0) { - *outl += outsz; + *outl += (int)outsz; out += outsz; ctx->remaining = 0; @@ -12321,7 +12350,7 @@ int wolfSSL_EVP_DecodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, return -1; } - *outl += outsz; + *outl += (int)outsz; out += outsz; } /* copy left data to ctx */ @@ -12389,7 +12418,7 @@ int wolfSSL_EVP_DecodeFinal(WOLFSSL_EVP_ENCODE_CTX* ctx, if (ctx->remaining > 0) { int res; - inLen = ctx->remaining; + inLen = (word32)ctx->remaining; if ((res = Base64_SkipNewline(ctx->data, &inLen, &j)) != 0) { *outl = 0; if (res == BUFFER_E) /* means no valid data to decode in buffer */ @@ -12399,10 +12428,10 @@ int wolfSSL_EVP_DecodeFinal(WOLFSSL_EVP_ENCODE_CTX* ctx, } - outsz = ctx->remaining; - res = Base64_Decode(ctx->data, ctx->remaining, out, &outsz); + outsz = (word32)ctx->remaining; + res = Base64_Decode(ctx->data, (word32)ctx->remaining, out, &outsz); if (res == 0) { - *outl = outsz; + *outl = (int)outsz; return 1; } else { diff --git a/wolfcrypt/src/fe_448.c b/wolfcrypt/src/fe_448.c index 5f3fbc248b..73853b79e7 100644 --- a/wolfcrypt/src/fe_448.c +++ b/wolfcrypt/src/fe_448.c @@ -609,62 +609,62 @@ void fe448_to_bytes(unsigned char* b, const sword64* a) in4 += o; t = o << 56; in7 -= (sword64)t; /* Output as bytes */ - b[ 0] = (in0 >> 0); - b[ 1] = (in0 >> 8); - b[ 2] = (in0 >> 16); - b[ 3] = (in0 >> 24); - b[ 4] = (in0 >> 32); - b[ 5] = (in0 >> 40); - b[ 6] = (in0 >> 48); - b[ 7] = (in1 >> 0); - b[ 8] = (in1 >> 8); - b[ 9] = (in1 >> 16); - b[10] = (in1 >> 24); - b[11] = (in1 >> 32); - b[12] = (in1 >> 40); - b[13] = (in1 >> 48); - b[14] = (in2 >> 0); - b[15] = (in2 >> 8); - b[16] = (in2 >> 16); - b[17] = (in2 >> 24); - b[18] = (in2 >> 32); - b[19] = (in2 >> 40); - b[20] = (in2 >> 48); - b[21] = (in3 >> 0); - b[22] = (in3 >> 8); - b[23] = (in3 >> 16); - b[24] = (in3 >> 24); - b[25] = (in3 >> 32); - b[26] = (in3 >> 40); - b[27] = (in3 >> 48); - b[28] = (in4 >> 0); - b[29] = (in4 >> 8); - b[30] = (in4 >> 16); - b[31] = (in4 >> 24); - b[32] = (in4 >> 32); - b[33] = (in4 >> 40); - b[34] = (in4 >> 48); - b[35] = (in5 >> 0); - b[36] = (in5 >> 8); - b[37] = (in5 >> 16); - b[38] = (in5 >> 24); - b[39] = (in5 >> 32); - b[40] = (in5 >> 40); - b[41] = (in5 >> 48); - b[42] = (in6 >> 0); - b[43] = (in6 >> 8); - b[44] = (in6 >> 16); - b[45] = (in6 >> 24); - b[46] = (in6 >> 32); - b[47] = (in6 >> 40); - b[48] = (in6 >> 48); - b[49] = (in7 >> 0); - b[50] = (in7 >> 8); - b[51] = (in7 >> 16); - b[52] = (in7 >> 24); - b[53] = (in7 >> 32); - b[54] = (in7 >> 40); - b[55] = (in7 >> 48); + b[ 0] = (byte)(in0 >> 0); + b[ 1] = (byte)(in0 >> 8); + b[ 2] = (byte)(in0 >> 16); + b[ 3] = (byte)(in0 >> 24); + b[ 4] = (byte)(in0 >> 32); + b[ 5] = (byte)(in0 >> 40); + b[ 6] = (byte)(in0 >> 48); + b[ 7] = (byte)(in1 >> 0); + b[ 8] = (byte)(in1 >> 8); + b[ 9] = (byte)(in1 >> 16); + b[10] = (byte)(in1 >> 24); + b[11] = (byte)(in1 >> 32); + b[12] = (byte)(in1 >> 40); + b[13] = (byte)(in1 >> 48); + b[14] = (byte)(in2 >> 0); + b[15] = (byte)(in2 >> 8); + b[16] = (byte)(in2 >> 16); + b[17] = (byte)(in2 >> 24); + b[18] = (byte)(in2 >> 32); + b[19] = (byte)(in2 >> 40); + b[20] = (byte)(in2 >> 48); + b[21] = (byte)(in3 >> 0); + b[22] = (byte)(in3 >> 8); + b[23] = (byte)(in3 >> 16); + b[24] = (byte)(in3 >> 24); + b[25] = (byte)(in3 >> 32); + b[26] = (byte)(in3 >> 40); + b[27] = (byte)(in3 >> 48); + b[28] = (byte)(in4 >> 0); + b[29] = (byte)(in4 >> 8); + b[30] = (byte)(in4 >> 16); + b[31] = (byte)(in4 >> 24); + b[32] = (byte)(in4 >> 32); + b[33] = (byte)(in4 >> 40); + b[34] = (byte)(in4 >> 48); + b[35] = (byte)(in5 >> 0); + b[36] = (byte)(in5 >> 8); + b[37] = (byte)(in5 >> 16); + b[38] = (byte)(in5 >> 24); + b[39] = (byte)(in5 >> 32); + b[40] = (byte)(in5 >> 40); + b[41] = (byte)(in5 >> 48); + b[42] = (byte)(in6 >> 0); + b[43] = (byte)(in6 >> 8); + b[44] = (byte)(in6 >> 16); + b[45] = (byte)(in6 >> 24); + b[46] = (byte)(in6 >> 32); + b[47] = (byte)(in6 >> 40); + b[48] = (byte)(in6 >> 48); + b[49] = (byte)(in7 >> 0); + b[50] = (byte)(in7 >> 8); + b[51] = (byte)(in7 >> 16); + b[52] = (byte)(in7 >> 24); + b[53] = (byte)(in7 >> 32); + b[54] = (byte)(in7 >> 40); + b[55] = (byte)(in7 >> 48); } /* 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) { unsigned int b = (n[i >> 3] >> (i & 7)) & 1; swap ^= b; - fe448_cswap(x2, x3, swap); - fe448_cswap(z2, z3, swap); + fe448_cswap(x2, x3, (int)swap); + fe448_cswap(z2, z3, (int)swap); swap = b; /* 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; /* Output as bytes */ - b[ 0] = (in0 >> 0); - b[ 1] = (in0 >> 8); - b[ 2] = (in0 >> 16); - b[ 3] = (in0 >> 24) + ((in1 >> 0) << 4); - b[ 4] = (in1 >> 4); - b[ 5] = (in1 >> 12); - b[ 6] = (in1 >> 20); - b[ 7] = (in2 >> 0); - b[ 8] = (in2 >> 8); - b[ 9] = (in2 >> 16); - b[10] = (in2 >> 24) + ((in3 >> 0) << 4); - b[11] = (in3 >> 4); - b[12] = (in3 >> 12); - b[13] = (in3 >> 20); - b[14] = (in4 >> 0); - b[15] = (in4 >> 8); - b[16] = (in4 >> 16); - b[17] = (in4 >> 24) + ((in5 >> 0) << 4); - b[18] = (in5 >> 4); - b[19] = (in5 >> 12); - b[20] = (in5 >> 20); - b[21] = (in6 >> 0); - b[22] = (in6 >> 8); - b[23] = (in6 >> 16); - b[24] = (in6 >> 24) + ((in7 >> 0) << 4); - b[25] = (in7 >> 4); - b[26] = (in7 >> 12); - b[27] = (in7 >> 20); - b[28] = (in8 >> 0); - b[29] = (in8 >> 8); - b[30] = (in8 >> 16); - b[31] = (in8 >> 24) + ((in9 >> 0) << 4); - b[32] = (in9 >> 4); - b[33] = (in9 >> 12); - b[34] = (in9 >> 20); - b[35] = (in10 >> 0); - b[36] = (in10 >> 8); - b[37] = (in10 >> 16); - b[38] = (in10 >> 24) + ((in11 >> 0) << 4); - b[39] = (in11 >> 4); - b[40] = (in11 >> 12); - b[41] = (in11 >> 20); - b[42] = (in12 >> 0); - b[43] = (in12 >> 8); - b[44] = (in12 >> 16); - b[45] = (in12 >> 24) + ((in13 >> 0) << 4); - b[46] = (in13 >> 4); - b[47] = (in13 >> 12); - b[48] = (in13 >> 20); - b[49] = (in14 >> 0); - b[50] = (in14 >> 8); - b[51] = (in14 >> 16); - b[52] = (in14 >> 24) + ((in15 >> 0) << 4); - b[53] = (in15 >> 4); - b[54] = (in15 >> 12); - b[55] = (in15 >> 20); + b[ 0] = (byte)(in0 >> 0); + b[ 1] = (byte)(in0 >> 8); + b[ 2] = (byte)(in0 >> 16); + b[ 3] = (byte)(in0 >> 24) + ((in1 >> 0) << 4); + b[ 4] = (byte)(in1 >> 4); + b[ 5] = (byte)(in1 >> 12); + b[ 6] = (byte)(in1 >> 20); + b[ 7] = (byte)(in2 >> 0); + b[ 8] = (byte)(in2 >> 8); + b[ 9] = (byte)(in2 >> 16); + b[10] = (byte)(in2 >> 24) + ((in3 >> 0) << 4); + b[11] = (byte)(in3 >> 4); + b[12] = (byte)(in3 >> 12); + b[13] = (byte)(in3 >> 20); + b[14] = (byte)(in4 >> 0); + b[15] = (byte)(in4 >> 8); + b[16] = (byte)(in4 >> 16); + b[17] = (byte)(in4 >> 24) + ((in5 >> 0) << 4); + b[18] = (byte)(in5 >> 4); + b[19] = (byte)(in5 >> 12); + b[20] = (byte)(in5 >> 20); + b[21] = (byte)(in6 >> 0); + b[22] = (byte)(in6 >> 8); + b[23] = (byte)(in6 >> 16); + b[24] = (byte)(in6 >> 24) + ((in7 >> 0) << 4); + b[25] = (byte)(in7 >> 4); + b[26] = (byte)(in7 >> 12); + b[27] = (byte)(in7 >> 20); + b[28] = (byte)(in8 >> 0); + b[29] = (byte)(in8 >> 8); + b[30] = (byte)(in8 >> 16); + b[31] = (byte)(in8 >> 24) + ((in9 >> 0) << 4); + b[32] = (byte)(in9 >> 4); + b[33] = (byte)(in9 >> 12); + b[34] = (byte)(in9 >> 20); + b[35] = (byte)(in10 >> 0); + b[36] = (byte)(in10 >> 8); + b[37] = (byte)(in10 >> 16); + b[38] = (byte)(in10 >> 24) + ((in11 >> 0) << 4); + b[39] = (byte)(in11 >> 4); + b[40] = (byte)(in11 >> 12); + b[41] = (byte)(in11 >> 20); + b[42] = (byte)(in12 >> 0); + b[43] = (byte)(in12 >> 8); + b[44] = (byte)(in12 >> 16); + b[45] = (byte)(in12 >> 24) + ((in13 >> 0) << 4); + b[46] = (byte)(in13 >> 4); + b[47] = (byte)(in13 >> 12); + b[48] = (byte)(in13 >> 20); + b[49] = (byte)(in14 >> 0); + b[50] = (byte)(in14 >> 8); + b[51] = (byte)(in14 >> 16); + b[52] = (byte)(in14 >> 24) + ((in15 >> 0) << 4); + b[53] = (byte)(in15 >> 4); + b[54] = (byte)(in15 >> 12); + b[55] = (byte)(in15 >> 20); } /* 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) { unsigned int b = (n[i >> 3] >> (i & 7)) & 1; swap ^= b; - fe448_cswap(x2, x3, swap); - fe448_cswap(z2, z3, swap); + fe448_cswap(x2, x3, (int)swap); + fe448_cswap(z2, z3, (int)swap); swap = b; /* Montgomery Ladder - double and add */ diff --git a/wolfcrypt/src/ge_448.c b/wolfcrypt/src/ge_448.c index fbc1c1f38b..7065b9af17 100644 --- a/wolfcrypt/src/ge_448.c +++ b/wolfcrypt/src/ge_448.c @@ -648,62 +648,62 @@ void sc448_reduce(byte* b) o = d[ 6] >> 56; d[ 7] += o; d[ 6] = d[ 6] & 0xffffffffffffff; /* Convert to bytes */ - b[ 0] = (d[0 ] >> 0); - b[ 1] = (d[0 ] >> 8); - b[ 2] = (d[0 ] >> 16); - b[ 3] = (d[0 ] >> 24); - b[ 4] = (d[0 ] >> 32); - b[ 5] = (d[0 ] >> 40); - b[ 6] = (d[0 ] >> 48); - b[ 7] = (d[1 ] >> 0); - b[ 8] = (d[1 ] >> 8); - b[ 9] = (d[1 ] >> 16); - b[10] = (d[1 ] >> 24); - b[11] = (d[1 ] >> 32); - b[12] = (d[1 ] >> 40); - b[13] = (d[1 ] >> 48); - b[14] = (d[2 ] >> 0); - b[15] = (d[2 ] >> 8); - b[16] = (d[2 ] >> 16); - b[17] = (d[2 ] >> 24); - b[18] = (d[2 ] >> 32); - b[19] = (d[2 ] >> 40); - b[20] = (d[2 ] >> 48); - b[21] = (d[3 ] >> 0); - b[22] = (d[3 ] >> 8); - b[23] = (d[3 ] >> 16); - b[24] = (d[3 ] >> 24); - b[25] = (d[3 ] >> 32); - b[26] = (d[3 ] >> 40); - b[27] = (d[3 ] >> 48); - b[28] = (d[4 ] >> 0); - b[29] = (d[4 ] >> 8); - b[30] = (d[4 ] >> 16); - b[31] = (d[4 ] >> 24); - b[32] = (d[4 ] >> 32); - b[33] = (d[4 ] >> 40); - b[34] = (d[4 ] >> 48); - b[35] = (d[5 ] >> 0); - b[36] = (d[5 ] >> 8); - b[37] = (d[5 ] >> 16); - b[38] = (d[5 ] >> 24); - b[39] = (d[5 ] >> 32); - b[40] = (d[5 ] >> 40); - b[41] = (d[5 ] >> 48); - b[42] = (d[6 ] >> 0); - b[43] = (d[6 ] >> 8); - b[44] = (d[6 ] >> 16); - b[45] = (d[6 ] >> 24); - b[46] = (d[6 ] >> 32); - b[47] = (d[6 ] >> 40); - b[48] = (d[6 ] >> 48); - b[49] = (d[7 ] >> 0); - b[50] = (d[7 ] >> 8); - b[51] = (d[7 ] >> 16); - b[52] = (d[7 ] >> 24); - b[53] = (d[7 ] >> 32); - b[54] = (d[7 ] >> 40); - b[55] = (d[7 ] >> 48); + b[ 0] = (byte)(d[0 ] >> 0); + b[ 1] = (byte)(d[0 ] >> 8); + b[ 2] = (byte)(d[0 ] >> 16); + b[ 3] = (byte)(d[0 ] >> 24); + b[ 4] = (byte)(d[0 ] >> 32); + b[ 5] = (byte)(d[0 ] >> 40); + b[ 6] = (byte)(d[0 ] >> 48); + b[ 7] = (byte)(d[1 ] >> 0); + b[ 8] = (byte)(d[1 ] >> 8); + b[ 9] = (byte)(d[1 ] >> 16); + b[10] = (byte)(d[1 ] >> 24); + b[11] = (byte)(d[1 ] >> 32); + b[12] = (byte)(d[1 ] >> 40); + b[13] = (byte)(d[1 ] >> 48); + b[14] = (byte)(d[2 ] >> 0); + b[15] = (byte)(d[2 ] >> 8); + b[16] = (byte)(d[2 ] >> 16); + b[17] = (byte)(d[2 ] >> 24); + b[18] = (byte)(d[2 ] >> 32); + b[19] = (byte)(d[2 ] >> 40); + b[20] = (byte)(d[2 ] >> 48); + b[21] = (byte)(d[3 ] >> 0); + b[22] = (byte)(d[3 ] >> 8); + b[23] = (byte)(d[3 ] >> 16); + b[24] = (byte)(d[3 ] >> 24); + b[25] = (byte)(d[3 ] >> 32); + b[26] = (byte)(d[3 ] >> 40); + b[27] = (byte)(d[3 ] >> 48); + b[28] = (byte)(d[4 ] >> 0); + b[29] = (byte)(d[4 ] >> 8); + b[30] = (byte)(d[4 ] >> 16); + b[31] = (byte)(d[4 ] >> 24); + b[32] = (byte)(d[4 ] >> 32); + b[33] = (byte)(d[4 ] >> 40); + b[34] = (byte)(d[4 ] >> 48); + b[35] = (byte)(d[5 ] >> 0); + b[36] = (byte)(d[5 ] >> 8); + b[37] = (byte)(d[5 ] >> 16); + b[38] = (byte)(d[5 ] >> 24); + b[39] = (byte)(d[5 ] >> 32); + b[40] = (byte)(d[5 ] >> 40); + b[41] = (byte)(d[5 ] >> 48); + b[42] = (byte)(d[6 ] >> 0); + b[43] = (byte)(d[6 ] >> 8); + b[44] = (byte)(d[6 ] >> 16); + b[45] = (byte)(d[6 ] >> 24); + b[46] = (byte)(d[6 ] >> 32); + b[47] = (byte)(d[6 ] >> 40); + b[48] = (byte)(d[6 ] >> 48); + b[49] = (byte)(d[7 ] >> 0); + b[50] = (byte)(d[7 ] >> 8); + b[51] = (byte)(d[7 ] >> 16); + b[52] = (byte)(d[7 ] >> 24); + b[53] = (byte)(d[7 ] >> 32); + b[54] = (byte)(d[7 ] >> 40); + b[55] = (byte)(d[7 ] >> 48); b[56] = 0; } @@ -894,70 +894,70 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) | ((sword64) (d[55]) << 48); /* a * b + d */ - t[ 0] = dd[ 0] + (sword128)ad[ 0] * bd[ 0]; - t[ 1] = dd[ 1] + (sword128)ad[ 0] * bd[ 1] - + (sword128)ad[ 1] * bd[ 0]; - t[ 2] = dd[ 2] + (sword128)ad[ 0] * bd[ 2] - + (sword128)ad[ 1] * bd[ 1] - + (sword128)ad[ 2] * bd[ 0]; - t[ 3] = dd[ 3] + (sword128)ad[ 0] * bd[ 3] - + (sword128)ad[ 1] * bd[ 2] - + (sword128)ad[ 2] * bd[ 1] - + (sword128)ad[ 3] * bd[ 0]; - t[ 4] = dd[ 4] + (sword128)ad[ 0] * bd[ 4] - + (sword128)ad[ 1] * bd[ 3] - + (sword128)ad[ 2] * bd[ 2] - + (sword128)ad[ 3] * bd[ 1] - + (sword128)ad[ 4] * bd[ 0]; - t[ 5] = dd[ 5] + (sword128)ad[ 0] * bd[ 5] - + (sword128)ad[ 1] * bd[ 4] - + (sword128)ad[ 2] * bd[ 3] - + (sword128)ad[ 3] * bd[ 2] - + (sword128)ad[ 4] * bd[ 1] - + (sword128)ad[ 5] * bd[ 0]; - t[ 6] = dd[ 6] + (sword128)ad[ 0] * bd[ 6] - + (sword128)ad[ 1] * bd[ 5] - + (sword128)ad[ 2] * bd[ 4] - + (sword128)ad[ 3] * bd[ 3] - + (sword128)ad[ 4] * bd[ 2] - + (sword128)ad[ 5] * bd[ 1] - + (sword128)ad[ 6] * bd[ 0]; - t[ 7] = dd[ 7] + (sword128)ad[ 0] * bd[ 7] - + (sword128)ad[ 1] * bd[ 6] - + (sword128)ad[ 2] * bd[ 5] - + (sword128)ad[ 3] * bd[ 4] - + (sword128)ad[ 4] * bd[ 3] - + (sword128)ad[ 5] * bd[ 2] - + (sword128)ad[ 6] * bd[ 1] - + (sword128)ad[ 7] * bd[ 0]; - t[ 8] = (sword128)ad[ 1] * bd[ 7] - + (sword128)ad[ 2] * bd[ 6] - + (sword128)ad[ 3] * bd[ 5] - + (sword128)ad[ 4] * bd[ 4] - + (sword128)ad[ 5] * bd[ 3] - + (sword128)ad[ 6] * bd[ 2] - + (sword128)ad[ 7] * bd[ 1]; - t[ 9] = (sword128)ad[ 2] * bd[ 7] - + (sword128)ad[ 3] * bd[ 6] - + (sword128)ad[ 4] * bd[ 5] - + (sword128)ad[ 5] * bd[ 4] - + (sword128)ad[ 6] * bd[ 3] - + (sword128)ad[ 7] * bd[ 2]; - t[10] = (sword128)ad[ 3] * bd[ 7] - + (sword128)ad[ 4] * bd[ 6] - + (sword128)ad[ 5] * bd[ 5] - + (sword128)ad[ 6] * bd[ 4] - + (sword128)ad[ 7] * bd[ 3]; - t[11] = (sword128)ad[ 4] * bd[ 7] - + (sword128)ad[ 5] * bd[ 6] - + (sword128)ad[ 6] * bd[ 5] - + (sword128)ad[ 7] * bd[ 4]; - t[12] = (sword128)ad[ 5] * bd[ 7] - + (sword128)ad[ 6] * bd[ 6] - + (sword128)ad[ 7] * bd[ 5]; - t[13] = (sword128)ad[ 6] * bd[ 7] - + (sword128)ad[ 7] * bd[ 6]; - t[14] = (sword128)ad[ 7] * bd[ 7]; + t[ 0] = (word128)dd[ 0] + (sword128)ad[ 0] * bd[ 0]; + t[ 1] = (word128)dd[ 1] + (sword128)ad[ 0] * bd[ 1] + + (sword128)ad[ 1] * bd[ 0]; + t[ 2] = (word128)dd[ 2] + (sword128)ad[ 0] * bd[ 2] + + (sword128)ad[ 1] * bd[ 1] + + (sword128)ad[ 2] * bd[ 0]; + t[ 3] = (word128)dd[ 3] + (sword128)ad[ 0] * bd[ 3] + + (sword128)ad[ 1] * bd[ 2] + + (sword128)ad[ 2] * bd[ 1] + + (sword128)ad[ 3] * bd[ 0]; + t[ 4] = (word128)dd[ 4] + (sword128)ad[ 0] * bd[ 4] + + (sword128)ad[ 1] * bd[ 3] + + (sword128)ad[ 2] * bd[ 2] + + (sword128)ad[ 3] * bd[ 1] + + (sword128)ad[ 4] * bd[ 0]; + t[ 5] = (word128)dd[ 5] + (sword128)ad[ 0] * bd[ 5] + + (sword128)ad[ 1] * bd[ 4] + + (sword128)ad[ 2] * bd[ 3] + + (sword128)ad[ 3] * bd[ 2] + + (sword128)ad[ 4] * bd[ 1] + + (sword128)ad[ 5] * bd[ 0]; + t[ 6] = (word128)dd[ 6] + (sword128)ad[ 0] * bd[ 6] + + (sword128)ad[ 1] * bd[ 5] + + (sword128)ad[ 2] * bd[ 4] + + (sword128)ad[ 3] * bd[ 3] + + (sword128)ad[ 4] * bd[ 2] + + (sword128)ad[ 5] * bd[ 1] + + (sword128)ad[ 6] * bd[ 0]; + t[ 7] = (word128)dd[ 7] + (sword128)ad[ 0] * bd[ 7] + + (sword128)ad[ 1] * bd[ 6] + + (sword128)ad[ 2] * bd[ 5] + + (sword128)ad[ 3] * bd[ 4] + + (sword128)ad[ 4] * bd[ 3] + + (sword128)ad[ 5] * bd[ 2] + + (sword128)ad[ 6] * bd[ 1] + + (sword128)ad[ 7] * bd[ 0]; + t[ 8] = (word128) (sword128)ad[ 1] * bd[ 7] + + (sword128)ad[ 2] * bd[ 6] + + (sword128)ad[ 3] * bd[ 5] + + (sword128)ad[ 4] * bd[ 4] + + (sword128)ad[ 5] * bd[ 3] + + (sword128)ad[ 6] * bd[ 2] + + (sword128)ad[ 7] * bd[ 1]; + t[ 9] = (word128) (sword128)ad[ 2] * bd[ 7] + + (sword128)ad[ 3] * bd[ 6] + + (sword128)ad[ 4] * bd[ 5] + + (sword128)ad[ 5] * bd[ 4] + + (sword128)ad[ 6] * bd[ 3] + + (sword128)ad[ 7] * bd[ 2]; + t[10] = (word128) (sword128)ad[ 3] * bd[ 7] + + (sword128)ad[ 4] * bd[ 6] + + (sword128)ad[ 5] * bd[ 5] + + (sword128)ad[ 6] * bd[ 4] + + (sword128)ad[ 7] * bd[ 3]; + t[11] = (word128) (sword128)ad[ 4] * bd[ 7] + + (sword128)ad[ 5] * bd[ 6] + + (sword128)ad[ 6] * bd[ 5] + + (sword128)ad[ 7] * bd[ 4]; + t[12] = (word128) (sword128)ad[ 5] * bd[ 7] + + (sword128)ad[ 6] * bd[ 6] + + (sword128)ad[ 7] * bd[ 5]; + t[13] = (word128) (sword128)ad[ 6] * bd[ 7] + + (sword128)ad[ 7] * bd[ 6]; + t[14] = (word128) (sword128)ad[ 7] * bd[ 7]; t[15] = 0; /* Mod curve order */ @@ -1045,62 +1045,62 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) o = rd[ 6] >> 56; rd[ 7] += o; rd[ 6] = rd[ 6] & 0xffffffffffffff; /* Convert to bytes */ - r[ 0] = (rd[0 ] >> 0); - r[ 1] = (rd[0 ] >> 8); - r[ 2] = (rd[0 ] >> 16); - r[ 3] = (rd[0 ] >> 24); - r[ 4] = (rd[0 ] >> 32); - r[ 5] = (rd[0 ] >> 40); - r[ 6] = (rd[0 ] >> 48); - r[ 7] = (rd[1 ] >> 0); - r[ 8] = (rd[1 ] >> 8); - r[ 9] = (rd[1 ] >> 16); - r[10] = (rd[1 ] >> 24); - r[11] = (rd[1 ] >> 32); - r[12] = (rd[1 ] >> 40); - r[13] = (rd[1 ] >> 48); - r[14] = (rd[2 ] >> 0); - r[15] = (rd[2 ] >> 8); - r[16] = (rd[2 ] >> 16); - r[17] = (rd[2 ] >> 24); - r[18] = (rd[2 ] >> 32); - r[19] = (rd[2 ] >> 40); - r[20] = (rd[2 ] >> 48); - r[21] = (rd[3 ] >> 0); - r[22] = (rd[3 ] >> 8); - r[23] = (rd[3 ] >> 16); - r[24] = (rd[3 ] >> 24); - r[25] = (rd[3 ] >> 32); - r[26] = (rd[3 ] >> 40); - r[27] = (rd[3 ] >> 48); - r[28] = (rd[4 ] >> 0); - r[29] = (rd[4 ] >> 8); - r[30] = (rd[4 ] >> 16); - r[31] = (rd[4 ] >> 24); - r[32] = (rd[4 ] >> 32); - r[33] = (rd[4 ] >> 40); - r[34] = (rd[4 ] >> 48); - r[35] = (rd[5 ] >> 0); - r[36] = (rd[5 ] >> 8); - r[37] = (rd[5 ] >> 16); - r[38] = (rd[5 ] >> 24); - r[39] = (rd[5 ] >> 32); - r[40] = (rd[5 ] >> 40); - r[41] = (rd[5 ] >> 48); - r[42] = (rd[6 ] >> 0); - r[43] = (rd[6 ] >> 8); - r[44] = (rd[6 ] >> 16); - r[45] = (rd[6 ] >> 24); - r[46] = (rd[6 ] >> 32); - r[47] = (rd[6 ] >> 40); - r[48] = (rd[6 ] >> 48); - r[49] = (rd[7 ] >> 0); - r[50] = (rd[7 ] >> 8); - r[51] = (rd[7 ] >> 16); - r[52] = (rd[7 ] >> 24); - r[53] = (rd[7 ] >> 32); - r[54] = (rd[7 ] >> 40); - r[55] = (rd[7 ] >> 48); + r[ 0] = (byte)(rd[0 ] >> 0); + r[ 1] = (byte)(rd[0 ] >> 8); + r[ 2] = (byte)(rd[0 ] >> 16); + r[ 3] = (byte)(rd[0 ] >> 24); + r[ 4] = (byte)(rd[0 ] >> 32); + r[ 5] = (byte)(rd[0 ] >> 40); + r[ 6] = (byte)(rd[0 ] >> 48); + r[ 7] = (byte)(rd[1 ] >> 0); + r[ 8] = (byte)(rd[1 ] >> 8); + r[ 9] = (byte)(rd[1 ] >> 16); + r[10] = (byte)(rd[1 ] >> 24); + r[11] = (byte)(rd[1 ] >> 32); + r[12] = (byte)(rd[1 ] >> 40); + r[13] = (byte)(rd[1 ] >> 48); + r[14] = (byte)(rd[2 ] >> 0); + r[15] = (byte)(rd[2 ] >> 8); + r[16] = (byte)(rd[2 ] >> 16); + r[17] = (byte)(rd[2 ] >> 24); + r[18] = (byte)(rd[2 ] >> 32); + r[19] = (byte)(rd[2 ] >> 40); + r[20] = (byte)(rd[2 ] >> 48); + r[21] = (byte)(rd[3 ] >> 0); + r[22] = (byte)(rd[3 ] >> 8); + r[23] = (byte)(rd[3 ] >> 16); + r[24] = (byte)(rd[3 ] >> 24); + r[25] = (byte)(rd[3 ] >> 32); + r[26] = (byte)(rd[3 ] >> 40); + r[27] = (byte)(rd[3 ] >> 48); + r[28] = (byte)(rd[4 ] >> 0); + r[29] = (byte)(rd[4 ] >> 8); + r[30] = (byte)(rd[4 ] >> 16); + r[31] = (byte)(rd[4 ] >> 24); + r[32] = (byte)(rd[4 ] >> 32); + r[33] = (byte)(rd[4 ] >> 40); + r[34] = (byte)(rd[4 ] >> 48); + r[35] = (byte)(rd[5 ] >> 0); + r[36] = (byte)(rd[5 ] >> 8); + r[37] = (byte)(rd[5 ] >> 16); + r[38] = (byte)(rd[5 ] >> 24); + r[39] = (byte)(rd[5 ] >> 32); + r[40] = (byte)(rd[5 ] >> 40); + r[41] = (byte)(rd[5 ] >> 48); + r[42] = (byte)(rd[6 ] >> 0); + r[43] = (byte)(rd[6 ] >> 8); + r[44] = (byte)(rd[6 ] >> 16); + r[45] = (byte)(rd[6 ] >> 24); + r[46] = (byte)(rd[6 ] >> 32); + r[47] = (byte)(rd[6 ] >> 40); + r[48] = (byte)(rd[6 ] >> 48); + r[49] = (byte)(rd[7 ] >> 0); + r[50] = (byte)(rd[7 ] >> 8); + r[51] = (byte)(rd[7 ] >> 16); + r[52] = (byte)(rd[7 ] >> 24); + r[53] = (byte)(rd[7 ] >> 32); + r[54] = (byte)(rd[7 ] >> 40); + r[55] = (byte)(rd[7 ] >> 48); r[56] = 0; } @@ -5449,62 +5449,62 @@ void sc448_reduce(byte* b) o = d[14] >> 28; d[15] += o; d[14] = d[14] & 0xfffffff; /* Convert to bytes */ - b[ 0] = (d[0 ] >> 0); - b[ 1] = (d[0 ] >> 8); - b[ 2] = (d[0 ] >> 16); - b[ 3] = (d[0 ] >> 24) + ((d[1 ] >> 0) << 4); - b[ 4] = (d[1 ] >> 4); - b[ 5] = (d[1 ] >> 12); - b[ 6] = (d[1 ] >> 20); - b[ 7] = (d[2 ] >> 0); - b[ 8] = (d[2 ] >> 8); - b[ 9] = (d[2 ] >> 16); - b[10] = (d[2 ] >> 24) + ((d[3 ] >> 0) << 4); - b[11] = (d[3 ] >> 4); - b[12] = (d[3 ] >> 12); - b[13] = (d[3 ] >> 20); - b[14] = (d[4 ] >> 0); - b[15] = (d[4 ] >> 8); - b[16] = (d[4 ] >> 16); - b[17] = (d[4 ] >> 24) + ((d[5 ] >> 0) << 4); - b[18] = (d[5 ] >> 4); - b[19] = (d[5 ] >> 12); - b[20] = (d[5 ] >> 20); - b[21] = (d[6 ] >> 0); - b[22] = (d[6 ] >> 8); - b[23] = (d[6 ] >> 16); - b[24] = (d[6 ] >> 24) + ((d[7 ] >> 0) << 4); - b[25] = (d[7 ] >> 4); - b[26] = (d[7 ] >> 12); - b[27] = (d[7 ] >> 20); - b[28] = (d[8 ] >> 0); - b[29] = (d[8 ] >> 8); - b[30] = (d[8 ] >> 16); - b[31] = (d[8 ] >> 24) + ((d[9 ] >> 0) << 4); - b[32] = (d[9 ] >> 4); - b[33] = (d[9 ] >> 12); - b[34] = (d[9 ] >> 20); - b[35] = (d[10] >> 0); - b[36] = (d[10] >> 8); - b[37] = (d[10] >> 16); - b[38] = (d[10] >> 24) + ((d[11] >> 0) << 4); - b[39] = (d[11] >> 4); - b[40] = (d[11] >> 12); - b[41] = (d[11] >> 20); - b[42] = (d[12] >> 0); - b[43] = (d[12] >> 8); - b[44] = (d[12] >> 16); - b[45] = (d[12] >> 24) + ((d[13] >> 0) << 4); - b[46] = (d[13] >> 4); - b[47] = (d[13] >> 12); - b[48] = (d[13] >> 20); - b[49] = (d[14] >> 0); - b[50] = (d[14] >> 8); - b[51] = (d[14] >> 16); - b[52] = (d[14] >> 24) + ((d[15] >> 0) << 4); - b[53] = (d[15] >> 4); - b[54] = (d[15] >> 12); - b[55] = (d[15] >> 20); + b[ 0] = (byte)(d[0 ] >> 0); + b[ 1] = (byte)(d[0 ] >> 8); + b[ 2] = (byte)(d[0 ] >> 16); + b[ 3] = (byte)(d[0 ] >> 24) + ((d[1 ] >> 0) << 4); + b[ 4] = (byte)(d[1 ] >> 4); + b[ 5] = (byte)(d[1 ] >> 12); + b[ 6] = (byte)(d[1 ] >> 20); + b[ 7] = (byte)(d[2 ] >> 0); + b[ 8] = (byte)(d[2 ] >> 8); + b[ 9] = (byte)(d[2 ] >> 16); + b[10] = (byte)(d[2 ] >> 24) + ((d[3 ] >> 0) << 4); + b[11] = (byte)(d[3 ] >> 4); + b[12] = (byte)(d[3 ] >> 12); + b[13] = (byte)(d[3 ] >> 20); + b[14] = (byte)(d[4 ] >> 0); + b[15] = (byte)(d[4 ] >> 8); + b[16] = (byte)(d[4 ] >> 16); + b[17] = (byte)(d[4 ] >> 24) + ((d[5 ] >> 0) << 4); + b[18] = (byte)(d[5 ] >> 4); + b[19] = (byte)(d[5 ] >> 12); + b[20] = (byte)(d[5 ] >> 20); + b[21] = (byte)(d[6 ] >> 0); + b[22] = (byte)(d[6 ] >> 8); + b[23] = (byte)(d[6 ] >> 16); + b[24] = (byte)(d[6 ] >> 24) + ((d[7 ] >> 0) << 4); + b[25] = (byte)(d[7 ] >> 4); + b[26] = (byte)(d[7 ] >> 12); + b[27] = (byte)(d[7 ] >> 20); + b[28] = (byte)(d[8 ] >> 0); + b[29] = (byte)(d[8 ] >> 8); + b[30] = (byte)(d[8 ] >> 16); + b[31] = (byte)(d[8 ] >> 24) + ((d[9 ] >> 0) << 4); + b[32] = (byte)(d[9 ] >> 4); + b[33] = (byte)(d[9 ] >> 12); + b[34] = (byte)(d[9 ] >> 20); + b[35] = (byte)(d[10] >> 0); + b[36] = (byte)(d[10] >> 8); + b[37] = (byte)(d[10] >> 16); + b[38] = (byte)(d[10] >> 24) + ((d[11] >> 0) << 4); + b[39] = (byte)(d[11] >> 4); + b[40] = (byte)(d[11] >> 12); + b[41] = (byte)(d[11] >> 20); + b[42] = (byte)(d[12] >> 0); + b[43] = (byte)(d[12] >> 8); + b[44] = (byte)(d[12] >> 16); + b[45] = (byte)(d[12] >> 24) + ((d[13] >> 0) << 4); + b[46] = (byte)(d[13] >> 4); + b[47] = (byte)(d[13] >> 12); + b[48] = (byte)(d[13] >> 20); + b[49] = (byte)(d[14] >> 0); + b[50] = (byte)(d[14] >> 8); + b[51] = (byte)(d[14] >> 16); + b[52] = (byte)(d[14] >> 24) + ((d[15] >> 0) << 4); + b[53] = (byte)(d[15] >> 4); + b[54] = (byte)(d[15] >> 12); + b[55] = (byte)(d[15] >> 20); b[56] = 0; } @@ -5719,262 +5719,262 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) | (((sword32)((d[55] ) >> 0)) << 20); /* a * b + d */ - t[ 0] = dd[ 0] + (sword64)ad[ 0] * bd[ 0]; - t[ 1] = dd[ 1] + (sword64)ad[ 0] * bd[ 1] - + (sword64)ad[ 1] * bd[ 0]; - t[ 2] = dd[ 2] + (sword64)ad[ 0] * bd[ 2] - + (sword64)ad[ 1] * bd[ 1] - + (sword64)ad[ 2] * bd[ 0]; - t[ 3] = dd[ 3] + (sword64)ad[ 0] * bd[ 3] - + (sword64)ad[ 1] * bd[ 2] - + (sword64)ad[ 2] * bd[ 1] - + (sword64)ad[ 3] * bd[ 0]; - t[ 4] = dd[ 4] + (sword64)ad[ 0] * bd[ 4] - + (sword64)ad[ 1] * bd[ 3] - + (sword64)ad[ 2] * bd[ 2] - + (sword64)ad[ 3] * bd[ 1] - + (sword64)ad[ 4] * bd[ 0]; - t[ 5] = dd[ 5] + (sword64)ad[ 0] * bd[ 5] - + (sword64)ad[ 1] * bd[ 4] - + (sword64)ad[ 2] * bd[ 3] - + (sword64)ad[ 3] * bd[ 2] - + (sword64)ad[ 4] * bd[ 1] - + (sword64)ad[ 5] * bd[ 0]; - t[ 6] = dd[ 6] + (sword64)ad[ 0] * bd[ 6] - + (sword64)ad[ 1] * bd[ 5] - + (sword64)ad[ 2] * bd[ 4] - + (sword64)ad[ 3] * bd[ 3] - + (sword64)ad[ 4] * bd[ 2] - + (sword64)ad[ 5] * bd[ 1] - + (sword64)ad[ 6] * bd[ 0]; - t[ 7] = dd[ 7] + (sword64)ad[ 0] * bd[ 7] - + (sword64)ad[ 1] * bd[ 6] - + (sword64)ad[ 2] * bd[ 5] - + (sword64)ad[ 3] * bd[ 4] - + (sword64)ad[ 4] * bd[ 3] - + (sword64)ad[ 5] * bd[ 2] - + (sword64)ad[ 6] * bd[ 1] - + (sword64)ad[ 7] * bd[ 0]; - t[ 8] = dd[ 8] + (sword64)ad[ 0] * bd[ 8] - + (sword64)ad[ 1] * bd[ 7] - + (sword64)ad[ 2] * bd[ 6] - + (sword64)ad[ 3] * bd[ 5] - + (sword64)ad[ 4] * bd[ 4] - + (sword64)ad[ 5] * bd[ 3] - + (sword64)ad[ 6] * bd[ 2] - + (sword64)ad[ 7] * bd[ 1] - + (sword64)ad[ 8] * bd[ 0]; - t[ 9] = dd[ 9] + (sword64)ad[ 0] * bd[ 9] - + (sword64)ad[ 1] * bd[ 8] - + (sword64)ad[ 2] * bd[ 7] - + (sword64)ad[ 3] * bd[ 6] - + (sword64)ad[ 4] * bd[ 5] - + (sword64)ad[ 5] * bd[ 4] - + (sword64)ad[ 6] * bd[ 3] - + (sword64)ad[ 7] * bd[ 2] - + (sword64)ad[ 8] * bd[ 1] - + (sword64)ad[ 9] * bd[ 0]; - t[10] = dd[10] + (sword64)ad[ 0] * bd[10] - + (sword64)ad[ 1] * bd[ 9] - + (sword64)ad[ 2] * bd[ 8] - + (sword64)ad[ 3] * bd[ 7] - + (sword64)ad[ 4] * bd[ 6] - + (sword64)ad[ 5] * bd[ 5] - + (sword64)ad[ 6] * bd[ 4] - + (sword64)ad[ 7] * bd[ 3] - + (sword64)ad[ 8] * bd[ 2] - + (sword64)ad[ 9] * bd[ 1] - + (sword64)ad[10] * bd[ 0]; - t[11] = dd[11] + (sword64)ad[ 0] * bd[11] - + (sword64)ad[ 1] * bd[10] - + (sword64)ad[ 2] * bd[ 9] - + (sword64)ad[ 3] * bd[ 8] - + (sword64)ad[ 4] * bd[ 7] - + (sword64)ad[ 5] * bd[ 6] - + (sword64)ad[ 6] * bd[ 5] - + (sword64)ad[ 7] * bd[ 4] - + (sword64)ad[ 8] * bd[ 3] - + (sword64)ad[ 9] * bd[ 2] - + (sword64)ad[10] * bd[ 1] - + (sword64)ad[11] * bd[ 0]; - t[12] = dd[12] + (sword64)ad[ 0] * bd[12] - + (sword64)ad[ 1] * bd[11] - + (sword64)ad[ 2] * bd[10] - + (sword64)ad[ 3] * bd[ 9] - + (sword64)ad[ 4] * bd[ 8] - + (sword64)ad[ 5] * bd[ 7] - + (sword64)ad[ 6] * bd[ 6] - + (sword64)ad[ 7] * bd[ 5] - + (sword64)ad[ 8] * bd[ 4] - + (sword64)ad[ 9] * bd[ 3] - + (sword64)ad[10] * bd[ 2] - + (sword64)ad[11] * bd[ 1] - + (sword64)ad[12] * bd[ 0]; - t[13] = dd[13] + (sword64)ad[ 0] * bd[13] - + (sword64)ad[ 1] * bd[12] - + (sword64)ad[ 2] * bd[11] - + (sword64)ad[ 3] * bd[10] - + (sword64)ad[ 4] * bd[ 9] - + (sword64)ad[ 5] * bd[ 8] - + (sword64)ad[ 6] * bd[ 7] - + (sword64)ad[ 7] * bd[ 6] - + (sword64)ad[ 8] * bd[ 5] - + (sword64)ad[ 9] * bd[ 4] - + (sword64)ad[10] * bd[ 3] - + (sword64)ad[11] * bd[ 2] - + (sword64)ad[12] * bd[ 1] - + (sword64)ad[13] * bd[ 0]; - t[14] = dd[14] + (sword64)ad[ 0] * bd[14] - + (sword64)ad[ 1] * bd[13] - + (sword64)ad[ 2] * bd[12] - + (sword64)ad[ 3] * bd[11] - + (sword64)ad[ 4] * bd[10] - + (sword64)ad[ 5] * bd[ 9] - + (sword64)ad[ 6] * bd[ 8] - + (sword64)ad[ 7] * bd[ 7] - + (sword64)ad[ 8] * bd[ 6] - + (sword64)ad[ 9] * bd[ 5] - + (sword64)ad[10] * bd[ 4] - + (sword64)ad[11] * bd[ 3] - + (sword64)ad[12] * bd[ 2] - + (sword64)ad[13] * bd[ 1] - + (sword64)ad[14] * bd[ 0]; - t[15] = dd[15] + (sword64)ad[ 0] * bd[15] - + (sword64)ad[ 1] * bd[14] - + (sword64)ad[ 2] * bd[13] - + (sword64)ad[ 3] * bd[12] - + (sword64)ad[ 4] * bd[11] - + (sword64)ad[ 5] * bd[10] - + (sword64)ad[ 6] * bd[ 9] - + (sword64)ad[ 7] * bd[ 8] - + (sword64)ad[ 8] * bd[ 7] - + (sword64)ad[ 9] * bd[ 6] - + (sword64)ad[10] * bd[ 5] - + (sword64)ad[11] * bd[ 4] - + (sword64)ad[12] * bd[ 3] - + (sword64)ad[13] * bd[ 2] - + (sword64)ad[14] * bd[ 1] - + (sword64)ad[15] * bd[ 0]; - t[16] = (sword64)ad[ 1] * bd[15] - + (sword64)ad[ 2] * bd[14] - + (sword64)ad[ 3] * bd[13] - + (sword64)ad[ 4] * bd[12] - + (sword64)ad[ 5] * bd[11] - + (sword64)ad[ 6] * bd[10] - + (sword64)ad[ 7] * bd[ 9] - + (sword64)ad[ 8] * bd[ 8] - + (sword64)ad[ 9] * bd[ 7] - + (sword64)ad[10] * bd[ 6] - + (sword64)ad[11] * bd[ 5] - + (sword64)ad[12] * bd[ 4] - + (sword64)ad[13] * bd[ 3] - + (sword64)ad[14] * bd[ 2] - + (sword64)ad[15] * bd[ 1]; - t[17] = (sword64)ad[ 2] * bd[15] - + (sword64)ad[ 3] * bd[14] - + (sword64)ad[ 4] * bd[13] - + (sword64)ad[ 5] * bd[12] - + (sword64)ad[ 6] * bd[11] - + (sword64)ad[ 7] * bd[10] - + (sword64)ad[ 8] * bd[ 9] - + (sword64)ad[ 9] * bd[ 8] - + (sword64)ad[10] * bd[ 7] - + (sword64)ad[11] * bd[ 6] - + (sword64)ad[12] * bd[ 5] - + (sword64)ad[13] * bd[ 4] - + (sword64)ad[14] * bd[ 3] - + (sword64)ad[15] * bd[ 2]; - t[18] = (sword64)ad[ 3] * bd[15] - + (sword64)ad[ 4] * bd[14] - + (sword64)ad[ 5] * bd[13] - + (sword64)ad[ 6] * bd[12] - + (sword64)ad[ 7] * bd[11] - + (sword64)ad[ 8] * bd[10] - + (sword64)ad[ 9] * bd[ 9] - + (sword64)ad[10] * bd[ 8] - + (sword64)ad[11] * bd[ 7] - + (sword64)ad[12] * bd[ 6] - + (sword64)ad[13] * bd[ 5] - + (sword64)ad[14] * bd[ 4] - + (sword64)ad[15] * bd[ 3]; - t[19] = (sword64)ad[ 4] * bd[15] - + (sword64)ad[ 5] * bd[14] - + (sword64)ad[ 6] * bd[13] - + (sword64)ad[ 7] * bd[12] - + (sword64)ad[ 8] * bd[11] - + (sword64)ad[ 9] * bd[10] - + (sword64)ad[10] * bd[ 9] - + (sword64)ad[11] * bd[ 8] - + (sword64)ad[12] * bd[ 7] - + (sword64)ad[13] * bd[ 6] - + (sword64)ad[14] * bd[ 5] - + (sword64)ad[15] * bd[ 4]; - t[20] = (sword64)ad[ 5] * bd[15] - + (sword64)ad[ 6] * bd[14] - + (sword64)ad[ 7] * bd[13] - + (sword64)ad[ 8] * bd[12] - + (sword64)ad[ 9] * bd[11] - + (sword64)ad[10] * bd[10] - + (sword64)ad[11] * bd[ 9] - + (sword64)ad[12] * bd[ 8] - + (sword64)ad[13] * bd[ 7] - + (sword64)ad[14] * bd[ 6] - + (sword64)ad[15] * bd[ 5]; - t[21] = (sword64)ad[ 6] * bd[15] - + (sword64)ad[ 7] * bd[14] - + (sword64)ad[ 8] * bd[13] - + (sword64)ad[ 9] * bd[12] - + (sword64)ad[10] * bd[11] - + (sword64)ad[11] * bd[10] - + (sword64)ad[12] * bd[ 9] - + (sword64)ad[13] * bd[ 8] - + (sword64)ad[14] * bd[ 7] - + (sword64)ad[15] * bd[ 6]; - t[22] = (sword64)ad[ 7] * bd[15] - + (sword64)ad[ 8] * bd[14] - + (sword64)ad[ 9] * bd[13] - + (sword64)ad[10] * bd[12] - + (sword64)ad[11] * bd[11] - + (sword64)ad[12] * bd[10] - + (sword64)ad[13] * bd[ 9] - + (sword64)ad[14] * bd[ 8] - + (sword64)ad[15] * bd[ 7]; - t[23] = (sword64)ad[ 8] * bd[15] - + (sword64)ad[ 9] * bd[14] - + (sword64)ad[10] * bd[13] - + (sword64)ad[11] * bd[12] - + (sword64)ad[12] * bd[11] - + (sword64)ad[13] * bd[10] - + (sword64)ad[14] * bd[ 9] - + (sword64)ad[15] * bd[ 8]; - t[24] = (sword64)ad[ 9] * bd[15] - + (sword64)ad[10] * bd[14] - + (sword64)ad[11] * bd[13] - + (sword64)ad[12] * bd[12] - + (sword64)ad[13] * bd[11] - + (sword64)ad[14] * bd[10] - + (sword64)ad[15] * bd[ 9]; - t[25] = (sword64)ad[10] * bd[15] - + (sword64)ad[11] * bd[14] - + (sword64)ad[12] * bd[13] - + (sword64)ad[13] * bd[12] - + (sword64)ad[14] * bd[11] - + (sword64)ad[15] * bd[10]; - t[26] = (sword64)ad[11] * bd[15] - + (sword64)ad[12] * bd[14] - + (sword64)ad[13] * bd[13] - + (sword64)ad[14] * bd[12] - + (sword64)ad[15] * bd[11]; - t[27] = (sword64)ad[12] * bd[15] - + (sword64)ad[13] * bd[14] - + (sword64)ad[14] * bd[13] - + (sword64)ad[15] * bd[12]; - t[28] = (sword64)ad[13] * bd[15] - + (sword64)ad[14] * bd[14] - + (sword64)ad[15] * bd[13]; - t[29] = (sword64)ad[14] * bd[15] - + (sword64)ad[15] * bd[14]; - t[30] = (sword64)ad[15] * bd[15]; + t[ 0] = (word64)dd[ 0] + (sword64)ad[ 0] * bd[ 0]; + t[ 1] = (word64)dd[ 1] + (sword64)ad[ 0] * bd[ 1] + + (sword64)ad[ 1] * bd[ 0]; + t[ 2] = (word64)dd[ 2] + (sword64)ad[ 0] * bd[ 2] + + (sword64)ad[ 1] * bd[ 1] + + (sword64)ad[ 2] * bd[ 0]; + t[ 3] = (word64)dd[ 3] + (sword64)ad[ 0] * bd[ 3] + + (sword64)ad[ 1] * bd[ 2] + + (sword64)ad[ 2] * bd[ 1] + + (sword64)ad[ 3] * bd[ 0]; + t[ 4] = (word64)dd[ 4] + (sword64)ad[ 0] * bd[ 4] + + (sword64)ad[ 1] * bd[ 3] + + (sword64)ad[ 2] * bd[ 2] + + (sword64)ad[ 3] * bd[ 1] + + (sword64)ad[ 4] * bd[ 0]; + t[ 5] = (word64)dd[ 5] + (sword64)ad[ 0] * bd[ 5] + + (sword64)ad[ 1] * bd[ 4] + + (sword64)ad[ 2] * bd[ 3] + + (sword64)ad[ 3] * bd[ 2] + + (sword64)ad[ 4] * bd[ 1] + + (sword64)ad[ 5] * bd[ 0]; + t[ 6] = (word64)dd[ 6] + (sword64)ad[ 0] * bd[ 6] + + (sword64)ad[ 1] * bd[ 5] + + (sword64)ad[ 2] * bd[ 4] + + (sword64)ad[ 3] * bd[ 3] + + (sword64)ad[ 4] * bd[ 2] + + (sword64)ad[ 5] * bd[ 1] + + (sword64)ad[ 6] * bd[ 0]; + t[ 7] = (word64)dd[ 7] + (sword64)ad[ 0] * bd[ 7] + + (sword64)ad[ 1] * bd[ 6] + + (sword64)ad[ 2] * bd[ 5] + + (sword64)ad[ 3] * bd[ 4] + + (sword64)ad[ 4] * bd[ 3] + + (sword64)ad[ 5] * bd[ 2] + + (sword64)ad[ 6] * bd[ 1] + + (sword64)ad[ 7] * bd[ 0]; + t[ 8] = (word64)dd[ 8] + (sword64)ad[ 0] * bd[ 8] + + (sword64)ad[ 1] * bd[ 7] + + (sword64)ad[ 2] * bd[ 6] + + (sword64)ad[ 3] * bd[ 5] + + (sword64)ad[ 4] * bd[ 4] + + (sword64)ad[ 5] * bd[ 3] + + (sword64)ad[ 6] * bd[ 2] + + (sword64)ad[ 7] * bd[ 1] + + (sword64)ad[ 8] * bd[ 0]; + t[ 9] = (word64)dd[ 9] + (sword64)ad[ 0] * bd[ 9] + + (sword64)ad[ 1] * bd[ 8] + + (sword64)ad[ 2] * bd[ 7] + + (sword64)ad[ 3] * bd[ 6] + + (sword64)ad[ 4] * bd[ 5] + + (sword64)ad[ 5] * bd[ 4] + + (sword64)ad[ 6] * bd[ 3] + + (sword64)ad[ 7] * bd[ 2] + + (sword64)ad[ 8] * bd[ 1] + + (sword64)ad[ 9] * bd[ 0]; + t[10] = (word64)dd[10] + (sword64)ad[ 0] * bd[10] + + (sword64)ad[ 1] * bd[ 9] + + (sword64)ad[ 2] * bd[ 8] + + (sword64)ad[ 3] * bd[ 7] + + (sword64)ad[ 4] * bd[ 6] + + (sword64)ad[ 5] * bd[ 5] + + (sword64)ad[ 6] * bd[ 4] + + (sword64)ad[ 7] * bd[ 3] + + (sword64)ad[ 8] * bd[ 2] + + (sword64)ad[ 9] * bd[ 1] + + (sword64)ad[10] * bd[ 0]; + t[11] = (word64)dd[11] + (sword64)ad[ 0] * bd[11] + + (sword64)ad[ 1] * bd[10] + + (sword64)ad[ 2] * bd[ 9] + + (sword64)ad[ 3] * bd[ 8] + + (sword64)ad[ 4] * bd[ 7] + + (sword64)ad[ 5] * bd[ 6] + + (sword64)ad[ 6] * bd[ 5] + + (sword64)ad[ 7] * bd[ 4] + + (sword64)ad[ 8] * bd[ 3] + + (sword64)ad[ 9] * bd[ 2] + + (sword64)ad[10] * bd[ 1] + + (sword64)ad[11] * bd[ 0]; + t[12] = (word64)dd[12] + (sword64)ad[ 0] * bd[12] + + (sword64)ad[ 1] * bd[11] + + (sword64)ad[ 2] * bd[10] + + (sword64)ad[ 3] * bd[ 9] + + (sword64)ad[ 4] * bd[ 8] + + (sword64)ad[ 5] * bd[ 7] + + (sword64)ad[ 6] * bd[ 6] + + (sword64)ad[ 7] * bd[ 5] + + (sword64)ad[ 8] * bd[ 4] + + (sword64)ad[ 9] * bd[ 3] + + (sword64)ad[10] * bd[ 2] + + (sword64)ad[11] * bd[ 1] + + (sword64)ad[12] * bd[ 0]; + t[13] = (word64)dd[13] + (sword64)ad[ 0] * bd[13] + + (sword64)ad[ 1] * bd[12] + + (sword64)ad[ 2] * bd[11] + + (sword64)ad[ 3] * bd[10] + + (sword64)ad[ 4] * bd[ 9] + + (sword64)ad[ 5] * bd[ 8] + + (sword64)ad[ 6] * bd[ 7] + + (sword64)ad[ 7] * bd[ 6] + + (sword64)ad[ 8] * bd[ 5] + + (sword64)ad[ 9] * bd[ 4] + + (sword64)ad[10] * bd[ 3] + + (sword64)ad[11] * bd[ 2] + + (sword64)ad[12] * bd[ 1] + + (sword64)ad[13] * bd[ 0]; + t[14] = (word64)dd[14] + (sword64)ad[ 0] * bd[14] + + (sword64)ad[ 1] * bd[13] + + (sword64)ad[ 2] * bd[12] + + (sword64)ad[ 3] * bd[11] + + (sword64)ad[ 4] * bd[10] + + (sword64)ad[ 5] * bd[ 9] + + (sword64)ad[ 6] * bd[ 8] + + (sword64)ad[ 7] * bd[ 7] + + (sword64)ad[ 8] * bd[ 6] + + (sword64)ad[ 9] * bd[ 5] + + (sword64)ad[10] * bd[ 4] + + (sword64)ad[11] * bd[ 3] + + (sword64)ad[12] * bd[ 2] + + (sword64)ad[13] * bd[ 1] + + (sword64)ad[14] * bd[ 0]; + t[15] = (word64)dd[15] + (sword64)ad[ 0] * bd[15] + + (sword64)ad[ 1] * bd[14] + + (sword64)ad[ 2] * bd[13] + + (sword64)ad[ 3] * bd[12] + + (sword64)ad[ 4] * bd[11] + + (sword64)ad[ 5] * bd[10] + + (sword64)ad[ 6] * bd[ 9] + + (sword64)ad[ 7] * bd[ 8] + + (sword64)ad[ 8] * bd[ 7] + + (sword64)ad[ 9] * bd[ 6] + + (sword64)ad[10] * bd[ 5] + + (sword64)ad[11] * bd[ 4] + + (sword64)ad[12] * bd[ 3] + + (sword64)ad[13] * bd[ 2] + + (sword64)ad[14] * bd[ 1] + + (sword64)ad[15] * bd[ 0]; + t[16] = (word64) (sword64)ad[ 1] * bd[15] + + (sword64)ad[ 2] * bd[14] + + (sword64)ad[ 3] * bd[13] + + (sword64)ad[ 4] * bd[12] + + (sword64)ad[ 5] * bd[11] + + (sword64)ad[ 6] * bd[10] + + (sword64)ad[ 7] * bd[ 9] + + (sword64)ad[ 8] * bd[ 8] + + (sword64)ad[ 9] * bd[ 7] + + (sword64)ad[10] * bd[ 6] + + (sword64)ad[11] * bd[ 5] + + (sword64)ad[12] * bd[ 4] + + (sword64)ad[13] * bd[ 3] + + (sword64)ad[14] * bd[ 2] + + (sword64)ad[15] * bd[ 1]; + t[17] = (word64) (sword64)ad[ 2] * bd[15] + + (sword64)ad[ 3] * bd[14] + + (sword64)ad[ 4] * bd[13] + + (sword64)ad[ 5] * bd[12] + + (sword64)ad[ 6] * bd[11] + + (sword64)ad[ 7] * bd[10] + + (sword64)ad[ 8] * bd[ 9] + + (sword64)ad[ 9] * bd[ 8] + + (sword64)ad[10] * bd[ 7] + + (sword64)ad[11] * bd[ 6] + + (sword64)ad[12] * bd[ 5] + + (sword64)ad[13] * bd[ 4] + + (sword64)ad[14] * bd[ 3] + + (sword64)ad[15] * bd[ 2]; + t[18] = (word64) (sword64)ad[ 3] * bd[15] + + (sword64)ad[ 4] * bd[14] + + (sword64)ad[ 5] * bd[13] + + (sword64)ad[ 6] * bd[12] + + (sword64)ad[ 7] * bd[11] + + (sword64)ad[ 8] * bd[10] + + (sword64)ad[ 9] * bd[ 9] + + (sword64)ad[10] * bd[ 8] + + (sword64)ad[11] * bd[ 7] + + (sword64)ad[12] * bd[ 6] + + (sword64)ad[13] * bd[ 5] + + (sword64)ad[14] * bd[ 4] + + (sword64)ad[15] * bd[ 3]; + t[19] = (word64) (sword64)ad[ 4] * bd[15] + + (sword64)ad[ 5] * bd[14] + + (sword64)ad[ 6] * bd[13] + + (sword64)ad[ 7] * bd[12] + + (sword64)ad[ 8] * bd[11] + + (sword64)ad[ 9] * bd[10] + + (sword64)ad[10] * bd[ 9] + + (sword64)ad[11] * bd[ 8] + + (sword64)ad[12] * bd[ 7] + + (sword64)ad[13] * bd[ 6] + + (sword64)ad[14] * bd[ 5] + + (sword64)ad[15] * bd[ 4]; + t[20] = (word64) (sword64)ad[ 5] * bd[15] + + (sword64)ad[ 6] * bd[14] + + (sword64)ad[ 7] * bd[13] + + (sword64)ad[ 8] * bd[12] + + (sword64)ad[ 9] * bd[11] + + (sword64)ad[10] * bd[10] + + (sword64)ad[11] * bd[ 9] + + (sword64)ad[12] * bd[ 8] + + (sword64)ad[13] * bd[ 7] + + (sword64)ad[14] * bd[ 6] + + (sword64)ad[15] * bd[ 5]; + t[21] = (word64) (sword64)ad[ 6] * bd[15] + + (sword64)ad[ 7] * bd[14] + + (sword64)ad[ 8] * bd[13] + + (sword64)ad[ 9] * bd[12] + + (sword64)ad[10] * bd[11] + + (sword64)ad[11] * bd[10] + + (sword64)ad[12] * bd[ 9] + + (sword64)ad[13] * bd[ 8] + + (sword64)ad[14] * bd[ 7] + + (sword64)ad[15] * bd[ 6]; + t[22] = (word64) (sword64)ad[ 7] * bd[15] + + (sword64)ad[ 8] * bd[14] + + (sword64)ad[ 9] * bd[13] + + (sword64)ad[10] * bd[12] + + (sword64)ad[11] * bd[11] + + (sword64)ad[12] * bd[10] + + (sword64)ad[13] * bd[ 9] + + (sword64)ad[14] * bd[ 8] + + (sword64)ad[15] * bd[ 7]; + t[23] = (word64) (sword64)ad[ 8] * bd[15] + + (sword64)ad[ 9] * bd[14] + + (sword64)ad[10] * bd[13] + + (sword64)ad[11] * bd[12] + + (sword64)ad[12] * bd[11] + + (sword64)ad[13] * bd[10] + + (sword64)ad[14] * bd[ 9] + + (sword64)ad[15] * bd[ 8]; + t[24] = (word64) (sword64)ad[ 9] * bd[15] + + (sword64)ad[10] * bd[14] + + (sword64)ad[11] * bd[13] + + (sword64)ad[12] * bd[12] + + (sword64)ad[13] * bd[11] + + (sword64)ad[14] * bd[10] + + (sword64)ad[15] * bd[ 9]; + t[25] = (word64) (sword64)ad[10] * bd[15] + + (sword64)ad[11] * bd[14] + + (sword64)ad[12] * bd[13] + + (sword64)ad[13] * bd[12] + + (sword64)ad[14] * bd[11] + + (sword64)ad[15] * bd[10]; + t[26] = (word64) (sword64)ad[11] * bd[15] + + (sword64)ad[12] * bd[14] + + (sword64)ad[13] * bd[13] + + (sword64)ad[14] * bd[12] + + (sword64)ad[15] * bd[11]; + t[27] = (word64) (sword64)ad[12] * bd[15] + + (sword64)ad[13] * bd[14] + + (sword64)ad[14] * bd[13] + + (sword64)ad[15] * bd[12]; + t[28] = (word64) (sword64)ad[13] * bd[15] + + (sword64)ad[14] * bd[14] + + (sword64)ad[15] * bd[13]; + t[29] = (word64) (sword64)ad[14] * bd[15] + + (sword64)ad[15] * bd[14]; + t[30] = (word64) (sword64)ad[15] * bd[15]; t[31] = 0; /* Mod curve order */ @@ -6202,62 +6202,62 @@ void sc448_muladd(byte* r, const byte* a, const byte* b, const byte* d) o = rd[14] >> 28; rd[15] += o; rd[14] = rd[14] & 0xfffffff; /* Convert to bytes */ - r[ 0] = (rd[0 ] >> 0); - r[ 1] = (rd[0 ] >> 8); - r[ 2] = (rd[0 ] >> 16); - r[ 3] = (rd[0 ] >> 24) + ((rd[1 ] >> 0) << 4); - r[ 4] = (rd[1 ] >> 4); - r[ 5] = (rd[1 ] >> 12); - r[ 6] = (rd[1 ] >> 20); - r[ 7] = (rd[2 ] >> 0); - r[ 8] = (rd[2 ] >> 8); - r[ 9] = (rd[2 ] >> 16); - r[10] = (rd[2 ] >> 24) + ((rd[3 ] >> 0) << 4); - r[11] = (rd[3 ] >> 4); - r[12] = (rd[3 ] >> 12); - r[13] = (rd[3 ] >> 20); - r[14] = (rd[4 ] >> 0); - r[15] = (rd[4 ] >> 8); - r[16] = (rd[4 ] >> 16); - r[17] = (rd[4 ] >> 24) + ((rd[5 ] >> 0) << 4); - r[18] = (rd[5 ] >> 4); - r[19] = (rd[5 ] >> 12); - r[20] = (rd[5 ] >> 20); - r[21] = (rd[6 ] >> 0); - r[22] = (rd[6 ] >> 8); - r[23] = (rd[6 ] >> 16); - r[24] = (rd[6 ] >> 24) + ((rd[7 ] >> 0) << 4); - r[25] = (rd[7 ] >> 4); - r[26] = (rd[7 ] >> 12); - r[27] = (rd[7 ] >> 20); - r[28] = (rd[8 ] >> 0); - r[29] = (rd[8 ] >> 8); - r[30] = (rd[8 ] >> 16); - r[31] = (rd[8 ] >> 24) + ((rd[9 ] >> 0) << 4); - r[32] = (rd[9 ] >> 4); - r[33] = (rd[9 ] >> 12); - r[34] = (rd[9 ] >> 20); - r[35] = (rd[10] >> 0); - r[36] = (rd[10] >> 8); - r[37] = (rd[10] >> 16); - r[38] = (rd[10] >> 24) + ((rd[11] >> 0) << 4); - r[39] = (rd[11] >> 4); - r[40] = (rd[11] >> 12); - r[41] = (rd[11] >> 20); - r[42] = (rd[12] >> 0); - r[43] = (rd[12] >> 8); - r[44] = (rd[12] >> 16); - r[45] = (rd[12] >> 24) + ((rd[13] >> 0) << 4); - r[46] = (rd[13] >> 4); - r[47] = (rd[13] >> 12); - r[48] = (rd[13] >> 20); - r[49] = (rd[14] >> 0); - r[50] = (rd[14] >> 8); - r[51] = (rd[14] >> 16); - r[52] = (rd[14] >> 24) + ((rd[15] >> 0) << 4); - r[53] = (rd[15] >> 4); - r[54] = (rd[15] >> 12); - r[55] = (rd[15] >> 20); + r[ 0] = (byte)(rd[0 ] >> 0); + r[ 1] = (byte)(rd[0 ] >> 8); + r[ 2] = (byte)(rd[0 ] >> 16); + r[ 3] = (byte)(rd[0 ] >> 24) + ((rd[1 ] >> 0) << 4); + r[ 4] = (byte)(rd[1 ] >> 4); + r[ 5] = (byte)(rd[1 ] >> 12); + r[ 6] = (byte)(rd[1 ] >> 20); + r[ 7] = (byte)(rd[2 ] >> 0); + r[ 8] = (byte)(rd[2 ] >> 8); + r[ 9] = (byte)(rd[2 ] >> 16); + r[10] = (byte)(rd[2 ] >> 24) + ((rd[3 ] >> 0) << 4); + r[11] = (byte)(rd[3 ] >> 4); + r[12] = (byte)(rd[3 ] >> 12); + r[13] = (byte)(rd[3 ] >> 20); + r[14] = (byte)(rd[4 ] >> 0); + r[15] = (byte)(rd[4 ] >> 8); + r[16] = (byte)(rd[4 ] >> 16); + r[17] = (byte)(rd[4 ] >> 24) + ((rd[5 ] >> 0) << 4); + r[18] = (byte)(rd[5 ] >> 4); + r[19] = (byte)(rd[5 ] >> 12); + r[20] = (byte)(rd[5 ] >> 20); + r[21] = (byte)(rd[6 ] >> 0); + r[22] = (byte)(rd[6 ] >> 8); + r[23] = (byte)(rd[6 ] >> 16); + r[24] = (byte)(rd[6 ] >> 24) + ((rd[7 ] >> 0) << 4); + r[25] = (byte)(rd[7 ] >> 4); + r[26] = (byte)(rd[7 ] >> 12); + r[27] = (byte)(rd[7 ] >> 20); + r[28] = (byte)(rd[8 ] >> 0); + r[29] = (byte)(rd[8 ] >> 8); + r[30] = (byte)(rd[8 ] >> 16); + r[31] = (byte)(rd[8 ] >> 24) + ((rd[9 ] >> 0) << 4); + r[32] = (byte)(rd[9 ] >> 4); + r[33] = (byte)(rd[9 ] >> 12); + r[34] = (byte)(rd[9 ] >> 20); + r[35] = (byte)(rd[10] >> 0); + r[36] = (byte)(rd[10] >> 8); + r[37] = (byte)(rd[10] >> 16); + r[38] = (byte)(rd[10] >> 24) + ((rd[11] >> 0) << 4); + r[39] = (byte)(rd[11] >> 4); + r[40] = (byte)(rd[11] >> 12); + r[41] = (byte)(rd[11] >> 20); + r[42] = (byte)(rd[12] >> 0); + r[43] = (byte)(rd[12] >> 8); + r[44] = (byte)(rd[12] >> 16); + r[45] = (byte)(rd[12] >> 24) + ((rd[13] >> 0) << 4); + r[46] = (byte)(rd[13] >> 4); + r[47] = (byte)(rd[13] >> 12); + r[48] = (byte)(rd[13] >> 20); + r[49] = (byte)(rd[14] >> 0); + r[50] = (byte)(rd[14] >> 8); + r[51] = (byte)(rd[14] >> 16); + r[52] = (byte)(rd[14] >> 24) + ((rd[15] >> 0) << 4); + r[53] = (byte)(rd[15] >> 4); + r[54] = (byte)(rd[15] >> 12); + r[55] = (byte)(rd[15] >> 20); r[56] = 0; } @@ -10455,7 +10455,7 @@ void ge448_to_bytes(byte *b, const ge448_p2 *p) fe448_mul(x, p->X, recip); fe448_mul(y, p->Y, recip); fe448_to_bytes(b, y); - b[56] = fe448_isnegative(x) << 7; + b[56] = (byte)fe448_isnegative(x) << 7; } /* Convert point to byte array assuming z is 1. @@ -10466,7 +10466,7 @@ void ge448_to_bytes(byte *b, const ge448_p2 *p) static void ge448_p2z1_to_bytes(byte *b, const ge448_p2 *p) { fe448_to_bytes(b, p->Y); - b[56] = fe448_isnegative(p->X) << 7; + b[56] = (byte)fe448_isnegative(p->X) << 7; } /* Compress the point to y-ordinate and negative bit. @@ -10543,7 +10543,7 @@ static void ge448_select(ge448_precomp* r, int pos, byte b) { ge448 minusx[16]; byte bnegative = negative(b); - byte babs = b - (((-bnegative) & b) << 1); + byte babs = (byte)(b - (((-bnegative) & b) << 1)); ge448_precomp_0(r); cmov(r, &base[pos][0], babs, 1); @@ -10575,12 +10575,12 @@ void ge448_scalarmult_base(ge448_p2* r, const byte* a) e[2 * i + 0] = ((a[i] >> 0) & 0xf) + carry; carry = e[2 * i + 0] + 8; carry >>= 4; - e[2 * i + 0] -= carry << 4; + e[2 * i + 0] -= (byte)(carry << 4); e[2 * i + 1] = ((a[i] >> 4) & 0xf) + carry; carry = e[2 * i + 1] + 8; carry >>= 4; - e[2 * i + 1] -= carry << 4; + e[2 * i + 1] -= (byte)(carry << 4); } e[112] = carry; /* each e[i] is between -8 and 8 */ @@ -10633,10 +10633,11 @@ static void slide(sword8 *r, const byte *a) } if (r[i] + (r[i + b] << b) <= 31) { - r[i] += r[i + b] << b; r[i + b] = 0; + r[i] += (sword8)(r[i + b] << b); + r[i + b] = 0; } else if (r[i] - (r[i + b] << b) >= -31) { - r[i] -= r[i + b] << b; + r[i] -= (sword8)(r[i + b] << b); for (k = i + b; k < 448; ++k) { if (!r[k]) { r[k] = 1; diff --git a/wolfcrypt/src/ge_operations.c b/wolfcrypt/src/ge_operations.c index 95f4f308d5..7f6c7d7264 100644 --- a/wolfcrypt/src/ge_operations.c +++ b/wolfcrypt/src/ge_operations.c @@ -744,38 +744,38 @@ void sc_reduce(byte* s) carry = t[ 3] >> 42; t[ 4] += carry; t[ 3] &= MASK_42; carry = t[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42; - s[ 0] = (t[ 0] >> 0); - s[ 1] = (t[ 0] >> 8); - s[ 2] = (t[ 0] >> 16); - s[ 3] = (t[ 0] >> 24); - s[ 4] = (t[ 0] >> 32); - s[ 5] = (t[ 0] >> 40) | (t[ 1] << 2); - s[ 6] = (t[ 1] >> 6); - s[ 7] = (t[ 1] >> 14); - s[ 8] = (t[ 1] >> 22); - s[ 9] = (t[ 1] >> 30); - s[10] = (t[ 1] >> 38) | (t[ 2] << 4); - s[11] = (t[ 2] >> 4); - s[12] = (t[ 2] >> 12); - s[13] = (t[ 2] >> 20); - s[14] = (t[ 2] >> 28); - s[15] = (t[ 2] >> 36) | (t[ 3] << 6); - s[16] = (t[ 3] >> 2); - s[17] = (t[ 3] >> 10); - s[18] = (t[ 3] >> 18); - s[19] = (t[ 3] >> 26); - s[20] = (t[ 3] >> 34); - s[21] = (t[ 4] >> 0); - s[22] = (t[ 4] >> 8); - s[23] = (t[ 4] >> 16); - s[24] = (t[ 4] >> 24); - s[25] = (t[ 4] >> 32); - s[26] = (t[ 4] >> 40) | (t[ 5] << 2); - s[27] = (t[ 5] >> 6); - s[28] = (t[ 5] >> 14); - s[29] = (t[ 5] >> 22); - s[30] = (t[ 5] >> 30); - s[31] = (t[ 5] >> 38); + s[ 0] = (byte)(t[ 0] >> 0); + s[ 1] = (byte)(t[ 0] >> 8); + s[ 2] = (byte)(t[ 0] >> 16); + s[ 3] = (byte)(t[ 0] >> 24); + s[ 4] = (byte)(t[ 0] >> 32); + s[ 5] = (byte)(t[ 0] >> 40) | (byte)(t[ 1] << 2); + s[ 6] = (byte)(t[ 1] >> 6); + s[ 7] = (byte)(t[ 1] >> 14); + s[ 8] = (byte)(t[ 1] >> 22); + s[ 9] = (byte)(t[ 1] >> 30); + s[10] = (byte)(t[ 1] >> 38) | (byte)(t[ 2] << 4); + s[11] = (byte)(t[ 2] >> 4); + s[12] = (byte)(t[ 2] >> 12); + s[13] = (byte)(t[ 2] >> 20); + s[14] = (byte)(t[ 2] >> 28); + s[15] = (byte)(t[ 2] >> 36) | (byte)(t[ 3] << 6); + s[16] = (byte)(t[ 3] >> 2); + s[17] = (byte)(t[ 3] >> 10); + s[18] = (byte)(t[ 3] >> 18); + s[19] = (byte)(t[ 3] >> 26); + s[20] = (byte)(t[ 3] >> 34); + s[21] = (byte)(t[ 4] >> 0); + s[22] = (byte)(t[ 4] >> 8); + s[23] = (byte)(t[ 4] >> 16); + s[24] = (byte)(t[ 4] >> 24); + s[25] = (byte)(t[ 4] >> 32); + s[26] = (byte)(t[ 4] >> 40) | (byte)(t[ 5] << 2); + s[27] = (byte)(t[ 5] >> 6); + s[28] = (byte)(t[ 5] >> 14); + s[29] = (byte)(t[ 5] >> 22); + s[30] = (byte)(t[ 5] >> 30); + 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[ 4] >> 42; t[ 5] += carry; t[ 4] &= MASK_42; - s[ 0] = (t[ 0] >> 0); - s[ 1] = (t[ 0] >> 8); - s[ 2] = (t[ 0] >> 16); - s[ 3] = (t[ 0] >> 24); - s[ 4] = (t[ 0] >> 32); - s[ 5] = (t[ 0] >> 40) | (t[ 1] << 2); - s[ 6] = (t[ 1] >> 6); - s[ 7] = (t[ 1] >> 14); - s[ 8] = (t[ 1] >> 22); - s[ 9] = (t[ 1] >> 30); - s[10] = (t[ 1] >> 38) | (t[ 2] << 4); - s[11] = (t[ 2] >> 4); - s[12] = (t[ 2] >> 12); - s[13] = (t[ 2] >> 20); - s[14] = (t[ 2] >> 28); - s[15] = (t[ 2] >> 36) | (t[ 3] << 6); - s[16] = (t[ 3] >> 2); - s[17] = (t[ 3] >> 10); - s[18] = (t[ 3] >> 18); - s[19] = (t[ 3] >> 26); - s[20] = (t[ 3] >> 34); - s[21] = (t[ 4] >> 0); - s[22] = (t[ 4] >> 8); - s[23] = (t[ 4] >> 16); - s[24] = (t[ 4] >> 24); - s[25] = (t[ 4] >> 32); - s[26] = (t[ 4] >> 40) | (t[ 5] << 2); - s[27] = (t[ 5] >> 6); - s[28] = (t[ 5] >> 14); - s[29] = (t[ 5] >> 22); - s[30] = (t[ 5] >> 30); - s[31] = (t[ 5] >> 38); + s[ 0] = (byte)(t[ 0] >> 0); + s[ 1] = (byte)(t[ 0] >> 8); + s[ 2] = (byte)(t[ 0] >> 16); + s[ 3] = (byte)(t[ 0] >> 24); + s[ 4] = (byte)(t[ 0] >> 32); + s[ 5] = (byte)(t[ 0] >> 40) | (byte)(t[ 1] << 2); + s[ 6] = (byte)(t[ 1] >> 6); + s[ 7] = (byte)(t[ 1] >> 14); + s[ 8] = (byte)(t[ 1] >> 22); + s[ 9] = (byte)(t[ 1] >> 30); + s[10] = (byte)(t[ 1] >> 38) | (byte)(t[ 2] << 4); + s[11] = (byte)(t[ 2] >> 4); + s[12] = (byte)(t[ 2] >> 12); + s[13] = (byte)(t[ 2] >> 20); + s[14] = (byte)(t[ 2] >> 28); + s[15] = (byte)(t[ 2] >> 36) | (byte)(t[ 3] << 6); + s[16] = (byte)(t[ 3] >> 2); + s[17] = (byte)(t[ 3] >> 10); + s[18] = (byte)(t[ 3] >> 18); + s[19] = (byte)(t[ 3] >> 26); + s[20] = (byte)(t[ 3] >> 34); + s[21] = (byte)(t[ 4] >> 0); + s[22] = (byte)(t[ 4] >> 8); + s[23] = (byte)(t[ 4] >> 16); + s[24] = (byte)(t[ 4] >> 24); + s[25] = (byte)(t[ 4] >> 32); + s[26] = (byte)(t[ 4] >> 40) | (byte)(t[ 5] << 2); + s[27] = (byte)(t[ 5] >> 6); + s[28] = (byte)(t[ 5] >> 14); + s[29] = (byte)(t[ 5] >> 22); + s[30] = (byte)(t[ 5] >> 30); + s[31] = (byte)(t[ 5] >> 38); } #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 /* 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 uc = c; - unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ + unsigned char x = b ^ c; /* 0: yes; 1..255: no */ word32 y = x; /* 0: yes; 1..255: no */ y -= 1; /* 4294967295: yes; 0..254: 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 ge_precomp minust; 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); 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; carry = e[i] + 8; carry >>= 4; - e[i] -= carry << 4; + e[i] -= (signed char)(carry << 4); } e[63] += carry; /* 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) { if (r[i + b]) { 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) { - r[i] -= r[i + b] << b; + r[i] -= (signed char)(r[i + b] << b); for (k = i + b;k < SLIDE_SIZE;++k) { if (!r[k]) { 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(y,h->Y,recip); 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(y,h->Y,recip); fe_tobytes(s,y); - s[31] ^= fe_isnegative(x) << 7; + s[31] ^= (unsigned char)(fe_isnegative(x) << 7); } #endif /* !ED25519_SMALL */ diff --git a/wolfcrypt/src/hpke.c b/wolfcrypt/src/hpke.c index b0d7dc4411..9206f5ceaa 100644 --- a/wolfcrypt/src/hpke.c +++ b/wolfcrypt/src/hpke.c @@ -117,7 +117,7 @@ static int I2OSP(int n, int w, byte* out) } /* 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++) { 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)); - hpke->kem = kem; - hpke->kdf = kdf; - hpke->aead = aead; + hpke->kem = (word32)kem; + hpke->kdf = (word32)kdf; + hpke->aead = (word32)aead; hpke->heap = heap; /* 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->Nsecret = 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; break; #endif @@ -187,7 +187,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap) hpke->curve_id = ECC_SECP384R1; hpke->Nsecret = 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; break; #endif @@ -197,7 +197,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap) hpke->curve_id = ECC_SECP521R1; hpke->Nsecret = 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; break; #endif @@ -272,7 +272,7 @@ int wc_HpkeInit(Hpke* hpke, int kem, int kdf, int aead, void* heap) } if ((int)hpke->Ndh < 0) { - return hpke->Ndh; + return (int)hpke->Ndh; } return ret; @@ -332,7 +332,7 @@ int wc_HpkeGenerateKeyPair(Hpke* hpke, void** keypair, WC_RNG* rng) ret = MEMORY_E; if (ret != 0 && *keypair != NULL) { - wc_HpkeFreeKey(hpke, hpke->kem, *keypair, hpke->heap); + wc_HpkeFreeKey(hpke, (word16)hpke->kem, *keypair, hpke->heap); *keypair = NULL; } @@ -373,7 +373,7 @@ int wc_HpkeSerializePublicKey(Hpke* hpke, void* key, byte* out, word16* outSz) break; } - *outSz = tmpOutSz; + *outSz = (word16)tmpOutSz; return ret; } @@ -430,7 +430,7 @@ int wc_HpkeDeserializePublicKey(Hpke* hpke, void** key, const byte* in, ret = MEMORY_E; if (ret != 0 && *key != NULL) { - wc_HpkeFreeKey(hpke, hpke->kem, *key, hpke->heap); + wc_HpkeFreeKey(hpke, (word16)hpke->kem, *key, hpke->heap); *key = NULL; } @@ -547,7 +547,7 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len, #endif /* copy length */ - ret = I2OSP(L, 2, labeled_info); + ret = I2OSP((int)L, 2, labeled_info); labeled_info_p = labeled_info + 2; 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 * nonce */ - ret = I2OSP(context->seq, hpke->Nn, seq_bytes); + ret = I2OSP(context->seq, (int)hpke->Nn, seq_bytes); if (ret == 0) { 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; } - receiverPubKeySz = hpke->Npk; - ephemeralPubKeySz = hpke->Npk; + receiverPubKeySz = (word16)hpke->Npk; + ephemeralPubKeySz = (word16)hpke->Npk; #ifdef WOLFSSL_SMALL_STACK 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; } - receiverPubKeySz = hpke->Npk; + receiverPubKeySz = (word16)hpke->Npk; #ifdef WOLFSSL_SMALL_STACK 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) - wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap); + wc_HpkeFreeKey(hpke, (word16)hpke->kem, ephemeralKey, hpke->heap); if (ret == 0) { /* copy pubKey into kemContext */ diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index 88d019d063..3763942a75 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -477,7 +477,7 @@ static int get_abs_idx(int relative_idx) return (int)((wc_errors.head_idx + wc_errors.count - 1) % 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, const char *file, const char *reason, int line) { - int sz; + size_t sz; XMEMSET(entry, 0, sizeof(struct wc_error_entry)); entry->err = error; entry->line = line; - sz = (int)XSTRLEN(reason); + sz = XSTRLEN(reason); if (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'; } - sz = (int)XSTRLEN(file); + sz = XSTRLEN(file); if (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) { /* removed entry sits "above" head (or is head), * 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) { XMEMMOVE(&wc_errors.entries[wc_errors.head_idx + 1], &wc_errors.entries[wc_errors.head_idx], @@ -642,7 +642,7 @@ void wc_RemoveErrorNode(int relative_idx) * move entries above it "down" */ int last_idx = get_abs_idx(-1); 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) { XMEMMOVE(&wc_errors.entries[abs_idx], &wc_errors.entries[abs_idx + 1], @@ -746,7 +746,7 @@ unsigned long wc_GetErrorNodeErr(void) wc_ClearErrorNodes(); } } - return ret; + return (unsigned long)ret; } #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", 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"); /* with void function there is no return here, continue on * to unlock mutex and log what buffer was created. */ diff --git a/wolfcrypt/src/md2.c b/wolfcrypt/src/md2.c index 480d6937dc..789704e675 100644 --- a/wolfcrypt/src/md2.c +++ b/wolfcrypt/src/md2.c @@ -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+7] ^= S[t]; } - t = (t + i) & 0xFF; + t = (byte)((t + i) & 0xFF); } } } diff --git a/wolfcrypt/src/pwdbased.c b/wolfcrypt/src/pwdbased.c index e75f5df331..e6ede27311 100644 --- a/wolfcrypt/src/pwdbased.c +++ b/wolfcrypt/src/pwdbased.c @@ -681,7 +681,7 @@ static void scryptROMix(byte* x, byte* v, byte* y, int r, word32 n) word32 i; word32 j; word32 k; - word32 bSz = 128 * r; + word32 bSz = (word32)(128 * r); #ifdef WORD64_AVAILABLE word64* x64 = (word64*)x; 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 WORD64_AVAILABLE - j = *(word64*)(x + (2*r - 1) * 64) & (n-1); + j = (word32)(*(word64*)(x + (2*r - 1) * 64) & (n-1)); #else j = *(word32*)(x + (2*r - 1) * 64) & (n-1); #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 * 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; - bSz = 128 * blockSize; - if ((word32)parallel > (SCRYPT_WORD32_MAX / bSz)) + bSz = 128 * (word32)blockSize; + if (parallel > (int)(SCRYPT_WORD32_MAX / bSz)) return BAD_FUNC_ARG; - blocksSz = bSz * parallel; - blocks = (byte*)XMALLOC(blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); + blocksSz = bSz * (word32)parallel; + blocks = (byte*)XMALLOC((size_t)blocksSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (blocks == NULL) { ret = MEMORY_E; goto end; } /* 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) { ret = MEMORY_E; goto end; } /* 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) { ret = MEMORY_E; goto end; } /* 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); if (ret != 0) goto end; /* Step 2. */ 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. */ - ret = wc_PBKDF2(output, passwd, passLen, blocks, blocksSz, 1, dkLen, + ret = wc_PBKDF2(output, passwd, passLen, blocks, (int)blocksSz, 1, dkLen, WC_SHA256); end: if (blocks != NULL) diff --git a/wolfcrypt/test/test.h b/wolfcrypt/test/test.h index 75f896887e..b58beca0d4 100644 --- a/wolfcrypt/test/test.h +++ b/wolfcrypt/test/test.h @@ -59,7 +59,7 @@ int wolf_test_task(void); #define WC_TEST_RET_TAG_I 3L #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 #define WC_TEST_RET_LN __LINE__ diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 29d5df388b..3562b3d27f 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -2043,7 +2043,7 @@ typedef enum MimeStatus #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_ex(const byte* data, word32 len, byte* hash, 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, int maxIdx); 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_CheckPrivateKey(const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz, enum Key_Sum ks);