wolfcrypt/src/pkcs12.c: fix non-portable casts;

wolfcrypt/src/sp_int.c: use unsigned int, not word32, for sign variables, to match type in header file.
This commit is contained in:
Daniel Pouzzner
2023-04-19 21:22:34 -05:00
parent 2a00b67056
commit da9cda7eae
2 changed files with 20 additions and 20 deletions

View File

@@ -213,7 +213,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
word32 oid; word32 oid;
word32 localIdx = *idx; word32 localIdx = *idx;
int ret; int ret;
word32 size = 0; int size = 0;
byte tag; byte tag;
safe = (AuthenticatedSafe*)XMALLOC(sizeof(AuthenticatedSafe), pkcs12->heap, safe = (AuthenticatedSafe*)XMALLOC(sizeof(AuthenticatedSafe), pkcs12->heap,
@@ -242,7 +242,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (GetLength(input, &localIdx, (int *)&size, maxIdx) <= 0) { if (GetLength(input, &localIdx, &size, maxIdx) <= 0) {
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ASN_PARSE_E; return ASN_PARSE_E;
} }
@@ -265,7 +265,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ASN_PARSE_E; return ASN_PARSE_E;
} }
if (GetLength(input, &localIdx, (int *)&size, maxIdx) <= 0) { if (GetLength(input, &localIdx, &size, maxIdx) <= 0) {
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ASN_PARSE_E; return ASN_PARSE_E;
} }
@@ -273,18 +273,18 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
break; break;
} }
safe->dataSz = size; safe->dataSz = (word32)size;
safe->data = (byte*)XMALLOC(size, pkcs12->heap, DYNAMIC_TYPE_PKCS); safe->data = (byte*)XMALLOC((size_t)size, pkcs12->heap, DYNAMIC_TYPE_PKCS);
if (safe->data == NULL) { if (safe->data == NULL) {
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return MEMORY_E; return MEMORY_E;
} }
XMEMCPY(safe->data, input + localIdx, size); XMEMCPY(safe->data, input + localIdx, (size_t)size);
*idx = localIdx; *idx = localIdx;
localIdx = 0; localIdx = 0;
input = safe->data; input = safe->data;
size = safe->dataSz; size = (int)safe->dataSz;
#ifdef ASN_BER_TO_DER #ifdef ASN_BER_TO_DER
if (pkcs12->indefinite) { if (pkcs12->indefinite) {
@@ -316,15 +316,15 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
* through the ContentInfo's and add them to our * through the ContentInfo's and add them to our
* AuthenticatedSafe struct */ * AuthenticatedSafe struct */
{ {
word32 CISz; int CISz;
ret = GetSequence(input, &localIdx, (int *)&CISz, size); ret = GetSequence(input, &localIdx, &CISz, (word32)size);
if (ret < 0) { if (ret < 0) {
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ASN_PARSE_E; return ASN_PARSE_E;
} }
CISz += localIdx; CISz += (int)localIdx;
while (localIdx < CISz) { while (localIdx < (word32)CISz) {
word32 curSz = 0; int curSz = 0;
word32 curIdx; word32 curIdx;
ContentInfo* ci = NULL; ContentInfo* ci = NULL;
@@ -332,7 +332,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
printf("\t\tlooking for Content Info.... "); printf("\t\tlooking for Content Info.... ");
#endif #endif
if ((ret = GetSequence(input, &localIdx, (int *)&curSz, size)) < 0) { if ((ret = GetSequence(input, &localIdx, &curSz, (word32)size)) < 0) {
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ret; return ret;
} }
@@ -345,7 +345,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
curIdx = localIdx; curIdx = localIdx;
if ((ret = GetObjectId(input, &localIdx, &oid, oidIgnoreType, if ((ret = GetObjectId(input, &localIdx, &oid, oidIgnoreType,
size)) < 0) { (word32)size)) < 0) {
WOLFSSL_LEAVE("Get object id failed", ret); WOLFSSL_LEAVE("Get object id failed", ret);
freeSafe(safe, pkcs12->heap); freeSafe(safe, pkcs12->heap);
return ret; return ret;
@@ -360,7 +360,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
} }
ci->type = (int)oid; ci->type = (int)oid;
ci->dataSz = curSz - (localIdx-curIdx); ci->dataSz = (word32)curSz - (localIdx-curIdx);
ci->data = (byte*)input + localIdx; ci->data = (byte*)input + localIdx;
localIdx += ci->dataSz; localIdx += ci->dataSz;

View File

@@ -8157,8 +8157,8 @@ int sp_div(const sp_int* a, const sp_int* d, sp_int* r, sp_int* rem)
sp_int* tr = NULL; sp_int* tr = NULL;
sp_int* trial = NULL; sp_int* trial = NULL;
#ifdef WOLFSSL_SP_INT_NEGATIVE #ifdef WOLFSSL_SP_INT_NEGATIVE
word32 signA = MP_ZPOS; unsigned int signA = MP_ZPOS;
word32 signD = MP_ZPOS; unsigned int signD = MP_ZPOS;
#endif /* WOLFSSL_SP_INT_NEGATIVE */ #endif /* WOLFSSL_SP_INT_NEGATIVE */
/* Intermediates will always be less than or equal to dividend. */ /* Intermediates will always be less than or equal to dividend. */
DECL_SP_INT_ARRAY(td, (a == NULL) ? 1 : a->used + 1, 4); DECL_SP_INT_ARRAY(td, (a == NULL) ? 1 : a->used + 1, 4);
@@ -11320,7 +11320,7 @@ int sp_mul(const sp_int* a, const sp_int* b, sp_int* r)
{ {
int err = MP_OKAY; int err = MP_OKAY;
#ifdef WOLFSSL_SP_INT_NEGATIVE #ifdef WOLFSSL_SP_INT_NEGATIVE
word32 sign = MP_ZPOS; unsigned int sign = MP_ZPOS;
#endif #endif
if ((a == NULL) || (b == NULL) || (r == NULL)) { if ((a == NULL) || (b == NULL) || (r == NULL)) {
@@ -17321,7 +17321,7 @@ int sp_read_radix(sp_int* a, const char* in, int radix)
{ {
int err = MP_OKAY; int err = MP_OKAY;
#ifdef WOLFSSL_SP_INT_NEGATIVE #ifdef WOLFSSL_SP_INT_NEGATIVE
word32 sign = MP_ZPOS; unsigned int sign = MP_ZPOS;
#endif #endif
if ((a == NULL) || (in == NULL)) { if ((a == NULL) || (in == NULL)) {
@@ -18538,7 +18538,7 @@ int sp_lcm(const sp_int* a, const sp_int* b, sp_int* r)
{ {
int err = MP_OKAY; int err = MP_OKAY;
/* Determine maximum digit length numbers will reach. */ /* Determine maximum digit length numbers will reach. */
word32 used = ((a == NULL) || (b == NULL)) ? 1 : unsigned int used = ((a == NULL) || (b == NULL)) ? 1 :
(a->used >= b->used ? a->used + 1: b->used + 1); (a->used >= b->used ? a->used + 1: b->used + 1);
DECL_SP_INT_ARRAY(t, used, 2); DECL_SP_INT_ARRAY(t, used, 2);