Fix undeclared identifier errors

This commit is contained in:
TakayukiMatsuo
2021-02-24 05:38:28 +09:00
parent 760ea219a8
commit 2d0207fc60
2 changed files with 78 additions and 43 deletions

View File

@ -2659,6 +2659,8 @@ static void test_wolfSSL_EVP_PKEY_print_public(void)
wbio = NULL; wbio = NULL;
#endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */ #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
/* to prevent "unused variable" warning */
(void)pkey; (void)pkey;
(void)wbio; (void)wbio;
(void)rbio; (void)rbio;
@ -22512,6 +22514,11 @@ static int test_wc_EccPrivateKeyToDer (void)
static int test_wc_EccPublicKeyDecode_ex(void) static int test_wc_EccPublicKeyDecode_ex(void)
{ {
int ret = 0; int ret = 0;
word32 inOutIdx;
int curveId;
word32 pointIdx;
int pointSz;
#if defined(HAVE_ECC) #if defined(HAVE_ECC)
printf(testingFmt, "test_wc_EccPublicKeyDecode_ex()"); printf(testingFmt, "test_wc_EccPublicKeyDecode_ex()");
@ -22521,10 +22528,6 @@ static int test_wc_EccPublicKeyDecode_ex(void)
ret = 0; ret = 0;
} }
#if defined(USE_CERT_BUFFERS_256) #if defined(USE_CERT_BUFFERS_256)
word32 inOutIdx;
int curveId;
word32 pointIdx;
int pointSz;
if (ret == 0) { if (ret == 0) {
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
@ -22533,24 +22536,28 @@ static int test_wc_EccPublicKeyDecode_ex(void)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,NULL,NULL,NULL,0); &inOutIdx,NULL,NULL,NULL,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,&curveId,NULL,NULL,0); &inOutIdx,&curveId,NULL,NULL,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,&curveId,&pointIdx,NULL,0); &inOutIdx,&curveId,&pointIdx,NULL,0);
if(ret == BAD_FUNC_ARG) if(ret == BAD_FUNC_ARG)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,&curveId,&pointIdx,&pointSz,0); &inOutIdx,&curveId,&pointIdx,&pointSz,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
@ -22558,12 +22565,14 @@ static int test_wc_EccPublicKeyDecode_ex(void)
} }
/* pass bad input size */ /* pass bad input size */
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256 - 3 ); &inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256 - 3 );
if (ret < 0 ) if (ret < 0 )
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256, ret = wc_EccPublicKeyDecode_ex(ecc_clikeypub_der_256,
&inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256); &inOutIdx,&curveId,&pointIdx,&pointSz,sizeof_ecc_clikeypub_der_256);
if (ret == 0 && inOutIdx == 91 && curveId == 7 && if (ret == 0 && inOutIdx == 91 && curveId == 7 &&
@ -22578,6 +22587,10 @@ static int test_wc_EccPublicKeyDecode_ex(void)
printf(resultFmt, ret == 0 ? passed : failed); printf(resultFmt, ret == 0 ? passed : failed);
#endif /* HAVE_ECC */ #endif /* HAVE_ECC */
(void)inOutIdx;
(void)curveId;
(void)pointIdx;
(void)pointSz;
return ret; return ret;
} }
/* /*
@ -22586,12 +22599,12 @@ static int test_wc_EccPublicKeyDecode_ex(void)
static int test_wc_DhPublicKeyDecode(void) static int test_wc_DhPublicKeyDecode(void)
{ {
int ret = 0; int ret = 0;
#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
printf(testingFmt, "test_wc_DhPublicKeyDecode()");
word32 inOutIdx; word32 inOutIdx;
DhKey key; DhKey key;
#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
printf(testingFmt, "test_wc_DhPublicKeyDecode()");
if (ret == 0) { if (ret == 0) {
ret = wc_DhPublicKeyDecode(NULL,NULL,NULL,0); ret = wc_DhPublicKeyDecode(NULL,NULL,NULL,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
@ -22603,16 +22616,19 @@ static int test_wc_DhPublicKeyDecode(void)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL,0); ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,0); ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,0);
if (ret == BAD_FUNC_ARG) if (ret == BAD_FUNC_ARG)
ret = 0; ret = 0;
} }
if (ret == 0) { if (ret == 0) {
inOutIdx = 0;
ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, ret = wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
sizeof_dh_pub_key_der_2048); sizeof_dh_pub_key_der_2048);
if (ret == 0 && key.p.used != 0 && key.g.used != 0 && 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); printf(resultFmt, ret == 0 ? passed : failed);
#endif #endif
(void)inOutIdx;
(void)key;
return ret; return ret;
} }

View File

@ -6806,15 +6806,15 @@ void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY* key)
#if defined(OPENSSL_EXTRA) #if defined(OPENSSL_EXTRA)
static int ToHex( byte in, byte* hex ) static int ToHex( byte in, byte* hex )
{ {
if ( hex == NULL ) byte UpNibble,LwNibble;
return 0;
byte HexTbl[16] = { '0','1','2','3','4','5','6','7', byte HexTbl[16] = { '0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f' }; '8','9','a','b','c','d','e','f' };
byte UpNibble = (in >> 4) & 0x0f; if ( hex == NULL )
byte LwNibble = in & 0x0f; return 0;
UpNibble = (in >> 4) & 0x0f;
LwNibble = in & 0x0f;
*hex++ = HexTbl[UpNibble]; *hex++ = HexTbl[UpNibble];
*hex = HexTbl[LwNibble]; *hex = HexTbl[LwNibble];
return 2; return 2;
@ -6822,12 +6822,14 @@ static int ToHex( byte in, byte* hex )
/* convert input value to upto five digit decimal */ /* convert input value to upto five digit decimal */
static int ToDec(word32 in, byte* hex) static int ToDec(word32 in, byte* hex)
{ {
int i = 0;
byte dgt[5];
word32 quo;
int written;
if (hex == NULL || in > 99999 ) if (hex == NULL || in > 99999 )
return 0; return 0;
quo = in;
byte dgt[5];
word32 quo = in;
dgt[4] = quo % 10; dgt[4] = quo % 10;
quo = quo / 10; quo = quo / 10;
dgt[3] = quo % 10; dgt[3] = quo % 10;
@ -6839,7 +6841,6 @@ static int ToDec(word32 in, byte* hex)
dgt[0] = quo % 10; dgt[0] = quo % 10;
/* to remove leading zero */ /* to remove leading zero */
int i = 0;
if (dgt[0] == 0) { if (dgt[0] == 0) {
if (dgt[1] == 0) { if (dgt[1] == 0) {
if (dgt[2] == 0) { if (dgt[2] == 0) {
@ -6854,39 +6855,45 @@ static int ToDec(word32 in, byte* hex)
}else }else
i = 0; i = 0;
int wrote = 5 - i; written = 5 - i;
for (; i < 5; i++) { for (; i < 5; i++) {
*hex++ = dgt[i] + '0'; *hex++ = dgt[i] + '0';
} }
return wrote; return written;
} }
static int Indent(int indents, byte* dst ) static int Indent(int indents, byte* dst )
{ {
int i;
if (dst == NULL) if (dst == NULL)
return 0; return 0;
for (int i = indents; i; i--) {*dst++ = ' ';} for (i = indents; i; i--) {*dst++ = ' ';}
return indents; return indents;
} }
static int DumpElement(WOLFSSL_BIO* out, const byte* input, static int DumpElement(WOLFSSL_BIO* out, const byte* input,
int inlen, int indent) int inlen, int indent)
{ {
int idx = 0; word32 in = 0;
int wsz = 0; word32 i;
byte buff[128] = { 0 }; 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 */ /* print pub element */
idx = 0; idx = 0;
wsz = Indent(indent, buff + idx); wsz = Indent(indent, buff + idx);
idx += wsz; idx += wsz;
const byte* point = input;
word32 len = inlen;
word32 line = len / 15;
word32 left = len % 15;
word32 in = 0;
word32 i;
while (line) { while (line) {
idx = 0; idx = 0;
@ -6947,6 +6954,9 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
word32 oid; word32 oid;
byte tag; byte tag;
(void)pctx; (void)pctx;
int idx = 0;
int wsz = 0;
word32 i;
if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0) if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 0)
return WOLFSSL_FAILURE; return WOLFSSL_FAILURE;
@ -7013,8 +7023,8 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
/* print out public key elements */ /* print out public key elements */
int idx = 0; idx = 0;
int wsz = 0; wsz = 0;
wsz = Indent(indent, buff + idx); wsz = Indent(indent, buff + idx);
idx += wsz; idx += wsz;
@ -7057,7 +7067,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
idx += wsz; idx += wsz;
word32 exponent = 0; word32 exponent = 0;
for (word32 i = 0; i < eSz; i++) { for (i = 0; i < eSz; i++) {
exponent <<= 8; exponent <<= 8;
exponent += e[i]; exponent += e[i];
} }
@ -7068,7 +7078,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
XSTRNCPY((char*)(buff + idx), " (0x", wsz); XSTRNCPY((char*)(buff + idx), " (0x", wsz);
idx += wsz; idx += wsz;
for (word32 i = 0; i < eSz; i++) { for (i = 0; i < eSz; i++) {
wsz = ToHex(e[i], buff + idx); wsz = ToHex(e[i], buff + idx);
idx += wsz; idx += wsz;
} }
@ -7098,8 +7108,11 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
const char* nistCurveName = NULL; const char* nistCurveName = NULL;
int nid; int nid;
WOLFSSL_ObjectInfo* oi = NULL; WOLFSSL_ObjectInfo* oi = NULL;
word32 i;
inOutIdx = 0; inOutIdx = 0;
int idx = 0;
int wsz = 0;
res = wc_EccPublicKeyDecode_ex(pkey, &inOutIdx, &curveId, res = wc_EccPublicKeyDecode_ex(pkey, &inOutIdx, &curveId,
&pointIdx, &pointSz, pkeySz); &pointIdx, &pointSz, pkeySz);
if (res != 0) if (res != 0)
@ -7111,7 +7124,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
oi = (WOLFSSL_ObjectInfo*)wolfssl_object_info; oi = (WOLFSSL_ObjectInfo*)wolfssl_object_info;
OIDName = NULL; 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) { if ( (oi + i)->type == oidCurveType && (oi + i)->nid == nid) {
OIDName = (char*)((oi + i)->sName); OIDName = (char*)((oi + i)->sName);
break; break;
@ -7121,8 +7134,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
/* get NIST curve name */ /* get NIST curve name */
nistCurveName = wolfSSL_EC_curve_nid2nist(nid); nistCurveName = wolfSSL_EC_curve_nid2nist(nid);
int idx = 0; idx = 0;
int wsz = 0; wsz = 0;
wsz = Indent(indent, buff + idx); wsz = Indent(indent, buff + idx);
idx += wsz; idx += wsz;
@ -7165,7 +7178,7 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
XSTRNCPY((char*)(buff + idx), "ASN1 OID: ", wsz); XSTRNCPY((char*)(buff + idx), "ASN1 OID: ", wsz);
idx += wsz; idx += wsz;
wsz = XSTRLEN(OIDName); wsz = (int)XSTRLEN(OIDName);
XSTRNCPY((char*)(buff + idx), OIDName, wsz); XSTRNCPY((char*)(buff + idx), OIDName, wsz);
idx += 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); XSTRNCPY((char*)(buff + idx), "NIST CURVE: ", wsz);
idx += wsz; idx += wsz;
wsz = XSTRLEN(nistCurveName); wsz = (int)XSTRLEN(nistCurveName);
XSTRNCPY((char*)(buff + idx), nistCurveName, wsz); XSTRNCPY((char*)(buff + idx), nistCurveName, wsz);
idx += wsz; idx += wsz;
@ -7213,6 +7226,8 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
byte tagFound; byte tagFound;
byte *p = NULL, * q = NULL, * g = NULL, * y = NULL; byte *p = NULL, * q = NULL, * g = NULL, * y = NULL;
int pSz, qSz, gSz, ySz; int pSz, qSz, gSz, ySz;
int idx = 0;
int wsz = 0;
inOutIdx = 0; inOutIdx = 0;
if (GetSequence(pkey, &inOutIdx, &length, pkeySz) < 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); y = (byte*)(pkey + inOutIdx);
ySz = length; ySz = length;
int idx = 0; idx = 0;
int wsz = 0; wsz = 0;
wsz = Indent(indent, buff + idx); wsz = Indent(indent, buff + idx);
idx += wsz; idx += wsz;
@ -7381,6 +7396,8 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
byte generator; byte generator;
byte* publicKey = NULL; byte* publicKey = NULL;
int publicKeySz; int publicKeySz;
int idx = 0;
int wsz = 0;
inOutIdx = 0; inOutIdx = 0;
if (GetSequence(pkey, &inOutIdx, (int*)&length, pkeySz) < 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 */ /* print elements */
int idx = 0; idx = 0;
int wsz = 0; wsz = 0;
wsz = Indent(indent, buff + idx); wsz = Indent(indent, buff + idx);
idx += wsz; idx += wsz;