Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions test-refactor/client-server/wh_test_crypto_curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,30 +467,46 @@ static int _whTest_CryptoCurve25519CacheKeyAndExportPublic(whClientContext* ctx)
return ret;
}

/* Cache keygen must reject WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoCurve25519MakeCacheKeyEphemeral(whClientContext* ctx)
/* Cache keygen argument checks, including WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoCurve25519MakeCacheKeyArgs(whClientContext* ctx)
{
whKeyId keyId = WH_KEYID_ERASED;
int ret;

ret = wh_Client_Curve25519MakeCacheKey(ctx, CURVE25519_KEYSIZE, &keyId,
WH_NVM_FLAGS_EPHEMERAL, NULL, 0);
if (ret != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("Curve25519MakeCacheKey with EPHEMERAL returned %d "
"(expected BADARGS)\n",
ret);
return WH_TEST_FAIL;
int ret = 0;
whKeyId keyId = WH_KEYID_ERASED;
curve25519_key pub[1] = {0};

if (wh_Client_Curve25519MakeCacheKey(ctx, CURVE25519_KEYSIZE, &keyId,
WH_NVM_FLAGS_EPHEMERAL, NULL,
0) != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("Curve25519 cache keygen accepted EPHEMERAL\n");
ret = WH_TEST_FAIL;
}
WH_TEST_PRINT("CURVE25519 CACHE-KEY EPHEMERAL REJECT SUCCESS\n");
return 0;
if ((wh_Client_Curve25519MakeCacheKeyAndExportPublic(
ctx, CURVE25519_KEYSIZE, &keyId, WH_NVM_FLAGS_EPHEMERAL, NULL, 0,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_Curve25519MakeCacheKeyAndExportPublic(
ctx, CURVE25519_KEYSIZE, NULL, WH_NVM_FLAGS_NONE, NULL, 0, pub) !=
WH_ERROR_BADARGS) ||
(wh_Client_Curve25519MakeCacheKeyAndExportPublic(
ctx, CURVE25519_KEYSIZE, &keyId, WH_NVM_FLAGS_NONE, NULL, 0,
NULL) != WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("Curve25519 cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
if (!WH_KEYID_ISERASED(keyId)) {
(void)wh_Client_KeyEvict(ctx, keyId);
}
if (ret == 0) {
WH_TEST_PRINT("CURVE25519 CACHE-KEY ARGS SUCCESS\n");
}
return ret;
}

int whTest_Crypto_Curve25519(whClientContext* ctx)
{
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoCurve25519(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoCurve25519ExportPublicKey(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoCurve25519CacheKeyAndExportPublic(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoCurve25519MakeCacheKeyEphemeral(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoCurve25519MakeCacheKeyArgs(ctx));
return 0;
}
#endif /* HAVE_CURVE25519 */
Expand Down
32 changes: 32 additions & 0 deletions test-refactor/client-server/wh_test_crypto_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,37 @@ static int _whTest_CryptoEccCacheKeyAndExportPublic(whClientContext* ctx)
return ret;
}

