Merge pull request #3246 from ethanlooney/23rd_branch
Added ecc.c unit tests to api.c - final PR
This commit is contained in:
commit
97241331ac
71
tests/api.c
71
tests/api.c
@ -20766,7 +20766,76 @@ static int test_wc_ecc_is_valid_idx (void)
|
||||
|
||||
|
||||
} /* END test_wc_ecc_is_valid_idx */
|
||||
/*
|
||||
* Testing wc_ecc_get_curve_id_from_oid()
|
||||
*/
|
||||
static int test_wc_ecc_get_curve_id_from_oid (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
|
||||
!defined(HAVE_FIPS)
|
||||
const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
|
||||
word32 len = sizeof(oid);
|
||||
|
||||
printf(testingFmt, "wc_ecc_get_curve_id_from_oid()");
|
||||
|
||||
/* Bad Cases */
|
||||
ret = wc_ecc_get_curve_id_from_oid(NULL, len);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_get_curve_id_from_oid(oid, 0);
|
||||
if (ret == ECC_CURVE_INVALID) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
/* Good Case */
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_get_curve_id_from_oid(oid, len);
|
||||
if (ret == 7) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
|
||||
#endif
|
||||
return ret;
|
||||
}/* END test_wc_ecc_get_curve_id_from_oid */
|
||||
/*
|
||||
* Testing wc_ecc_sig_size_calc()
|
||||
*/
|
||||
static int test_wc_ecc_sig_size_calc (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
|
||||
ecc_key key;
|
||||
WC_RNG rng;
|
||||
int sz;
|
||||
|
||||
printf(testingFmt, "wc_ecc_sig_size_calc()");
|
||||
|
||||
ret = wc_InitRng(&rng);
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_init(&key);
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_make_key(&rng, 16, &key);
|
||||
}
|
||||
sz = key.dp->size;
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_sig_size_calc(sz);
|
||||
if (ret > 0) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_ecc_free(&key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
} /* END test_wc_ecc_sig_size_calc */
|
||||
/*
|
||||
* Testing ToTraditional
|
||||
*/
|
||||
@ -36898,6 +36967,8 @@ void ApiTest(void)
|
||||
AssertIntEQ(test_wc_ecc_verify_hash_ex(), 0);
|
||||
AssertIntEQ(test_wc_ecc_mulmod(), 0);
|
||||
AssertIntEQ(test_wc_ecc_is_valid_idx(), 0);
|
||||
AssertIntEQ(test_wc_ecc_get_curve_id_from_oid(), 0);
|
||||
AssertIntEQ(test_wc_ecc_sig_size_calc(), 0);
|
||||
|
||||
|
||||
AssertIntEQ(test_ToTraditional(), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user