forked from wolfSSL/wolfssl
Merge pull request #3085 from ethanlooney/fourth_branch
API tests for Curve448
This commit is contained in:
319
tests/api.c
319
tests/api.c
@@ -16654,6 +16654,7 @@ 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
|
* Testing wc_curve448_make_key
|
||||||
*/
|
*/
|
||||||
@@ -16720,6 +16721,231 @@ static int test_wc_curve448_make_key (void)
|
|||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
} /*END test_wc_curve448_make_key*/
|
} /*END test_wc_curve448_make_key*/
|
||||||
|
/*
|
||||||
|
* Testing test_wc_curve448_shared_secret_ex
|
||||||
|
*/
|
||||||
|
static int test_wc_curve448_shared_secret_ex (void)
|
||||||
|
{
|
||||||
|
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 (ret == 0){
|
||||||
|
ret = wc_curve448_init(&public_key);
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_export_private_raw_ex(&key, out, &outLen,
|
||||||
|
EC448_LITTLE_ENDIAN);
|
||||||
|
}
|
||||||
|
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
|
* Testing test_wc_curve448_import_private_raw_ex
|
||||||
*/
|
*/
|
||||||
@@ -16797,6 +17023,11 @@ static int test_wc_curve448_import_private_raw_ex(void)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||||
|
&key, EC448_LITTLE_ENDIAN);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (wc_FreeRng(&rng) != 0 && ret == 0) {
|
if (wc_FreeRng(&rng) != 0 && ret == 0) {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
@@ -16808,6 +17039,85 @@ static int test_wc_curve448_import_private_raw_ex(void)
|
|||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
} /*END test_wc_curve448_import_private_raw_ex*/
|
} /*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.
|
* Testing test_wc_curve448_size.
|
||||||
*/
|
*/
|
||||||
@@ -33503,10 +33813,15 @@ void ApiTest(void)
|
|||||||
AssertIntEQ(test_wc_ed448_size(), 0);
|
AssertIntEQ(test_wc_ed448_size(), 0);
|
||||||
AssertIntEQ(test_wc_ed448_exportKey(), 0);
|
AssertIntEQ(test_wc_ed448_exportKey(), 0);
|
||||||
AssertIntEQ(test_wc_Ed448PublicKeyToDer(), 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_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