/* Cache keygen argument checks, including WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoEccMakeCacheKeyArgs(whClientContext* ctx)
{
int ret = 0;
whKeyId keyId = WH_KEYID_ERASED;
ecc_key pub[1] = {0};

if ((wh_Client_EccMakeCacheKeyAndExportPublic(
ctx, TEST_ECC_KEYSIZE, TEST_ECC_CURVE_ID, &keyId,
WH_NVM_FLAGS_EPHEMERAL, 0, NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_EccMakeCacheKeyAndExportPublic(
NULL, TEST_ECC_KEYSIZE, TEST_ECC_CURVE_ID, &keyId,
WH_NVM_FLAGS_NONE, 0, NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_EccMakeCacheKeyAndExportPublic(
ctx, TEST_ECC_KEYSIZE, TEST_ECC_CURVE_ID, NULL, WH_NVM_FLAGS_NONE,
0, NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_EccMakeCacheKeyAndExportPublic(
ctx, TEST_ECC_KEYSIZE, TEST_ECC_CURVE_ID, &keyId,
WH_NVM_FLAGS_NONE, 0, NULL, NULL) != WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("ECC cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
if (!WH_KEYID_ISERASED(keyId)) {
(void)wh_Client_KeyEvict(ctx, keyId);
}
if (ret == 0) {
WH_TEST_PRINT("ECC CACHE-KEY ARGS SUCCESS\n");
}
return ret;
}

#if !defined(WOLF_CRYPTO_CB_ONLY_ECC)

/* Build a private-key-only ECC key bound to devId, along with a locally
Expand Down Expand Up @@ -2388,6 +2419,7 @@ int whTest_Crypto_Ecc(whClientContext* ctx)
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEccCacheDuplicate(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEccExportPublicKey(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEccCacheKeyAndExportPublic(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEccMakeCacheKeyArgs(ctx));
#if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEccMakePub(ctx));
#ifdef HAVE_ECC_CHECK_KEY
Expand Down
44 changes: 29 additions & 15 deletions test-refactor/client-server/wh_test_crypto_ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,22 +727,36 @@ static int _whTest_CryptoEd25519BufferTooSmall(whClientContext* ctx)
return ret;
}

/* Cache keygen must reject WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoEd25519MakeCacheKeyEphemeral(whClientContext* ctx)
/* Cache keygen argument checks, including WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoEd25519MakeCacheKeyArgs(whClientContext* ctx)
{
whKeyId keyId = WH_KEYID_ERASED;
int ret;

ret = wh_Client_Ed25519MakeCacheKey(ctx, &keyId, WH_NVM_FLAGS_EPHEMERAL, 0,
NULL);
if (ret != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("Ed25519MakeCacheKey with EPHEMERAL returned %d "
"(expected BADARGS)\n",
ret);
return WH_TEST_FAIL;
int ret = 0;
whKeyId keyId = WH_KEYID_ERASED;
ed25519_key pub[1] = {0};

if (wh_Client_Ed25519MakeCacheKey(ctx, &keyId, WH_NVM_FLAGS_EPHEMERAL, 0,
NULL) != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("Ed25519 cache keygen accepted EPHEMERAL\n");
ret = WH_TEST_FAIL;
}
WH_TEST_PRINT("Ed25519 CACHE-KEY EPHEMERAL REJECT SUCCESS\n");
return 0;
if ((wh_Client_Ed25519MakeCacheKeyAndExportPublic(
ctx, &keyId, WH_NVM_FLAGS_EPHEMERAL, 0, NULL, pub) !=
WH_ERROR_BADARGS) ||
(wh_Client_Ed25519MakeCacheKeyAndExportPublic(
ctx, NULL, WH_NVM_FLAGS_NONE, 0, NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_Ed25519MakeCacheKeyAndExportPublic(
ctx, &keyId, WH_NVM_FLAGS_NONE, 0, NULL, NULL) !=
WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("Ed25519 cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
if (!WH_KEYID_ISERASED(keyId)) {
(void)wh_Client_KeyEvict(ctx, keyId);
}
if (ret == 0) {
WH_TEST_PRINT("Ed25519 CACHE-KEY ARGS SUCCESS\n");
}
return ret;
}

/* A NULL key must be rejected before its devCtx is read */
Expand Down Expand Up @@ -784,7 +798,7 @@ int whTest_Crypto_Ed25519(whClientContext* ctx)
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519ExportPublicKey(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519CacheKeyAndExportPublic(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519BufferTooSmall(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519MakeCacheKeyEphemeral(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519MakeCacheKeyArgs(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519NullKey(ctx));
return 0;
}
Expand Down
60 changes: 45 additions & 15 deletions test-refactor/client-server/wh_test_crypto_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,22 +1348,52 @@ static int _whTest_CryptoMlDsaBufferTooSmall(whClientContext* ctx)
return ret;
}

/* Cache keygen must reject WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoMlDsaMakeCacheKeyEphemeral(whClientContext* ctx)
/* Cache keygen argument checks, including WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoMlDsaMakeCacheKeyArgs(whClientContext* ctx)
{
whKeyId keyId = WH_KEYID_ERASED;
int ret;

ret = wh_Client_MlDsaMakeCacheKey(ctx, 0, WC_ML_DSA_44, &keyId,
WH_NVM_FLAGS_EPHEMERAL, 0, NULL);
if (ret != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("MlDsaMakeCacheKey with EPHEMERAL returned %d "
"(expected BADARGS)\n",
ret);
return WH_TEST_FAIL;
int ret = 0;
whKeyId keyId = WH_KEYID_ERASED;
MlDsaKey pub[1] = {0};

if (wh_Client_MlDsaMakeCacheKey(ctx, 0, WC_ML_DSA_44, &keyId,
WH_NVM_FLAGS_EPHEMERAL, 0,
NULL) != WH_ERROR_BADARGS) {
WH_ERROR_PRINT("ML-DSA cache keygen accepted EPHEMERAL\n");
ret = WH_TEST_FAIL;
}
WH_TEST_PRINT("ML-DSA CACHE-KEY EPHEMERAL REJECT SUCCESS\n");
return 0;
if ((wh_Client_MlDsaMakeCacheKeyAndExportPublic(
ctx, 0, WC_ML_DSA_44, &keyId, WH_NVM_FLAGS_EPHEMERAL, 0, NULL,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_MlDsaMakeCacheKeyAndExportPublic(ctx, 0, WC_ML_DSA_44, NULL,
WH_NVM_FLAGS_NONE, 0, NULL,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_MlDsaMakeCacheKeyAndExportPublic(
ctx, 0, WC_ML_DSA_44, &keyId, WH_NVM_FLAGS_NONE, 0, NULL, NULL) !=
WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("ML-DSA cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
#ifdef WOLFHSM_CFG_DMA
if ((wh_Client_MlDsaMakeCacheKeyDma(ctx, WC_ML_DSA_44, &keyId,
WH_NVM_FLAGS_EPHEMERAL, 0, NULL,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_MlDsaMakeCacheKeyDma(ctx, WC_ML_DSA_44, NULL,
WH_NVM_FLAGS_NONE, 0, NULL,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_MlDsaMakeCacheKeyDma(ctx, WC_ML_DSA_44, &keyId,
WH_NVM_FLAGS_NONE, 0, NULL,
NULL) != WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("ML-DSA DMA cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
#endif /* WOLFHSM_CFG_DMA */
if (!WH_KEYID_ISERASED(keyId)) {
(void)wh_Client_KeyEvict(ctx, keyId);
}
if (ret == 0) {
WH_TEST_PRINT("ML-DSA CACHE-KEY ARGS SUCCESS\n");
}
return ret;
}
#endif /* make/sign/verify && ML_DSA_44 */

Expand Down Expand Up @@ -1391,7 +1421,7 @@ int whTest_Crypto_MlDsa(whClientContext* ctx)
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaCacheKeyAndExportPublic(ctx));
#endif
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaBufferTooSmall(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaMakeCacheKeyEphemeral(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaMakeCacheKeyArgs(ctx));
#ifdef WOLFHSM_CFG_DMA
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaDmaClient(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoMlDsaExportPublicKeyDma(ctx));
Expand Down
32 changes: 32 additions & 0 deletions test-refactor/client-server/wh_test_crypto_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,37 @@ static int _whTest_CryptoRsaCacheKeyAndExportPublic(whClientContext* ctx)
return ret;
}

