diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 1771aa5dc..2e23981b6 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -433,7 +433,9 @@ static int GetInt(mp_int* mpi, const byte* input, word32* inOutIdx, else i--; - mp_init(mpi); + if (mp_init(mpi) != MP_OKAY) + return MP_INIT_E; + if (mp_read_unsigned_bin(mpi, (byte*)input + i, length) != 0) { mp_clear(mpi); return ASN_GETINT_E; @@ -928,14 +930,19 @@ int DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, word32 gSz) gSz--; g++; } - mp_init(&key->p); + if (mp_init(&key->p) != MP_OKAY) + return MP_INIT_E; if (mp_read_unsigned_bin(&key->p, p, pSz) != 0) { mp_clear(&key->p); return ASN_DH_KEY_E; } - mp_init(&key->g); + if (mp_init(&key->g) != MP_OKAY) { + mp_clear(&key->p); + return MP_INIT_E; + } if (mp_read_unsigned_bin(&key->g, g, gSz) != 0) { + mp_clear(&key->g); mp_clear(&key->p); return ASN_DH_KEY_E; } diff --git a/ctaocrypt/src/pwdbased.c b/ctaocrypt/src/pwdbased.c index d36f7e9aa..d493bfa31 100644 --- a/ctaocrypt/src/pwdbased.c +++ b/ctaocrypt/src/pwdbased.c @@ -261,11 +261,14 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, for (i = 0; i < (int)v; i++) B[i] = Ai[i % u]; - mp_init(&B1); - if (mp_read_unsigned_bin(&B1, B, v) != MP_OKAY) + if (mp_init(&B1) != MP_OKAY) + ret = MP_INIT_E; + else if (mp_read_unsigned_bin(&B1, B, v) != MP_OKAY) ret = MP_READ_E; - else if (mp_add_d(&B1, (mp_digit)1, &B1) != MP_OKAY) { + else if (mp_add_d(&B1, (mp_digit)1, &B1) != MP_OKAY) ret = MP_ADD_E; + + if (ret != 0) { mp_clear(&B1); break; } @@ -275,9 +278,10 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, mp_int i1; mp_int res; - mp_init(&i1); - mp_init(&res); - + if (mp_init_multi(&i1, &res, NULL, NULL, NULL, NULL) != MP_OKAY) { + ret = MP_INIT_E; + break; + } if (mp_read_unsigned_bin(&i1, I + i, v) != MP_OKAY) ret = MP_READ_E; else if (mp_add(&i1, &B1, &res) != MP_OKAY) diff --git a/cyassl/ctaocrypt/types.h b/cyassl/ctaocrypt/types.h index 0704b0b5c..7ec8aa650 100644 --- a/cyassl/ctaocrypt/types.h +++ b/cyassl/ctaocrypt/types.h @@ -30,7 +30,7 @@ #endif -#if defined(WORDS_BIGENDIAN) || (defined(__MWERKS__) && !defined(__INTEL__)) +#if defined(WORDS_BIGENDIAN) #define BIG_ENDIAN_ORDER #endif diff --git a/src/ssl.c b/src/ssl.c index d25ebc377..28c5f0cc4 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -6121,8 +6121,11 @@ static int initGlobalRNG = 0; } InitCyaSSL_BigNum(external); - mp_init(mpi); external->internal = mpi; + if (mp_init(mpi) != MP_OKAY) { + CyaSSL_BN_free(external); + return NULL; + } return external; }