Added more tests to api.c for curve448
This commit is contained in:
parent
94654c7a46
commit
b7e682e677
316
tests/api.c
316
tests/api.c
@ -16654,6 +16654,7 @@ static int test_wc_curve448_init (void)
|
||||
return ret;
|
||||
|
||||
} /* END test_wc_curve448_init and wc_curve_448_free*/
|
||||
|
||||
/*
|
||||
* Testing wc_curve448_make_key
|
||||
*/
|
||||
@ -16720,10 +16721,235 @@ static int test_wc_curve448_make_key (void)
|
||||
#endif
|
||||
return ret;
|
||||
} /*END test_wc_curve448_make_key*/
|
||||
/*
|
||||
* Testing test_wc_curve448_shared_secret_ex
|
||||
*/
|
||||
static int test_wc_curve448_shared_secret_ex (void) //ethan-3
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
WC_RNG rng;
|
||||
curve448_key private_key, public_key;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
printf(testingFmt, "wc_curve448_shared_secret_ex()");
|
||||
|
||||
ret = wc_curve448_init(&private_key);
|
||||
if (ret == 0) {
|
||||
ret = wc_InitRng(&rng);
|
||||
if (ret == 0){
|
||||
ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key);
|
||||
}
|
||||
if (wc_FreeRng(&rng) && ret == 0) {
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
}
|
||||
ret = wc_curve448_init(&public_key);
|
||||
if (ret == 0) {
|
||||
ret = wc_InitRng(&rng);
|
||||
if (ret == 0){
|
||||
ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian);
|
||||
}
|
||||
/*test bad cases*/
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(NULL, NULL, NULL,
|
||||
0, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(NULL, &public_key, out,
|
||||
&outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(&private_key, NULL, out,
|
||||
&outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
|
||||
&outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
NULL, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
outLen = outLen - 2;
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_curve448_free(&private_key);
|
||||
wc_curve448_free(&public_key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
} /*END test_wc_curve448_shared_secret_ex*/
|
||||
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_export_public_ex
|
||||
*/
|
||||
static int test_wc_curve448_export_public_ex (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
|
||||
WC_RNG rng;
|
||||
curve448_key key;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
printf(testingFmt, "wc_curve448_export_public_ex()");
|
||||
|
||||
ret = wc_curve448_init(&key);
|
||||
if (ret == 0) {
|
||||
ret = wc_InitRng(&rng);
|
||||
}
|
||||
if (ret == 0) {
|
||||
|
||||
ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key);
|
||||
if (ret == 0){
|
||||
ret = wc_curve448_export_public(&key, out, &outLen);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(&key, out, &outLen, endian);
|
||||
}
|
||||
}
|
||||
/*test bad cases*/
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(NULL, NULL, NULL, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(NULL, out, &outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(&key, NULL, &outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(&key, out, NULL, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
outLen = outLen - 2;
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_public_ex(&key, out, &outLen, endian);
|
||||
if (ret == ECC_BAD_ARG_E) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_curve448_free(&key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
} /*END test_wc_curve448_export_public_ex*/
|
||||
/*
|
||||
* Testing test_wc_curve448_export_private_raw_ex
|
||||
*/
|
||||
static int test_wc_curve448_export_private_raw_ex (void)
|
||||
{
|
||||
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
|
||||
WC_RNG rng;
|
||||
curve448_key key;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
printf(testingFmt, "wc_curve448_export_private_raw_ex()");
|
||||
|
||||
ret = wc_curve448_init(&key);
|
||||
if (ret == 0) {
|
||||
ret = wc_InitRng(&rng);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(&key, out, &outLen, endian);
|
||||
}
|
||||
/*test bad cases*/
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(&key, out, NULL, endian);
|
||||
if (ret == BAD_FUNC_ARG) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
outLen = outLen - 2;
|
||||
if (ret == 0) {
|
||||
ret = wc_curve448_export_private_raw_ex(&key, out, &outLen, endian);
|
||||
if (ret == ECC_BAD_ARG_E) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_curve448_free(&key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
}/*END test_wc_curve448_export_private_raw_ex*/
|
||||
/*
|
||||
* Testing test_wc_curve448_import_private_raw_ex
|
||||
*/
|
||||
static int test_wc_curve448_import_private_raw_ex(void)
|
||||
static int test_wc_curve448_import_private_raw_ex (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
@ -16808,6 +17034,85 @@ static int test_wc_curve448_import_private_raw_ex(void)
|
||||
#endif
|
||||
return ret;
|
||||
} /*END test_wc_curve448_import_private_raw_ex*/
|
||||
/*
|
||||
* Testing test_curve448_export_key_raw
|
||||
*/
|
||||
static int test_wc_curve448_export_key_raw (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
WC_RNG rng;
|
||||
curve448_key key;
|
||||
byte priv[CURVE448_KEY_SIZE];
|
||||
byte pub[CURVE448_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
|
||||
printf(testingFmt, "wc_curve448_export_key_raw()");
|
||||
|
||||
ret = wc_curve448_init(&key);
|
||||
if (ret == 0) {
|
||||
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_export_key_raw(&key, priv, &privSz, pub, &pubSz);
|
||||
}
|
||||
}
|
||||
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_curve448_free(&key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
}/*END test_wc_curve448_import_private_raw_ex*/
|
||||
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_import_private
|
||||
*/
|
||||
static int test_wc_curve448_import_private (void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(HAVE_CURVE448)
|
||||
|
||||
curve448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE448_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
|
||||
printf(testingFmt, "wc_curve448_import_private()");
|
||||
|
||||
ret = wc_curve448_init(&key);
|
||||
if (ret == 0) {
|
||||
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_import_private(priv, privSz, &key);
|
||||
}
|
||||
printf(resultFmt, ret == 0 ? passed : failed);
|
||||
wc_curve448_free(&key);
|
||||
wc_FreeRng(&rng);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
} /*END test_wc_curve448_import*/
|
||||
/*
|
||||
* Testing test_wc_curve448_size.
|
||||
*/
|
||||
@ -33503,10 +33808,15 @@ void ApiTest(void)
|
||||
AssertIntEQ(test_wc_ed448_size(), 0);
|
||||
AssertIntEQ(test_wc_ed448_exportKey(), 0);
|
||||
AssertIntEQ(test_wc_Ed448PublicKeyToDer(), 0);
|
||||
AssertIntEQ(test_wc_curve448_make_key (), 0);
|
||||
AssertIntEQ(test_wc_curve448_shared_secret_ex (), 0);
|
||||
AssertIntEQ(test_wc_curve448_export_public_ex (), 0);
|
||||
AssertIntEQ(test_wc_curve448_export_private_raw_ex (), 0);
|
||||
AssertIntEQ(test_wc_curve448_export_key_raw (), 0);
|
||||
AssertIntEQ(test_wc_curve448_import_private_raw_ex (), 0);
|
||||
AssertIntEQ(test_wc_curve448_import_private (), 0);
|
||||
AssertIntEQ(test_wc_curve448_init(), 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_init(), 0);
|
||||
AssertIntEQ(test_wc_ecc_check_key(), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user