Skip to content

Commit 7947814

Browse files
committed
add cleanup logic to sakke_kat_derive_test()
1 parent dcdf650 commit 7947814

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

wolfcrypt/test/test.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52297,44 +52297,67 @@ static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
5229752297
return WC_TEST_RET_ENC_EC(ret);
5229852298
if (iTableLen != 0) {
5229952299
iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
52300-
if (iTable == NULL)
52301-
return WC_TEST_RET_ENC_ERRNO;
52300+
if (iTable == NULL) {
52301+
ret = WC_TEST_RET_ENC_ERRNO;
52302+
goto out;
52303+
}
5230252304
ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
52303-
if (ret != 0)
52304-
return WC_TEST_RET_ENC_EC(ret);
52305+
if (ret != 0) {
52306+
ret = WC_TEST_RET_ENC_EC(ret);
52307+
goto out;
52308+
}
5230552309
}
5230652310
len = 0;
5230752311
ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
52308-
if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
52309-
return WC_TEST_RET_ENC_EC(ret);
52312+
if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
52313+
ret = WC_TEST_RET_ENC_EC(ret);
52314+
goto out;
52315+
}
5231052316
if (len > 0) {
5231152317
table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
52312-
if (table == NULL)
52313-
return WC_TEST_RET_ENC_ERRNO;
52318+
if (table == NULL) {
52319+
ret = WC_TEST_RET_ENC_ERRNO;
52320+
goto out;
52321+
}
5231452322
ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
52315-
if (ret != 0)
52316-
return WC_TEST_RET_ENC_EC(ret);
52323+
if (ret != 0) {
52324+
ret = WC_TEST_RET_ENC_EC(ret);
52325+
goto out;
52326+
}
5231752327
}
5231852328

5231952329
ret = wc_SetSakkeRsk(key, rsk, table, len);
52320-
if (ret != 0)
52321-
return WC_TEST_RET_ENC_EC(ret);
52330+
if (ret != 0) {
52331+
ret = WC_TEST_RET_ENC_EC(ret);
52332+
goto out;
52333+
}
5232252334

5232352335
XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
5232452336
ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
5232552337
auth, sizeof(auth));
52326-
if (ret != 0)
52327-
return WC_TEST_RET_ENC_EC(ret);
52328-
if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
52329-
return WC_TEST_RET_ENC_NC;
52338+
if (ret != 0) {
52339+
ret = WC_TEST_RET_ENC_EC(ret);
52340+
goto out;
52341+
}
52342+
if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0) {
52343+
ret = WC_TEST_RET_ENC_NC;
52344+
goto out;
52345+
}
5233052346

5233152347
/* Don't reference table that is about to be freed. */
5233252348
ret = wc_ClearSakkePointITable(key);
52333-
if (ret != 0)
52334-
return WC_TEST_RET_ENC_EC(ret);
52349+
if (ret != 0) {
52350+
ret = WC_TEST_RET_ENC_EC(ret);
52351+
}
52352+
52353+
out:
5233552354
/* Dispose of tables */
5233652355
XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5233752356
XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
52357+
/* return error code if encountered */
52358+
if (ret != 0) {
52359+
return ret;
52360+
}
5233852361

5233952362
/* Make sure the key public key is exportable - convert to Montgomery form
5234052363
* in Validation.

0 commit comments

Comments
 (0)