From 52b6c361f9c4fefb23926612364891ce3771bc20 Mon Sep 17 00:00:00 2001 From: Jack Tjaden Date: Wed, 22 May 2024 11:51:44 -0600 Subject: [PATCH 1/3] test.c code coverage test hpke.c --- wolfcrypt/test/test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 78bf1cdc40..ec6bc537e4 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -27625,6 +27625,22 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void) #endif #endif +/* added this code to hit code coverage on lines 219-225 on hpke.c*/ +#if defined(HAVE_CURVE448) && \ + (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) + /* have_curve448 */ + ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512, + HPKE_AES_128_GCM, NULL); + printf("ERROR RIGHT HERE %d\n",ret); + if (ret == 0) + return WC_TEST_RET_ENC_EC(ret); + + ret = hpke_test_single(hpke); + + if (ret == 0) + return ret; +#endif + #if defined(HAVE_CURVE25519) /* test with curve25519 and aes256 */ ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256, From 1a000ef94c361aafcacc4709399e798be8939a82 Mon Sep 17 00:00:00 2001 From: Jack Tjaden Date: Wed, 22 May 2024 13:13:56 -0600 Subject: [PATCH 2/3] single_test and BAD_FUNC_ARG fix --- wolfcrypt/test/test.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index ec6bc537e4..5fb9b9c785 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -27628,14 +27628,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void) /* added this code to hit code coverage on lines 219-225 on hpke.c*/ #if defined(HAVE_CURVE448) && \ (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) - /* have_curve448 */ + /* test with_curve448 */ ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512, HPKE_AES_128_GCM, NULL); - printf("ERROR RIGHT HERE %d\n",ret); - if (ret == 0) - return WC_TEST_RET_ENC_EC(ret); - ret = hpke_test_single(hpke); + if (ret != BAD_FUNC_ARG) /* Curve448 is not supported yet */ + return WC_TEST_RET_ENC_EC(ret); if (ret == 0) return ret; From 14068fb7f3310105d7df463706fe40ca9b9ac098 Mon Sep 17 00:00:00 2001 From: Jack Tjaden Date: Wed, 22 May 2024 15:58:09 -0600 Subject: [PATCH 3/3] Removed returns & check next case for ret --- wolfcrypt/test/test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 5fb9b9c785..a0fc7ae241 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -27625,24 +27625,24 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void) #endif #endif -/* added this code to hit code coverage on lines 219-225 on hpke.c*/ +/* Test coverage for wc_HpkeInit with Curve448, even though it is not supported */ #if defined(HAVE_CURVE448) && \ (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) /* test with_curve448 */ ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512, - HPKE_AES_128_GCM, NULL); + HPKE_AES_256_GCM, NULL); if (ret != BAD_FUNC_ARG) /* Curve448 is not supported yet */ - return WC_TEST_RET_ENC_EC(ret); - - if (ret == 0) - return ret; + ret = WC_TEST_RET_ENC_EC(ret); + else + ret = 0; #endif #if defined(HAVE_CURVE25519) /* test with curve25519 and aes256 */ - ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256, - HPKE_AES_256_GCM, NULL); + if (ret == 0) + ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256, + HPKE_AES_256_GCM, NULL); if (ret != 0) return WC_TEST_RET_ENC_EC(ret);