/* Cache keygen argument checks, including WH_NVM_FLAGS_EPHEMERAL */
static int _whTest_CryptoRsaMakeCacheKeyArgs(whClientContext* ctx)
{
int ret = 0;
whKeyId keyId = WH_KEYID_ERASED;
RsaKey pub[1] = {0};

if ((wh_Client_RsaMakeCacheKeyAndExportPublic(
ctx, RSA_KEY_BITS, RSA_EXPONENT, &keyId, WH_NVM_FLAGS_EPHEMERAL, 0,
NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_RsaMakeCacheKeyAndExportPublic(
NULL, RSA_KEY_BITS, RSA_EXPONENT, &keyId, WH_NVM_FLAGS_NONE, 0,
NULL, pub) != WH_ERROR_BADARGS) ||
(wh_Client_RsaMakeCacheKeyAndExportPublic(
ctx, RSA_KEY_BITS, RSA_EXPONENT, NULL, WH_NVM_FLAGS_NONE, 0, NULL,
pub) != WH_ERROR_BADARGS) ||
(wh_Client_RsaMakeCacheKeyAndExportPublic(
ctx, RSA_KEY_BITS, RSA_EXPONENT, &keyId, WH_NVM_FLAGS_NONE, 0,
NULL, NULL) != WH_ERROR_BADARGS)) {
WH_ERROR_PRINT("RSA cache keygen argument check failed\n");
ret = WH_TEST_FAIL;
}
if (!WH_KEYID_ISERASED(keyId)) {
(void)wh_Client_KeyEvict(ctx, keyId);
}
if (ret == 0) {
WH_TEST_PRINT("RSA CACHE-KEY ARGS SUCCESS\n");
}
return ret;
}

/* Exercises wh_Client_RsaFunction with an undersized output buffer. */
static int _whTest_CryptoRsaBufferTooSmall(whClientContext* ctx)
{
Expand Down Expand Up @@ -499,6 +530,7 @@ int whTest_Crypto_Rsa(whClientContext* ctx)
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoRsa(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoRsaExportPublicKey(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoRsaCacheKeyAndExportPublic(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoRsaMakeCacheKeyArgs(ctx));
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoRsaBufferTooSmall(ctx));
return 0;
}
Expand Down
Loading