diff --git a/tests/api.c b/tests/api.c index 9caa55d54..c52ec3bf5 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2659,6 +2659,8 @@ static void test_wolfSSL_EVP_PKEY_print_public(void) wbio = NULL; #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */ + + /* to prevent "unused variable" warning */ (void)pkey; (void)wbio; (void)rbio; @@ -22512,6 +22514,11 @@ static int test_wc_EccPrivateKeyToDer (void) static int test_wc_EccPublicKeyDecode_ex(void) { int ret = 0; + word32 inOutIdx; + int curveId; + word32 pointIdx; + int pointSz; + #if defined(HAVE_ECC) printf(testingFmt, "test_wc_EccPublicKeyDecode_ex()"); @@ -22521,10 +22528,6 @@ static int test_wc_EccPublicKeyDecode_ex(void) ret = 0; } #if defined(USE_CERT_BUFFERS_256) - word32 inOutIdx; - int curveId; - word32 pointIdx; - int pointSz; if (ret == 0) { ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, @@ -22533,24 +22536,28 @@ static int test_wc_EccPublicKeyDecode_ex(void) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,NULL,NULL,NULL,0); if (ret == BAD_FUNC_ARG) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,&curveId,NULL,NULL,0); if (ret == BAD_FUNC_ARG) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,&curveId,&pointIdx,NULL,0); if(ret == BAD_FUNC_ARG) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,&curveId,&pointIdx,&pointSz,0); if (ret == BAD_FUNC_ARG) @@ -22558,12 +22565,14 @@ static int test_wc_EccPublicKeyDecode_ex(void) } /* pass bad input size */ if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256 - 3 ); if (ret < 0 ) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, &inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256); if (ret == 0 && inOutIdx == 91 && curveId == 7 && @@ -22578,6 +22587,10 @@ static int test_wc_EccPublicKeyDecode_ex(void) printf(resultFmt, ret == 0 ? passed : failed); #endif /* HAVE_ECC */ + (void)inOutIdx; + (void)curveId; + (void)pointIdx; + (void)pointSz; return ret; } /* @@ -22586,12 +22599,12 @@ static int test_wc_EccPublicKeyDecode_ex(void) static int test_wc_DhPublicKeyDecode(void) { int ret = 0; -#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048) - printf(testingFmt, "test_wc_DhPublicKeyDecode()"); - word32 inOutIdx; DhKey key; +#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048) + printf(testingFmt, "test_wc_DhPublicKeyDecode()"); + if (ret == 0) { ret = wc_DhPublicKeyDecode(NULL,NULL,NULL,0); if (ret == BAD_FUNC_ARG) @@ -22603,16 +22616,19 @@ static int test_wc_DhPublicKeyDecode(void) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL,0); if (ret == BAD_FUNC_ARG) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,0); if (ret == BAD_FUNC_ARG) ret = 0; } if (ret == 0) { + inOutIdx = 0; ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, sizeof_dh_pub_key_der_2048); if (ret == 0 && key.p.used != 0 && key.g.used != 0 && @@ -22626,6 +22642,8 @@ static int test_wc_DhPublicKeyDecode(void) printf(resultFmt, ret == 0 ? passed : failed); #endif + (void)inOutIdx; + (void)key; return ret; } diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index baa92d1ad..c65ff7a15 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -6806,15 +6806,15 @@ void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key) #if defined(OPENSSL_EXTRA) static int ToHex( byte in, byte* hex ) { - if ( hex == NULL ) - return 0; - + byte UpNibble,LwNibble; byte HexTbl[16] = { '0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f' }; - byte UpNibble = (in >> 4) & 0x0f; - byte LwNibble = in & 0x0f; + if ( hex == NULL ) + return 0; + UpNibble = (in >> 4) & 0x0f; + LwNibble = in & 0x0f; *hex++ = HexTbl[UpNibble]; *hex = HexTbl[LwNibble]; return 2; @@ -6822,12 +6822,14 @@ static int ToHex( byte in, byte* hex ) /* convert input value to upto five digit decimal */ static int ToDec(word32 in, byte* hex) { + int i = 0; + byte dgt[5]; + word32 quo; + int written; + if (hex == NULL || in > 99999 ) return 0; - - byte dgt[5]; - word32 quo = in; - + quo = in; dgt[4] = quo % 10; quo = quo / 10; dgt[3] = quo % 10; @@ -6839,7 +6841,6 @@ static int ToDec(word32 in, byte* hex) dgt[0] = quo % 10; /* to remove leading zero */ - int i = 0; if (dgt[0] == 0) { if (dgt[1] == 0) { if (dgt[2] == 0) { @@ -6854,39 +6855,45 @@ static int ToDec(word32 in, byte* hex) }else i = 0; - int wrote = 5 - i; + written = 5 - i; for (; i < 5; i++) { *hex++ = dgt[i] + '0'; } - return wrote; + return written; } static int Indent(int indents, byte* dst ) { + int i; if (dst == NULL) return 0; - for (int i = indents; i; i--) {*dst++ = ' ';} + for (i = indents; i; i--) {*dst++ = ' ';} return indents; } static int DumpElement(WOLFSSL_BIO* out, const byte* input, int inlen, int indent) { - int idx = 0; - int wsz = 0; - byte buff[128] = { 0 }; + word32 in = 0; + word32 i; + int idx = 0; + int wsz = 0; + byte buff[128] = { 0 }; + word32 line; + word32 len; + word32 left; + const byte* point; + + point = input; + len = inlen; + line = len / 15; + left = len % 15; /* print pub element */ idx = 0; wsz = Indent(indent, buff + idx); idx += wsz; - const byte* point = input; - word32 len = inlen; - word32 line = len / 15; - word32 left = len % 15; - word32 in = 0; - word32 i; while (line) { idx = 0; @@ -6947,6 +6954,9 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, word32 oid; byte tag; (void)pctx; + int idx = 0; + int wsz = 0; + word32 i; if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) return WOLFSSL_FAILURE; @@ -7013,8 +7023,8 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, /* print out public key elements */ - int idx = 0; - int wsz = 0; + idx = 0; + wsz = 0; wsz = Indent(indent, buff + idx); idx += wsz; @@ -7057,7 +7067,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, idx += wsz; word32 exponent = 0; - for (word32 i = 0; i < eSz; i++) { + for (i = 0; i < eSz; i++) { exponent <<= 8; exponent += e[i]; } @@ -7068,7 +7078,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, XSTRNCPY((char*)(buff + idx), " (0x", wsz); idx += wsz; - for (word32 i = 0; i < eSz; i++) { + for (i = 0; i < eSz; i++) { wsz = ToHex(e[i], buff + idx); idx += wsz; } @@ -7098,8 +7108,11 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, const char* nistCurveName = NULL; int nid; WOLFSSL_ObjectInfo* oi = NULL; - + word32 i; inOutIdx = 0; + int idx = 0; + int wsz = 0; + res = wc_EccPublicKeyDecode_ex(pkey, &inOutIdx, &curveId, &pointIdx, &pointSz, pkeySz); if (res != 0) @@ -7111,7 +7124,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, oi = (WOLFSSL_ObjectInfo*)wolfssl_object_info; OIDName = NULL; - for (size_t i = 0;i < wolfssl_object_info_sz; i++) { + for (i = 0;i < wolfssl_object_info_sz; i++) { if ( (oi + i)->type == oidCurveType && (oi + i)->nid == nid) { OIDName = (char*)((oi + i)->sName); break; @@ -7121,8 +7134,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, /* get NIST curve name */ nistCurveName = wolfSSL_EC_curve_nid2nist(nid); - int idx = 0; - int wsz = 0; + idx = 0; + wsz = 0; wsz = Indent(indent, buff + idx); idx += wsz; @@ -7165,7 +7178,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, XSTRNCPY((char*)(buff + idx), "ASN1 OID: ", wsz); idx += wsz; - wsz = XSTRLEN(OIDName); + wsz = (int)XSTRLEN(OIDName); XSTRNCPY((char*)(buff + idx), OIDName, wsz); idx += wsz; @@ -7186,7 +7199,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, XSTRNCPY((char*)(buff + idx), "NIST CURVE: ", wsz); idx += wsz; - wsz = XSTRLEN(nistCurveName); + wsz = (int)XSTRLEN(nistCurveName); XSTRNCPY((char*)(buff + idx), nistCurveName, wsz); idx += wsz; @@ -7213,6 +7226,8 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, byte tagFound; byte *p = NULL, * q = NULL, * g = NULL, * y = NULL; int pSz, qSz, gSz, ySz; + int idx = 0; + int wsz = 0; inOutIdx = 0; if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) @@ -7289,8 +7304,8 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, y = (byte*)(pkey + inOutIdx); ySz = length; - int idx = 0; - int wsz = 0; + idx = 0; + wsz = 0; wsz = Indent(indent, buff + idx); idx += wsz; @@ -7381,6 +7396,8 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, byte generator; byte* publicKey = NULL; int publicKeySz; + int idx = 0; + int wsz = 0; inOutIdx = 0; if (GetSequence(pkey, &inOutIdx, (int*)&length, pkeySz) < 0) @@ -7444,8 +7461,8 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, } /* print elements */ - int idx = 0; - int wsz = 0; + idx = 0; + wsz = 0; wsz = Indent(indent, buff + idx); idx += wsz;