diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 7a1d0f363..673d89bf2 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -1359,7 +1359,7 @@ static int GetCertHeader(DecodedCert* cert) len = mp_unsigned_bin_size(&mpi); if (len < (int)sizeof(serialTmp)) { - if (mp_to_unsigned_bin(&mpi, serialTmp) == MP_OKAY) { + if ( (ret = mp_to_unsigned_bin(&mpi, serialTmp)) == MP_OKAY) { if (len > EXTERNAL_SERIAL_SIZE) len = EXTERNAL_SERIAL_SIZE; XMEMCPY(cert->serial, serialTmp, len); diff --git a/ctaocrypt/src/ecc.c b/ctaocrypt/src/ecc.c index 9b6cb1aa8..209b41ae5 100644 --- a/ctaocrypt/src/ecc.c +++ b/ctaocrypt/src/ecc.c @@ -1582,20 +1582,23 @@ static int ecc_mul2add(ecc_point* A, mp_int* kA, if (err == MP_OKAY) { /* extract and justify kA */ - mp_to_unsigned_bin(kA, (len - lenA) + tA); + err = mp_to_unsigned_bin(kA, (len - lenA) + tA); /* extract and justify kB */ - mp_to_unsigned_bin(kB, (len - lenB) + tB); + if (err == MP_OKAY) + err = mp_to_unsigned_bin(kB, (len - lenB) + tB); /* allocate the table */ - for (x = 0; x < 16; x++) { - precomp[x] = ecc_new_point(); - if (precomp[x] == NULL) { - for (y = 0; y < x; ++y) { - ecc_del_point(precomp[y]); + if (err == MP_OKAY) { + for (x = 0; x < 16; x++) { + precomp[x] = ecc_new_point(); + if (precomp[x] == NULL) { + for (y = 0; y < x; ++y) { + ecc_del_point(precomp[y]); + } + err = GEN_MEM_ERR; + break; } - err = GEN_MEM_ERR; - break; } } } @@ -1943,6 +1946,7 @@ int ecc_export_x963(ecc_key* key, byte* out, word32* outLen) { byte buf[ECC_BUFSIZE]; word32 numlen; + int ret = MP_OKAY; if (key == NULL || out == NULL || outLen == NULL) return ECC_BAD_ARG_E; @@ -1962,14 +1966,18 @@ int ecc_export_x963(ecc_key* key, byte* out, word32* outLen) /* pad and store x */ XMEMSET(buf, 0, sizeof(buf)); - mp_to_unsigned_bin(&key->pubkey.x, + ret = mp_to_unsigned_bin(&key->pubkey.x, buf + (numlen - mp_unsigned_bin_size(&key->pubkey.x))); + if (ret != MP_OKAY) + return ret; XMEMCPY(out+1, buf, numlen); /* pad and store y */ XMEMSET(buf, 0, sizeof(buf)); - mp_to_unsigned_bin(&key->pubkey.y, + ret = mp_to_unsigned_bin(&key->pubkey.y, buf + (numlen - mp_unsigned_bin_size(&key->pubkey.y))); + if (ret != MP_OKAY) + return ret; XMEMCPY(out+1+numlen, buf, numlen); *outLen = 1 + 2*numlen; diff --git a/ctaocrypt/src/pwdbased.c b/ctaocrypt/src/pwdbased.c index 8a7fc1478..3f330ef4d 100644 --- a/ctaocrypt/src/pwdbased.c +++ b/ctaocrypt/src/pwdbased.c @@ -325,15 +325,15 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, if (outSz > (int)v) { /* take off MSB */ byte tmp[129]; - mp_to_unsigned_bin(&res, tmp); + ret = mp_to_unsigned_bin(&res, tmp); XMEMCPY(I + i, tmp + 1, v); } else if (outSz < (int)v) { XMEMSET(I + i, 0, v - outSz); - mp_to_unsigned_bin(&res, I + i + v - outSz); + ret = mp_to_unsigned_bin(&res, I + i + v - outSz); } else - mp_to_unsigned_bin(&res, I + i); + ret = mp_to_unsigned_bin(&res, I + i); } mp_clear(&i1);