mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Added additional tests to curve448.c through api.c
This commit is contained in:
150
tests/api.c
150
tests/api.c
@@ -16107,6 +16107,154 @@ static int test_wc_curve448_init (void)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} /* END test_wc_curve448_init and wc_curve_448_free*/
|
} /* END test_wc_curve448_init and wc_curve_448_free*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Testing wc_curve448_make_key
|
||||||
|
*/
|
||||||
|
static int test_wc_curve448_make_key (void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#if defined(HAVE_CURVE448)
|
||||||
|
RNG rng;
|
||||||
|
curve448_key key;
|
||||||
|
int keysize;
|
||||||
|
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_curve448_make_key()");
|
||||||
|
|
||||||
|
ret = wc_curve448_init(&key);
|
||||||
|
|
||||||
|
ret = wc_InitRng(&rng);
|
||||||
|
if (ret == 0) {
|
||||||
|
|
||||||
|
|
||||||
|
ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key);
|
||||||
|
if (ret == 0) {
|
||||||
|
keysize = wc_curve448_size(&key);
|
||||||
|
if (keysize != CURVE448_KEY_SIZE) {
|
||||||
|
ret = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_make_key(&rng, keysize, &key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*test bad cases*/
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_make_key(NULL, 0, NULL);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_make_key(&rng, keysize, NULL);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_make_key(NULL, keysize, &key);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_make_key(&rng, 0, &key);
|
||||||
|
if (ret == ECC_BAD_ARG_E) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, ret == 0 ? passed : failed);
|
||||||
|
wc_curve448_free(&key);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
} /*END test_wc_curve448_make_key*/
|
||||||
|
/*
|
||||||
|
* Testing test_wc_curve448_import_private_raw_ex
|
||||||
|
*/
|
||||||
|
static int test_wc_curve448_import_private_raw_ex(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#if defined(HAVE_CURVE448)
|
||||||
|
RNG rng;
|
||||||
|
curve448_key key;
|
||||||
|
byte priv[CURVE448_KEY_SIZE];
|
||||||
|
byte pub[CURVE448_KEY_SIZE];
|
||||||
|
word32 privSz = sizeof(priv);
|
||||||
|
word32 pubSz = sizeof(pub);
|
||||||
|
int endian = EC448_BIG_ENDIAN;
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_curve448_import_private_raw_ex()");
|
||||||
|
|
||||||
|
|
||||||
|
ret = wc_curve448_init(&key);
|
||||||
|
|
||||||
|
ret = wc_InitRng(&rng);
|
||||||
|
if (ret == 0) {
|
||||||
|
|
||||||
|
|
||||||
|
ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key);
|
||||||
|
if (ret == 0){
|
||||||
|
ret = wc_curve448_export_private_raw(&key, priv, &privSz);
|
||||||
|
}
|
||||||
|
if (ret == 0){
|
||||||
|
ret = wc_curve448_export_public(&key, pub, &pubSz);
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||||
|
&key, endian);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*test bad cases*/
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
|
||||||
|
&key, endian);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
|
||||||
|
&key, endian);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||||
|
NULL, endian);
|
||||||
|
if (ret == BAD_FUNC_ARG) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
|
||||||
|
&key, endian);
|
||||||
|
if (ret == ECC_BAD_ARG_E) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
|
||||||
|
&key, endian);
|
||||||
|
if (ret == ECC_BAD_ARG_E) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, ret == 0 ? passed : failed);
|
||||||
|
wc_curve448_free(&key);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
} /*END test_wc_curve448_import_private_raw_ex*/
|
||||||
/*
|
/*
|
||||||
* Testing test_wc_curve448_size.
|
* Testing test_wc_curve448_size.
|
||||||
*/
|
*/
|
||||||
@@ -32790,6 +32938,8 @@ void ApiTest(void)
|
|||||||
AssertIntEQ(test_wc_Ed448PublicKeyToDer(), 0);
|
AssertIntEQ(test_wc_Ed448PublicKeyToDer(), 0);
|
||||||
AssertIntEQ(test_wc_curve448_init(), 0);
|
AssertIntEQ(test_wc_curve448_init(), 0);
|
||||||
AssertIntEQ(test_wc_curve448_size (), 0);
|
AssertIntEQ(test_wc_curve448_size (), 0);
|
||||||
|
AssertIntEQ(test_wc_curve448_import_private_raw_ex (), 0);
|
||||||
|
AssertIntEQ(test_wc_curve448_make_key (), 0);
|
||||||
AssertIntEQ(test_wc_ecc_make_key(), 0);
|
AssertIntEQ(test_wc_ecc_make_key(), 0);
|
||||||
AssertIntEQ(test_wc_ecc_init(), 0);
|
AssertIntEQ(test_wc_ecc_init(), 0);
|
||||||
AssertIntEQ(test_wc_ecc_check_key(), 0);
|
AssertIntEQ(test_wc_ecc_check_key(), 0);
|
||||||
|
Reference in New Issue
Block a user