From 7101461f35df05e473c71dab7105a5b65f97b94d Mon Sep 17 00:00:00 2001 From: JeremiahM37 Date: Wed, 27 Aug 2025 14:29:18 -0600 Subject: [PATCH 1/2] wolfprov error printing --- include/wolfprovider/wp_logging.h | 7 +++++-- src/wp_aes_aead.c | 28 ++++++++++++++++++++++++++-- src/wp_aes_block.c | 14 ++++++++++++++ src/wp_aes_stream.c | 8 ++++++++ src/wp_aes_wrap.c | 5 +++++ src/wp_cmac.c | 3 +++ src/wp_dec_pem2der.c | 4 ++++ src/wp_des.c | 2 ++ src/wp_dh_exch.c | 2 ++ src/wp_dh_kmgmt.c | 26 ++++++++++++++++++++++++++ src/wp_digests.c | 30 ++++++++++++++++++++++++++++++ src/wp_drbg.c | 5 +++++ src/wp_ecc_kmgmt.c | 24 ++++++++++++++++++++++-- src/wp_ecdh_exch.c | 2 ++ src/wp_ecdsa_sig.c | 7 +++++++ src/wp_ecx_exch.c | 2 ++ src/wp_ecx_kmgmt.c | 30 ++++++++++++++++++++++++++++++ src/wp_ecx_sig.c | 10 ++++++++++ src/wp_gmac.c | 2 ++ src/wp_hkdf.c | 6 ++++++ src/wp_hmac.c | 4 ++++ src/wp_internal.c | 8 ++++++++ src/wp_kbkdf.c | 7 +++++++ src/wp_kdf_kmgmt.c | 2 ++ src/wp_krb5kdf.c | 3 +++ src/wp_logging.c | 13 +++++++++++++ src/wp_mac_kmgmt.c | 2 ++ src/wp_params.c | 2 ++ src/wp_pbkdf2.c | 2 ++ src/wp_rsa_asym.c | 9 +++++++++ src/wp_rsa_kem.c | 8 ++++++++ src/wp_rsa_kmgmt.c | 6 ++++++ src/wp_rsa_sig.c | 23 +++++++++++++++++++++++ src/wp_tls1_prf.c | 2 ++ 34 files changed, 302 insertions(+), 6 deletions(-) diff --git a/include/wolfprovider/wp_logging.h b/include/wolfprovider/wp_logging.h index 0da07c92..51480857 100644 --- a/include/wolfprovider/wp_logging.h +++ b/include/wolfprovider/wp_logging.h @@ -83,7 +83,7 @@ * Define these macros in this header to control logging at compile time: * NOTE: wolfProvider needs to be built with --debug to enable the logging first * before we can set the log level and components. - * + * * WOLFPROV_LOG_LEVEL_FILTER Sets the log level. Use WP_LOG_* constants from enum below. * Examples: * - WP_LOG_ERROR (only errors) @@ -114,6 +114,8 @@ enum wolfProv_LogType { WP_LOG_LEAVE = 0x0004, /* logs function leave */ WP_LOG_INFO = 0x0008, /* logs informative messages */ WP_LOG_VERBOSE = 0x0010, /* logs encrypted/decrypted/digested data */ + /* To see the return code from wolfssl, you must add WP_LOG_DEBUG to the + * WOLFPROV_LOG_LEVEL_FILTER */ WP_LOG_DEBUG = 0x0020, /* logs debug-level detailed information */ WP_LOG_TRACE = 0x0040, /* logs trace-level ultra-detailed information */ @@ -140,7 +142,7 @@ enum wolfProv_LogComponents { WP_LOG_KE = 0x0020, /* key agreement (DH, ECDH) */ WP_LOG_KDF = 0x0040, /* password base key derivation algorithms */ WP_LOG_PROVIDER = 0x0080, /* all provider specific logs */ - + /* Granular algorithm family categories */ WP_LOG_RSA = 0x0001, /* RSA operations */ WP_LOG_ECC = 0x0002, /* ECC operations */ @@ -257,6 +259,7 @@ void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg, void WOLFPROV_MSG(int type, const char* fmt, ...); void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...); void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...); +void WOLFPROV_MSG_DEBUG_RETCODE(int type, const char* func_name, int rc); void WOLFPROV_MSG_TRACE(int type, const char* fmt, ...); void WOLFPROV_ERROR_LINE(int type, int err, const char* file, int line); void WOLFPROV_ERROR_MSG_LINE(int type, const char* msg, const char* file, diff --git a/src/wp_aes_aead.c b/src/wp_aes_aead.c index 2b9627b0..7c9de4b5 100644 --- a/src/wp_aes_aead.c +++ b/src/wp_aes_aead.c @@ -720,7 +720,7 @@ static int wp_aead_get_params(OSSL_PARAM params[], unsigned int md, { int ok = 1; OSSL_PARAM* p; - + WOLFPROV_ENTER(WP_LOG_AES, "wp_aead_get_params"); p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_MODE); @@ -869,6 +869,7 @@ static int wp_aesgcm_get_rand_iv(wp_AeadCtx* ctx, unsigned char* out, rc = wc_AesGcmInit(&ctx->aes, NULL, 0, ctx->iv, (word32)ctx->ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmInit", rc); ok = 0; } #endif @@ -972,6 +973,7 @@ static int wp_aesgcm_tls_iv_set_fixed(wp_AeadCtx* ctx, unsigned char* iv, rc = wc_AesGcmSetIV(&ctx->aes, (word32)ctx->ivLen, iv, (word32)len, wp_provctx_get_rng(ctx->provCtx)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmSetIV", rc); ok = 0; } } @@ -1038,12 +1040,14 @@ static int wp_aesgcm_einit(wp_AeadCtx* ctx, const unsigned char *key, if ((ivLen == 0) && (key != NULL)) { rc = wc_AesGcmSetKey(aes, key, (word32)keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmSetKey", rc); ok = 0; } } else if (key != NULL) { rc = wc_AesGcmEncryptInit(aes, key, (word32)keyLen, iv, (word32)ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncryptInit", rc); ok = 0; } } @@ -1052,6 +1056,7 @@ static int wp_aesgcm_einit(wp_AeadCtx* ctx, const unsigned char *key, if (ok && (key != NULL)) { int rc = wc_AesGcmSetKey(aes, key, (word32)keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmSetKey", rc); ok = 0; } } @@ -1105,7 +1110,9 @@ static int wp_aesgcm_dinit(wp_AeadCtx *ctx, const unsigned char *key, } #ifdef WOLFSSL_AESGCM_STREAM if (ok && key != NULL) { - if (wc_AesGcmDecryptInit(aes, key, (word32)keyLen, iv, (word32)ivLen) != 0) { + int rc = wc_AesGcmDecryptInit(aes, key, (word32)keyLen, iv, (word32)ivLen); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmDecryptInit", rc); ok = 0; } } @@ -1118,6 +1125,7 @@ static int wp_aesgcm_dinit(wp_AeadCtx *ctx, const unsigned char *key, if (ok && (key != NULL)) { int rc = wc_AesGcmSetKey(aes, key, (word32)keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmSetKey", rc); ok = 0; } } @@ -1201,6 +1209,7 @@ static int wp_aesgcm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out, (word32)ctx->ivLen, out + len, EVP_GCM_TLS_TAG_LEN, ctx->buf, EVP_AEAD_TLS1_AAD_LEN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncrypt", rc); ok = 0; } } @@ -1209,6 +1218,7 @@ static int wp_aesgcm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out, (word32)ctx->ivLen, in + len, EVP_GCM_TLS_TAG_LEN, ctx->buf, EVP_AEAD_TLS1_AAD_LEN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmDecrypt", rc); OPENSSL_cleanse(out, len); ok = 0; } @@ -1265,6 +1275,7 @@ static int wp_aesgcm_stream_update(wp_AeadCtx *ctx, unsigned char *out, if (ctx->ivState == IV_STATE_BUFFERED) { rc = wc_AesGcmInit(&ctx->aes, NULL, 0, ctx->iv, (word32)ctx->ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmInit", rc); ok = 0; } @@ -1298,6 +1309,7 @@ static int wp_aesgcm_stream_update(wp_AeadCtx *ctx, unsigned char *out, } } else { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncryptUpdate/wc_AesGcmDecryptUpdate", rc); ok = 0; } @@ -1355,6 +1367,7 @@ static int wp_aesgcm_stream_final(wp_AeadCtx *ctx, unsigned char *out, rc = wc_AesGcmDecryptFinal(aes, ctx->buf, (word32)ctx->tagLen); } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncryptFinal/wc_AesGcmDecryptFinal", rc); ok = 0; } } @@ -1412,6 +1425,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen, if (ok) { rc = wc_AesGcmSetExtIV(&ctx->aes, iv, (word32)ctx->ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmSetExtIV", rc); ok = 0; } @@ -1428,6 +1442,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen, (word32)ctx->inLen, iv, (word32)ctx->ivLen, ctx->buf, (word32)ctx->tagLen, ctx->aad, (word32)ctx->aadLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncrypt_ex", rc); ok = 0; } if (ok) { @@ -1446,6 +1461,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen, ctx->authErr = 1; } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmDecrypt", rc); ok = 0; } } @@ -1459,6 +1475,7 @@ static int wp_aesgcm_encdec(wp_AeadCtx *ctx, unsigned char *out, size_t* outLen, (word32)ctx->inLen, iv, (word32)ctx->ivLen, (byte*)tmpTag, (word32)ctx->tagLen, ctx->aad, (word32)ctx->aadLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesGcmEncrypt_ex", rc); ok = 0; } } @@ -1740,6 +1757,7 @@ static int wp_aesccm_init(wp_AeadCtx* ctx, const unsigned char *key, if (ok && (key != NULL)) { rc = wc_AesCcmSetKey(&ctx->aes, key, (word32)keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmSetKey", rc); ok = 0; } } @@ -1849,6 +1867,7 @@ static int wp_aesccm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out, if (ctx->enc) { rc = wc_AesCcmSetNonce(&ctx->aes, ctx->iv, (word32)ctx->ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmSetNonce", rc); ok = 0; } else { @@ -1856,6 +1875,7 @@ static int wp_aesccm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out, ctx->iv, (word32)ctx->ivLen, out + len, (word32)ctx->tagLen, ctx->buf, (word32)ctx->tlsAadLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmEncrypt_ex", rc); ok = 0; } } @@ -1865,6 +1885,7 @@ static int wp_aesccm_tls_cipher(wp_AeadCtx* ctx, unsigned char* out, (word32)ctx->ivLen, in + len, (word32)ctx->tagLen, ctx->buf, (word32)ctx->tlsAadLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmDecrypt", rc); ok = 0; } } @@ -1907,6 +1928,7 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out, if (!ctx->ivSet) { rc = wc_AesCcmSetNonce(&ctx->aes, ctx->iv, (word32)ctx->ivLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmSetNonce", rc); ok = 0; } } @@ -1917,6 +1939,7 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out, ctx->iv, (word32)ctx->ivLen, ctx->buf, (word32)ctx->tagLen, ctx->aad, (word32)ctx->aadLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmEncrypt_ex", rc); ok = 0; } } @@ -1929,6 +1952,7 @@ static int wp_aesccm_encdec(wp_AeadCtx *ctx, unsigned char *out, ctx->authErr = 1; } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCcmDecrypt", rc); ok = 0; } if (ok) { diff --git a/src/wp_aes_block.c b/src/wp_aes_block.c index cdd32e10..5e5e2a8e 100644 --- a/src/wp_aes_block.c +++ b/src/wp_aes_block.c @@ -267,6 +267,7 @@ static int wp_aes_init_iv(wp_AesBlockCtx *ctx, const unsigned char *iv, XMEMCPY(ctx->oiv, iv, ivLen); rc = wc_AesSetIV(&ctx->aes, iv); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetIV", rc); ok = 0; } } @@ -330,6 +331,7 @@ static int wp_aes_block_init(wp_AesBlockCtx *ctx, const unsigned char *key, int rc = wc_AesSetKey(&ctx->aes, key, (word32)ctx->keyLen, ctx->iv, enc ? AES_ENCRYPTION : AES_DECRYPTION); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetKey", rc); ok = 0; } } @@ -403,9 +405,15 @@ static int wp_aes_block_doit(wp_AesBlockCtx *ctx, unsigned char *out, if (ctx->mode == EVP_CIPH_CBC_MODE) { if (ctx->enc) { rc = wc_AesCbcEncrypt(&ctx->aes, out, in, (word32)inLen); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcEncrypt", rc); + } } else { rc = wc_AesCbcDecrypt(&ctx->aes, out, in, (word32)inLen); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcDecrypt", rc); + } } XMEMCPY(ctx->iv, ctx->aes.reg, ctx->ivLen); } @@ -415,9 +423,15 @@ static int wp_aes_block_doit(wp_AesBlockCtx *ctx, unsigned char *out, if (ctx->mode == EVP_CIPH_ECB_MODE) { if (ctx->enc) { rc = wc_AesEcbEncrypt(&ctx->aes, out, in, (word32)inLen); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesEcbEncrypt", rc); + } } else { rc = wc_AesEcbDecrypt(&ctx->aes, out, in, (word32)inLen); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesEcbDecrypt", rc); + } } } else diff --git a/src/wp_aes_stream.c b/src/wp_aes_stream.c index 26f23c0b..549ba4d7 100644 --- a/src/wp_aes_stream.c +++ b/src/wp_aes_stream.c @@ -322,6 +322,7 @@ static int wp_aes_stream_init(wp_AesStreamCtx *ctx, const unsigned char *key, int rc = wc_AesSetKey(&ctx->aes, key, (word32)ctx->keyLen, iv, dir); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetKey", rc); ok = 0; } } @@ -404,6 +405,7 @@ static int wp_aes_cts_encrypt(wp_AesStreamCtx *ctx, unsigned char *out, XMEMCPY(&ctx->aes.reg, ctx->iv, ctx->ivLen); rc = wc_AesCbcEncrypt(&ctx->aes, out, in, blocks * AES_BLOCK_SIZE); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcEncrypt", rc); ok = 0; } if (ok) { @@ -418,6 +420,7 @@ static int wp_aes_cts_encrypt(wp_AesStreamCtx *ctx, unsigned char *out, rc = wc_AesCbcEncrypt(&ctx->aes, ctsBlock, ctsBlock, AES_BLOCK_SIZE * 2); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcEncrypt", rc); ok = 0; } if (ok) { @@ -460,6 +463,7 @@ static int wp_aes_cts_decrypt(wp_AesStreamCtx *ctx, unsigned char *out, XMEMCPY(&ctx->aes.reg, ctx->iv, ctx->ivLen); rc = wc_AesCbcDecrypt(&ctx->aes, out, in, blocks * AES_BLOCK_SIZE); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcDecrypt", rc); ok = 0; } if (ok) { @@ -474,6 +478,7 @@ static int wp_aes_cts_decrypt(wp_AesStreamCtx *ctx, unsigned char *out, XMEMCPY(&ctx->aes.reg, ctsBlock + AES_BLOCK_SIZE, AES_BLOCK_SIZE); rc = wc_AesCbcDecrypt(&ctx->aes, tmp, ctsBlock, AES_BLOCK_SIZE); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcDecrypt", rc); ok = 0; } } @@ -485,6 +490,7 @@ static int wp_aes_cts_decrypt(wp_AesStreamCtx *ctx, unsigned char *out, rc = wc_AesCbcDecrypt(&ctx->aes, out, ctsBlock + AES_BLOCK_SIZE, AES_BLOCK_SIZE); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcDecrypt", rc); ok = 0; } if (ok) { @@ -525,6 +531,7 @@ static int wp_aes_stream_doit(wp_AesStreamCtx *ctx, unsigned char *out, XMEMCPY(&ctx->aes.reg, ctx->iv, ctx->ivLen); rc = wc_AesCtrEncrypt(&ctx->aes, out, in, (word32)inLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCtrEncrypt", rc); ok = 0; } if (ok) { @@ -544,6 +551,7 @@ static int wp_aes_stream_doit(wp_AesStreamCtx *ctx, unsigned char *out, rc = wc_AesCfbDecrypt(&ctx->aes, out, in, (word32)inLen); } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCfbEncrypt/wc_AesCfbDecrypt", rc); ok = 0; } if (ok) { diff --git a/src/wp_aes_wrap.c b/src/wp_aes_wrap.c index deefdd67..d271f0da 100644 --- a/src/wp_aes_wrap.c +++ b/src/wp_aes_wrap.c @@ -269,6 +269,7 @@ static int wp_aes_wrap_init(wp_AesWrapCtx *ctx, const unsigned char *key, int rc = wc_AesSetKey(&ctx->aes, key, (word32)ctx->keyLen, iv, wrap ? AES_ENCRYPTION : AES_DECRYPTION); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetKey", rc); ok = 0; } #else @@ -365,6 +366,7 @@ static int wp_aes_wrap_update(wp_AesWrapCtx *ctx, unsigned char *out, if (ctx->wrap) { rc = wc_AesKeyWrap_ex(&ctx->aes, in, (word32)inLen, out, outSz, iv); if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesKeyWrap_ex", rc); ok = 0; } } @@ -372,6 +374,7 @@ static int wp_aes_wrap_update(wp_AesWrapCtx *ctx, unsigned char *out, rc = wc_AesKeyUnWrap_ex(&ctx->aes, in, (word32)inLen, out, outSz, iv); if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesKeyUnWrap_ex", rc); ok = 0; } } @@ -380,6 +383,7 @@ static int wp_aes_wrap_update(wp_AesWrapCtx *ctx, unsigned char *out, rc = wc_AesKeyWrap(ctx->key, ctx->keyLen, in, inLen, out, outSz, iv); if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesKeyWrap", rc); ok = 0; } } @@ -387,6 +391,7 @@ static int wp_aes_wrap_update(wp_AesWrapCtx *ctx, unsigned char *out, rc = wc_AesKeyUnWrap(ctx->key, ctx->keyLen, in, inLen, out, outSz, iv); if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesKeyUnWrap", rc); ok = 0; } #endif diff --git a/src/wp_cmac.c b/src/wp_cmac.c index 4d453556..65880b16 100644 --- a/src/wp_cmac.c +++ b/src/wp_cmac.c @@ -134,6 +134,7 @@ static int wp_cmac_set_key(wp_CmacCtx* macCtx, const unsigned char* key, (word32)macCtx->keyLen, macCtx->type, NULL); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitCmac/wc_InitCmac_ex", rc); ok = 0; } } @@ -227,6 +228,7 @@ static int wp_cmac_update(wp_CmacCtx* macCtx, const unsigned char* data, rc = wc_CmacUpdate(&macCtx->cmac, data, (word32)dataLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_CmacUpdate", rc); ok = 0; } @@ -264,6 +266,7 @@ static int wp_cmac_final(wp_CmacCtx* macCtx, unsigned char* out, size_t* outl, outSz = (word32)outSize; rc = wc_CmacFinal(&macCtx->cmac, out, &outSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_CmacFinal", rc); ok = 0; } } diff --git a/src/wp_dec_pem2der.c b/src/wp_dec_pem2der.c index d8788fa9..e73514ff 100644 --- a/src/wp_dec_pem2der.c +++ b/src/wp_dec_pem2der.c @@ -170,6 +170,7 @@ static int wp_pem2der_convert(const char* data, word32 len, DerBuffer** pDer, base64Len = footer - base64Data; rc = wc_AllocDer(pDer, (word32)base64Len, ECC_TYPE, NULL); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AllocDer", rc); ok = 0; } } @@ -177,6 +178,7 @@ static int wp_pem2der_convert(const char* data, word32 len, DerBuffer** pDer, rc = Base64_Decode((byte*)base64Data, (word32)base64Len, (*pDer)->buffer, &(*pDer)->length); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "Base64_Decode", rc); ok = 0; } } @@ -324,6 +326,7 @@ static int wp_pem2der_decode_data(const unsigned char* data, word32 len, /* Decode the PEM to DER using wolfSSL. */ rc = wc_PemToDer(data, len, type, &der, NULL, &info, &algoId); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_PemToDer", rc); ok = 0; } #if LIBWOLFSSL_VERSION_HEX < 0x05000000 @@ -341,6 +344,7 @@ static int wp_pem2der_decode_data(const unsigned char* data, word32 len, if (ok) { rc = wc_AllocDer(&pkcs8Der, pkcs8Sz, DYNAMIC_TYPE_KEY, NULL); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AllocDer", rc); ok = 0; } } diff --git a/src/wp_des.c b/src/wp_des.c index 51e9bb09..994662d0 100644 --- a/src/wp_des.c +++ b/src/wp_des.c @@ -252,6 +252,7 @@ static int wp_des3_init_iv(wp_Des3BlockCtx *ctx, const unsigned char *iv, XMEMCPY(ctx->oiv, iv, ivLen); rc = wc_Des3_SetIV(&ctx->des3, iv); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Des3_SetIV", rc); ok = 0; } } @@ -305,6 +306,7 @@ static int wp_des3_block_init(wp_Des3BlockCtx *ctx, const unsigned char *key, int rc = wc_Des3_SetKey(&ctx->des3, key, iv, enc ? DES_ENCRYPTION : DES_DECRYPTION); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Des3_SetKey", rc); ok = 0; } } diff --git a/src/wp_dh_exch.c b/src/wp_dh_exch.c index da9e1b5b..bac53629 100644 --- a/src/wp_dh_exch.c +++ b/src/wp_dh_exch.c @@ -230,6 +230,7 @@ static int wp_dh_kdf_derive(wp_DhCtx* ctx, unsigned char* key, rc = wc_X963_KDF(ctx->kdfMd, sec, (word32)secLen, ctx->ukm, (word32)ctx->ukmLen, key, (word32)ctx->keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_X963_KDF", rc); ok = 0; } else { @@ -288,6 +289,7 @@ static int wp_dh_derive_secret(wp_DhCtx* ctx, unsigned char* secret, pub, pubSz); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhAgree", rc); ok = 0; } else { diff --git a/src/wp_dh_kmgmt.c b/src/wp_dh_kmgmt.c index e9e32717..bddd913e 100644 --- a/src/wp_dh_kmgmt.c +++ b/src/wp_dh_kmgmt.c @@ -189,11 +189,13 @@ static int wp_dh_map_group_name(wp_Dh* dh, const char* name) params = wp_dh_group_map[i].get(); rc = mp_read_unsigned_bin(&dh->key.p, params->p, params->p_len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } if (ok) { rc = mp_read_unsigned_bin(&dh->key.g, params->g, params->g_len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } } @@ -201,6 +203,7 @@ static int wp_dh_map_group_name(wp_Dh* dh, const char* name) if (ok) { rc = mp_read_unsigned_bin(&dh->key.q, params->q, params->q_len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } } @@ -208,6 +211,7 @@ static int wp_dh_map_group_name(wp_Dh* dh, const char* name) #else rc = wc_DhSetNamedKey(&dh->key, wp_dh_group_map[i].wcName); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhSetNamedKey", rc); ok = 0; } #endif @@ -269,6 +273,7 @@ int wp_dh_up_ref(wp_Dh* dh) rc = wc_LockMutex(&dh->mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } if (ok) { @@ -387,12 +392,14 @@ static wp_Dh* wp_dh_new(WOLFPROV_CTX *provCtx) rc = wc_InitDhKey_ex(&dh->key, NULL, INVALID_DEVID); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitDhKey_ex", rc); ok = 0; } #ifndef SINGLE_THREADED if (ok) { rc = wc_InitMutex(&dh->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); wc_FreeDhKey(&dh->key); ok = 0; } @@ -426,6 +433,9 @@ void wp_dh_free(wp_Dh* dh) int rc; rc = wc_LockMutex(&dh->mutex); + if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); + } cnt = --dh->refCnt; if (rc == 0) { wc_UnLockMutex(&dh->mutex); @@ -465,12 +475,14 @@ static int wp_dh_copy_params(const wp_Dh *src, wp_Dh *dst) /* Copy prime in wolfSSL object. */ rc = mp_copy((mp_int*)&src->key.p, &dst->key.p); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } if (ok) { /* Copy generator in wolfSSL object. */ rc = mp_copy((mp_int*)&src->key.g, &dst->key.g); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } } @@ -478,6 +490,7 @@ static int wp_dh_copy_params(const wp_Dh *src, wp_Dh *dst) /* Copy the small prime in wolfSSL object. */ rc = mp_copy((mp_int*)&src->key.q, &dst->key.q); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } } @@ -965,12 +978,14 @@ static int wp_dh_validate_pub_key_quick(const wp_Dh* dh) if (ok) { rc = mp_to_unsigned_bin((mp_int*)&dh->key.p, prime); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_to_unsigned_bin", rc); ok = 0; } } if (ok) { rc = wc_DhCheckPubValue(prime, primeSz, dh->pub, (word32)dh->pubSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhCheckPubValue", rc); ok = 0; } } @@ -1016,6 +1031,7 @@ static int wp_dh_validate(const wp_Dh* dh, int selection, int checkType) { rc = wc_DhCheckPubKey((DhKey*)&dh->key, dh->pub, (word32)dh->pubSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhCheckPubKey", rc); ok = 0; } } @@ -1023,6 +1039,7 @@ static int wp_dh_validate(const wp_Dh* dh, int selection, int checkType) if (ok && ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)) { rc = wc_DhCheckPrivKey((DhKey*)&dh->key, dh->priv, (word32)dh->privSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhCheckPrivKey", rc); ok = 0; } } @@ -1472,6 +1489,7 @@ static wp_DhGenCtx* wp_dh_gen_init(WOLFPROV_CTX* provCtx, rc = wc_InitRng(&ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); ok = 0; } if (ok) { @@ -1590,6 +1608,7 @@ static int wp_dh_gen_parameters(wp_DhGenCtx *ctx, wp_Dh* dh) rc = wc_DhGenerateParams(&ctx->rng, ctx->bits, &dh->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhGenerateParams", rc); ok = 0; } @@ -1618,17 +1637,20 @@ static int wp_dh_gen_copy_parameters(wp_DhGenCtx *ctx, wp_Dh* dh) rc = mp_copy(&ctx->dh->key.p, &dh->key.p); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } if (ok) { rc = mp_copy(&ctx->dh->key.g, &dh->key.g); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } } if (ok) { rc = mp_copy(&ctx->dh->key.q, &dh->key.q); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } } @@ -1715,6 +1737,7 @@ static int wp_dh_gen_keypair(wp_DhGenCtx *ctx, wp_Dh* dh) dh->pub, &pubSz); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_DhGenerateKeyPair", rc); ok = 0; } } @@ -1746,6 +1769,7 @@ static int wp_dh_params_validate(wp_Dh* dh) rc = mp_init_multi(&t, &one, NULL, NULL, NULL, NULL); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_init_multi", rc); ok = 0; } @@ -1757,6 +1781,7 @@ static int wp_dh_params_validate(wp_Dh* dh) } if (ok && (mp_set(&one, 1) != 0)) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_set", rc); ok = 0; } @@ -1770,6 +1795,7 @@ static int wp_dh_params_validate(wp_Dh* dh) } /* Ensure generator works. */ if (ok && (mp_exptmod(&dh->key.g, &dh->key.q, &dh->key.p, &t) != 0)) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_exptmod", rc); ok = 0; } if (ok && (!mp_isone(&t))) { diff --git a/src/wp_digests.c b/src/wp_digests.c index 43d82117..38e65e94 100644 --- a/src/wp_digests.c +++ b/src/wp_digests.c @@ -130,6 +130,7 @@ static int name##_init(CTX* ctx, const OSSL_PARAM params[]) \ if (ok) { \ int rc = init(ctx, NULL, -1); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #init, rc); \ ok = 0; \ } \ } \ @@ -154,6 +155,7 @@ static int name##_update(void* ctx, const unsigned char* in, size_t inLen) \ WOLFPROV_ENTER(WP_LOG_DIGEST, #name "_update"); \ int rc = upd(ctx, in, (word32)inLen); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #upd, rc); \ ok = 0; \ } \ WOLFPROV_LEAVE(WP_LOG_DIGEST, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);\ @@ -186,6 +188,7 @@ static int name##_final(void* ctx, unsigned char* out, size_t* outLen, \ if (ok) { \ int rc = fin(ctx, out); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #fin, rc); \ ok = 0; \ } \ else { \ @@ -352,8 +355,14 @@ static int wp_InitMd5Sha_ex(wp_Md5Sha* dgst, void* heap, int devId) { int rc; rc = wc_InitMd5_ex(&dgst->md5, heap, devId); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMd5_ex", rc); + } if (rc == 0) { rc = wc_InitSha_ex(&dgst->sha, heap, devId); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitSha_ex", rc); + } } return rc; @@ -373,8 +382,14 @@ static int wp_Md5ShaUpdate(wp_Md5Sha* dgst, const byte* data, word32 len) int rc; rc = wc_Md5Update(&dgst->md5, data, len); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Md5Update", rc); + } if (rc == 0) { rc = wc_ShaUpdate(&dgst->sha, data, len); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ShaUpdate", rc); + } } return rc; @@ -394,8 +409,14 @@ static int wp_Md5ShaFinal(wp_Md5Sha* dgst, byte* hash) int rc; rc = wc_Md5Final(&dgst->md5, hash); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Md5Final", rc); + } if (rc == 0) { rc = wc_ShaFinal(&dgst->sha, hash + WC_MD5_DIGEST_SIZE); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ShaFinal", rc); + } } return rc; @@ -414,8 +435,14 @@ static int wp_Md5ShaCopy(wp_Md5Sha* src, wp_Md5Sha* dst) int rc; rc = wc_Md5Copy(&src->md5, &dst->md5); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Md5Copy", rc); + } if (rc == 0) { rc = wc_ShaCopy(&src->sha, &dst->sha); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ShaCopy", rc); + } } return rc; @@ -577,6 +604,7 @@ static int name##_init(CTX* ctx, const OSSL_PARAM params[]) \ if (ok) { \ int rc = init(&ctx->obj, NULL, -1); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #init, rc); \ ok = 0; \ } \ } \ @@ -613,6 +641,7 @@ static int name##_final(CTX* ctx, unsigned char* out, size_t* outLen, \ if (ok) { \ int rc = fin(&ctx->obj, out, (word32)ctx->outLen); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #fin, rc); \ ok = 0; \ } \ else { \ @@ -658,6 +687,7 @@ static CTX* name##_dupctx(CTX* src) \ int rc; \ rc = copy(&src->obj, &dst->obj); \ if (rc != 0) { \ + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, #copy, rc); \ OPENSSL_free(dst); \ dst = NULL; \ } \ diff --git a/src/wp_drbg.c b/src/wp_drbg.c index 6a7ddc4d..6d17f927 100644 --- a/src/wp_drbg.c +++ b/src/wp_drbg.c @@ -143,6 +143,7 @@ static int wp_drbg_instantiate(wp_DrbgCtx* ctx, unsigned int strength, if (ok) { int rc = wc_InitRng(ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); OPENSSL_clear_free(ctx->rng, sizeof(*ctx->rng)); ok = 0; } @@ -214,6 +215,7 @@ static int wp_drbg_generate(wp_DrbgCtx* ctx, unsigned char* out, if (ok) { rc = wc_RNG_GenerateBlock(ctx->rng, out, (word32)outLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RNG_GenerateBlock", rc); ok = 0; } } @@ -293,6 +295,7 @@ static int wp_drbg_enable_locking(wp_DrbgCtx* ctx) if (ok) { int rc = wc_InitMutex(ctx->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); OPENSSL_free(ctx->mutex); ok = 0; } @@ -323,6 +326,7 @@ static int wp_drbg_lock(wp_DrbgCtx* ctx) if (ctx->mutex != NULL) { rc = wc_LockMutex(ctx->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } } @@ -503,6 +507,7 @@ static size_t wp_drbg_get_seed(wp_DrbgCtx* ctx, unsigned char** pSeed, if (ok) { rc = wc_RNG_GenerateBlock(ctx->rng, buffer, (word32)minLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RNG_GenerateBlock", rc); ok = 0; } } diff --git a/src/wp_ecc_kmgmt.c b/src/wp_ecc_kmgmt.c index c0ee1077..0bf6c5ac 100644 --- a/src/wp_ecc_kmgmt.c +++ b/src/wp_ecc_kmgmt.c @@ -336,6 +336,7 @@ static wp_Ecc* wp_ecc_new(WOLFPROV_CTX *provCtx) rc = wc_ecc_init_ex(&ecc->key, NULL, INVALID_DEVID); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_init_ex", rc); ok = 0; } @@ -343,6 +344,7 @@ static wp_Ecc* wp_ecc_new(WOLFPROV_CTX *provCtx) /* RNG's tied to lifecycle of key in wolfSSL. */ rc = wc_InitRng(&ecc->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); wc_ecc_free(&ecc->key); ok = 0; } @@ -352,6 +354,7 @@ static wp_Ecc* wp_ecc_new(WOLFPROV_CTX *provCtx) if (ok) { rc = wc_InitMutex(&ecc->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); wc_FreeRng(&ecc->rng); wc_ecc_free(&ecc->key); ok = 0; @@ -393,6 +396,9 @@ void wp_ecc_free(wp_Ecc* ecc) int rc; rc = wc_LockMutex(&ecc->mutex); + if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); + } cnt = --ecc->refCnt; if (rc == 0) { wc_UnLockMutex(&ecc->mutex); @@ -436,6 +442,7 @@ static wp_Ecc* wp_ecc_dup(const wp_Ecc *src, int selection) if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { rc = wc_ecc_set_curve(&dst->key, (src->bits + 7) / 8, src->curveId); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_set_curve", rc); ok = 0; } if (ok) { @@ -450,6 +457,7 @@ static wp_Ecc* wp_ecc_dup(const wp_Ecc *src, int selection) rc = wc_ecc_copy_point((ecc_point*)&src->key.pubkey, &dst->key.pubkey); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_copy_point", rc); ok = 0; } } @@ -464,6 +472,7 @@ static wp_Ecc* wp_ecc_dup(const wp_Ecc *src, int selection) rc = mp_copy(&(src->key.k), &(dst->key.k)); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; } } @@ -550,6 +559,7 @@ static int wp_ecc_set_params_enc_pub_key(wp_Ecc *ecc, const OSSL_PARAM params[], int rc = wc_ecc_import_x963_ex(data, (word32)len, &ecc->key, ecc->curveId); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_import_x963_ex", rc); ok = 0; } if (ok) { @@ -737,6 +747,7 @@ static int wp_ecc_get_params_enc_pub_key(wp_Ecc* ecc, OSSL_PARAM params[], rc = wc_ecc_export_x963_ex(&ecc->key, p->data, &outLen, 0); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_export_x963_ex", rc); ok = 0; } } @@ -1041,6 +1052,7 @@ static int wp_ecc_validate(const wp_Ecc* ecc, int selection, int checkType) rc = wc_ecc_check_key((ecc_key*)&ecc->key); ((wp_Ecc*)ecc)->key.type = origType; if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_check_key", rc); ok = 0; } } @@ -1052,6 +1064,7 @@ static int wp_ecc_validate(const wp_Ecc* ecc, int selection, int checkType) if ((ok && (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)) { rc = wc_ecc_check_key((ecc_key*)&ecc->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_check_key", rc); ok = 0; } } @@ -1439,6 +1452,7 @@ static int wp_ecc_export_keypair(wp_Ecc* ecc, OSSL_PARAM* params, int* pIdx, rc = wc_ecc_export_x963_ex(&ecc->key, data + *idx, &outLen, 0); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_export_x963_ex", rc); ok = 0; } if (ok) { @@ -1752,6 +1766,7 @@ static wp_Ecc* wp_ecc_gen(wp_EccGenCtx *ctx, OSSL_CALLBACK *cb, void *cbArg) #endif PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_make_key_ex/wc_ecc_make_key_ex2", rc); ok = 0; } else { @@ -1764,6 +1779,7 @@ static wp_Ecc* wp_ecc_gen(wp_EccGenCtx *ctx, OSSL_CALLBACK *cb, void *cbArg) if (ok && ((ctx->selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)) { rc = wc_ecc_set_curve(&ecc->key, 0, ecc->curveId); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_set_curve", rc); ok = 0; } } @@ -1981,8 +1997,10 @@ static int wp_ecc_get_curve_id_from_oid(unsigned char* oid, int len) /* Get the OID for the OID sum. */ rc = wc_ecc_get_oid(wp_oid_sum_to_curve_id[i].oidSum, &wcOid, &wcOidSz); - if (rc < 0) + if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_get_oid", rc); break; + } /* Compare retrieved OID with one passed in. */ if ((len == (int)wcOidSz) && (XMEMCMP(oid, wcOid, len) == 0)) { @@ -2042,7 +2060,7 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len) if (ok) { rc = wc_ecc_set_curve(&ecc->key, 0, ecc->curveId); if (rc != 0) { - WOLFPROV_MSG(WP_LOG_ECC, "Can't set curve: %d",rc); + WOLFPROV_MSG(WP_LOG_ECC, "Can't set curve: %d", rc); ok = 0; } } @@ -2397,6 +2415,7 @@ static int wp_ecc_encode_pub_size(const wp_Ecc *ecc, size_t* keyLen) rc = wc_ecc_export_x963_ex((ecc_key*)&ecc->key, NULL, &len, 0); PRIVATE_KEY_LOCK(); if (rc != LENGTH_ONLY_E) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_export_x963_ex", rc); ok = 0; } if (ok) { @@ -2430,6 +2449,7 @@ static int wp_ecc_encode_pub(const wp_Ecc *ecc, unsigned char* keyData, rc = wc_ecc_export_x963_ex((ecc_key*)&ecc->key, keyData, &len, 0); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_export_x963_ex", rc); ok = 0; } if (ok) { diff --git a/src/wp_ecdh_exch.c b/src/wp_ecdh_exch.c index 04aa91b5..154a38b8 100644 --- a/src/wp_ecdh_exch.c +++ b/src/wp_ecdh_exch.c @@ -230,6 +230,7 @@ static int wp_ecdh_kdf_derive(wp_EcdhCtx* ctx, unsigned char* key, rc = wc_X963_KDF(ctx->kdfMd, secret, (word32)secLen, ctx->ukm, (word32)ctx->ukmLen, key, (word32)ctx->keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_X963_KDF", rc); ok = 0; } else { @@ -279,6 +280,7 @@ static int wp_ecdh_derive_secret(wp_EcdhCtx* ctx, unsigned char* secret, wp_ecc_get_key(ctx->peer), secret, &len); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_shared_secret", rc); ok = 0; } } diff --git a/src/wp_ecdsa_sig.c b/src/wp_ecdsa_sig.c index fbaa7059..d647abbf 100644 --- a/src/wp_ecdsa_sig.c +++ b/src/wp_ecdsa_sig.c @@ -296,6 +296,7 @@ static int wp_ecdsa_sign(wp_EcdsaSigCtx *ctx, unsigned char *sig, PRIVATE_KEY_LOCK(); wp_unlock(wp_ecc_get_mutex(ctx->ecc)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_sign_hash", rc); ok = 0; } else { @@ -362,9 +363,11 @@ static int wp_ecdsa_verify(wp_EcdsaSigCtx *ctx, const unsigned char *sig, int rc = wc_ecc_verify_hash(sig, (word32)sigLen, tbs, (word32)tbsLen, &res, wp_ecc_get_key(ctx->ecc)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_verify_hash", rc); ok = 0; } if (res == 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "Signature verification", rc); ok = 0; } } @@ -481,6 +484,7 @@ static int wp_ecdsa_setup_md(wp_EcdsaSigCtx *ctx, const char *mdName, rc = wc_HashInit_ex(&ctx->hash, ctx->hashType, NULL, INVALID_DEVID); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashInit_ex", rc); ok = 0; } } @@ -547,6 +551,7 @@ static int wp_ecdsa_digest_signverify_update(wp_EcdsaSigCtx *ctx, #endif data, (word32)dataLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashUpdate", rc); ok = 0; } WOLFPROV_LEAVE(WP_LOG_ECDSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); @@ -615,6 +620,7 @@ static int wp_ecdsa_digest_sign_final(wp_EcdsaSigCtx *ctx, unsigned char *sig, #endif digest); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashFinal", rc); ok = 0; } } @@ -692,6 +698,7 @@ static int wp_ecdsa_digest_verify_final(wp_EcdsaSigCtx *ctx, unsigned char *sig, #endif digest); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashFinal", rc); ok = 0; } } diff --git a/src/wp_ecx_exch.c b/src/wp_ecx_exch.c index 3a109e35..a88b8c7c 100644 --- a/src/wp_ecx_exch.c +++ b/src/wp_ecx_exch.c @@ -242,6 +242,7 @@ static int wp_x25519_derive(wp_EcxCtx* ctx, unsigned char* secret, rc = wc_curve25519_shared_secret(wp_ecx_get_key(ctx->key), wp_ecx_get_key(ctx->peer), secret, &len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_curve25519_shared_secret", rc); ok = 0; } if (ok) { @@ -329,6 +330,7 @@ static int wp_x448_derive(wp_EcxCtx* ctx, unsigned char* secret, rc = wc_curve448_shared_secret(wp_ecx_get_key(ctx->key), wp_ecx_get_key(ctx->peer), secret, &len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_curve448_shared_secret", rc); ok = 0; } if (ok) { diff --git a/src/wp_ecx_kmgmt.c b/src/wp_ecx_kmgmt.c index b3ef6a65..2ffd7249 100644 --- a/src/wp_ecx_kmgmt.c +++ b/src/wp_ecx_kmgmt.c @@ -218,6 +218,7 @@ int wp_ecx_up_ref(wp_Ecx* ecx) rc = wc_LockMutex(&ecx->mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } if (ok) { @@ -278,6 +279,7 @@ static wp_Ecx* wp_ecx_new(WOLFPROV_CTX* provCtx, const wp_EcxData* data) rc = (*data->initKey)((void*)&ecx->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "initKey", rc); ok = 0; } @@ -285,6 +287,7 @@ static wp_Ecx* wp_ecx_new(WOLFPROV_CTX* provCtx, const wp_EcxData* data) if (ok) { rc = wc_InitMutex(&ecx->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); (*data->freeKey)(&ecx->key); ok = 0; } @@ -320,6 +323,9 @@ void wp_ecx_free(wp_Ecx* ecx) int rc; rc = wc_LockMutex(&ecx->mutex); + if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); + } cnt = --ecx->refCnt; if (rc == 0) { wc_UnLockMutex(&ecx->mutex); @@ -428,6 +434,7 @@ static int wp_ecx_set_params(wp_Ecx* ecx, const OSSL_PARAM params[]) int rc = (*ecx->data->importPub)(data, (word32)len, (void*)&ecx->key, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "importPub", rc); ok = 0; } if (ok) { @@ -511,6 +518,7 @@ static int wp_ecx_get_params_enc_pub_key(wp_Ecx* ecx, OSSL_PARAM params[], int rc = (*ecx->data->exportPub)((void*)&ecx->key, p->data, &outLen, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPub", rc); ok = 0; } } @@ -549,6 +557,7 @@ static int wp_ecx_get_params_priv_key(wp_Ecx* ecx, OSSL_PARAM params[]) &outLen); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPriv", rc); ok = 0; } } @@ -668,6 +677,7 @@ static int wp_ecx_match_priv_key(const wp_Ecx* ecx1, const wp_Ecx* ecx2) rc = (*ecx1->data->exportPriv)((void*)&ecx1->key, key1, &len1); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPriv", rc); ok = 0; } } @@ -677,6 +687,7 @@ static int wp_ecx_match_priv_key(const wp_Ecx* ecx1, const wp_Ecx* ecx2) rc = (*ecx2->data->exportPriv)((void*)&ecx2->key, key2, &len2); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPriv", rc); ok = 0; } } @@ -718,6 +729,7 @@ static int wp_ecx_match_pub_key(const wp_Ecx* ecx1, const wp_Ecx* ecx2) rc = (*ecx1->data->exportPub)((void*)&ecx1->key, key1, &len1, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPub", rc); ok = 0; } } @@ -726,6 +738,7 @@ static int wp_ecx_match_pub_key(const wp_Ecx* ecx1, const wp_Ecx* ecx2) rc = (*ecx2->data->exportPub)((void*)&ecx2->key, key2, &len2, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPub", rc); ok = 0; } } @@ -798,6 +811,7 @@ static int wp_ecx_validate_pub_key(const wp_Ecx* ecx) rc = (*ecx->data->exportPub)((void*)&ecx->key, key, &len, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPub", rc); ok = 0; } } @@ -805,6 +819,7 @@ static int wp_ecx_validate_pub_key(const wp_Ecx* ecx) /* Check the public key is valid. */ rc = (*ecx->data->checkPub)(key, len, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "checkPub", rc); ok = 0; } } @@ -878,6 +893,7 @@ static int wp_ecx_ed_validate(const wp_Ecx* ecx, int selection, int checkType) OSSL_KEYMGMT_SELECT_KEYPAIR)) { int rc = (*ecx->data->checkKey)((void*)&ecx->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "checkKey", rc); ok = 0; } } @@ -923,6 +939,7 @@ static int wp_ecx_import(wp_Ecx* ecx, int selection, const OSSL_PARAM params[]) rc = (*ecx->data->importPriv)(privData, (word32)len, (void*)&ecx->key, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "importPriv", rc); ok = 0; } if (ok) { @@ -941,6 +958,7 @@ static int wp_ecx_import(wp_Ecx* ecx, int selection, const OSSL_PARAM params[]) rc = (*ecx->data->importPub)(pubData, (word32)len, (void*)&ecx->key, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "importPub", rc); ok = 0; } if (ok) { @@ -1063,6 +1081,7 @@ static int wp_ecx_export_keypair(wp_Ecx* ecx, OSSL_PARAM* params, int* pIdx, rc = (*ecx->data->exportPub)((void*)&ecx->key, data + *idx, &outLen, ECX_LITTLE_ENDIAN); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPub", rc); ok = 0; } if (ok) { @@ -1074,8 +1093,10 @@ static int wp_ecx_export_keypair(wp_Ecx* ecx, OSSL_PARAM* params, int* pIdx, outLen = ecx->data->len; PRIVATE_KEY_UNLOCK(); rc = (*ecx->data->exportPriv)((void*)&ecx->key, data + *idx, &outLen); + PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "exportPriv", rc); ok = 0; } if (ok) { @@ -1184,6 +1205,7 @@ static wp_EcxGenCtx* wp_ecx_gen_init(WOLFPROV_CTX* provCtx, rc = wc_InitRng(&ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); ok = 0; } if (ok) { @@ -1282,6 +1304,7 @@ static wp_Ecx* wp_ecx_gen(wp_EcxGenCtx* ctx, OSSL_CALLBACK* osslcb, void* cbarg) int rc = (*ctx->data->makeKey)(&ctx->rng, ctx->data->len, (void*)&ecx->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "makeKey", rc); wp_ecx_free(ecx); ecx = NULL; } @@ -2036,6 +2059,7 @@ static int wp_ecx_decode(wp_EcxEncDecCtx* ctx, OSSL_CORE_BIO* cBio, if (ok) { rc = ctx->decode(data, &idx, (void*)&ecx->key, len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "decode", rc); ok = 0; decoded = 0; } @@ -2682,6 +2706,9 @@ static int wp_Ed25519PublicKeyToDer(ed25519_key* key, byte* output, int rc; /* Make the public key to encode. */ rc = wc_ed25519_make_public(key, key->p, ED25519_PUB_KEY_SIZE); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed25519_make_public", rc); + } ok = key->pubKeySet = (rc == 0); } if (ok) { @@ -3329,6 +3356,9 @@ static int wp_Ed448PublicKeyToDer(ed448_key* key, byte* output, word32 inLen) int rc; /* Make the public key to encode. */ rc = wc_ed448_make_public(key, key->p, ED448_PUB_KEY_SIZE); + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed448_make_public", rc); + } ok = key->pubKeySet = (rc == 0); } if (ok) { diff --git a/src/wp_ecx_sig.c b/src/wp_ecx_sig.c index 7e79e2a2..385cb437 100644 --- a/src/wp_ecx_sig.c +++ b/src/wp_ecx_sig.c @@ -388,11 +388,13 @@ static int wp_ed25519_digest_sign(wp_EcxSigCtx *ctx, unsigned char *sig, rc = wc_ed25519_make_public(ed25519, pubKey, sizeof(pubKey)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed25519_make_public", rc); ok = 0; } if (ok) { rc = wc_ed25519_import_public(pubKey, sizeof(pubKey), ed25519); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed25519_import_public", rc); ok = 0; } } @@ -405,6 +407,7 @@ static int wp_ed25519_digest_sign(wp_EcxSigCtx *ctx, unsigned char *sig, rc = wc_ed25519_sign_msg(tbs, (word32)tbsLen, sig, &len, ed25519); wp_unlock(wp_ecx_get_mutex(ctx->ecx)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed25519_sign_msg", rc); ok = 0; } else { @@ -464,9 +467,11 @@ static int wp_ed25519_digest_verify(wp_EcxSigCtx *ctx, unsigned char *sig, int rc = wc_ed25519_verify_msg(sig, (word32)sigLen, tbs, (word32)tbsLen, &res, wp_ecx_get_key(ctx->ecx)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed25519_verify_msg", rc); ok = 0; } if (res == 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "Signature verification", rc); ok = 0; } } @@ -590,11 +595,13 @@ static int wp_ed448_digest_sign(wp_EcxSigCtx *ctx, unsigned char *sig, rc = wc_ed448_make_public(ed448, pubKey, sizeof(pubKey)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed448_make_public", rc); ok = 0; } if (ok) { rc = wc_ed448_import_public(pubKey, sizeof(pubKey), ed448); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed448_import_public", rc); ok = 0; } } @@ -608,6 +615,7 @@ static int wp_ed448_digest_sign(wp_EcxSigCtx *ctx, unsigned char *sig, (ed448_key*)wp_ecx_get_key(ctx->ecx), NULL, 0); wp_unlock(wp_ecx_get_mutex(ctx->ecx)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed448_sign_msg", rc); ok = 0; } else { @@ -672,9 +680,11 @@ static int wp_ed448_digest_verify(wp_EcxSigCtx *ctx, unsigned char *sig, int rc = wc_ed448_verify_msg(sig, (word32)sigLen, tbs, (word32)tbsLen, &res, wp_ecx_get_key(ctx->ecx), NULL, 0); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ed448_verify_msg", rc); ok = 0; } if (res == 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "Signature verification", rc); ok = 0; } } diff --git a/src/wp_gmac.c b/src/wp_gmac.c index 2e1e3c6f..bc3547fb 100644 --- a/src/wp_gmac.c +++ b/src/wp_gmac.c @@ -132,6 +132,7 @@ static int wp_gmac_set_key(wp_GmacCtx* macCtx, const unsigned char *key, int rc = wc_GmacSetKey(&macCtx->gmac, macCtx->key, (word32)macCtx->keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_GmacSetKey", rc); ok = 0; } } @@ -270,6 +271,7 @@ static int wp_gmac_final(wp_GmacCtx* macCtx, unsigned char* out, size_t* outl, rc = wc_GmacUpdate(&macCtx->gmac, macCtx->iv, (word32)macCtx->ivLen, macCtx->data, (word32)macCtx->dataLen, out, (word32)outSize); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_GmacUpdate", rc); ok = 0; } } diff --git a/src/wp_hkdf.c b/src/wp_hkdf.c index 5994ff81..49f57010 100644 --- a/src/wp_hkdf.c +++ b/src/wp_hkdf.c @@ -207,6 +207,7 @@ static int wp_kdf_hkdf_derive(wp_HkdfCtx* ctx, unsigned char* key, (word32)ctx->saltSz, ctx->key, (word32)ctx->keySz, key); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HKDF_Extract", rc); ok = 0; } } @@ -218,6 +219,7 @@ static int wp_kdf_hkdf_derive(wp_HkdfCtx* ctx, unsigned char* key, ctx->info, (word32)ctx->infoSz, key, (word32)keyLen); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HKDF_Expand", rc); ok = 0; } break; @@ -230,6 +232,7 @@ static int wp_kdf_hkdf_derive(wp_HkdfCtx* ctx, unsigned char* key, (word32)keyLen); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HKDF", rc); ok = 0; } break; @@ -568,6 +571,7 @@ static int wp_tls13_hkdf_expand(wp_HkdfCtx* ctx, unsigned char* inKey, (word32)ctx->infoSz, key, (word32)keyLen); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HKDF_Expand", rc); ok = 0; } @@ -621,6 +625,7 @@ static int wp_tls13_hkdf_extract(wp_HkdfCtx* ctx, unsigned char* key, /* Calculate the digest of an empty string. */ rc = wc_Hash(ctx->mdType, zeros, 0, secret, (word32)ctx->mdLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_Hash", rc); ok = 0; } else if (!wp_tls13_hkdf_expand(ctx, ctx->salt, ctx->saltSz, secret, @@ -642,6 +647,7 @@ static int wp_tls13_hkdf_extract(wp_HkdfCtx* ctx, unsigned char* key, } PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HKDF_Extract", rc); ok = 0; } } diff --git a/src/wp_hmac.c b/src/wp_hmac.c index ecc4c018..0a972436 100644 --- a/src/wp_hmac.c +++ b/src/wp_hmac.c @@ -77,6 +77,7 @@ static wp_HmacCtx* wp_hmac_new(WOLFPROV_CTX* provCtx) if (macCtx != NULL) { rc = wc_HmacInit(&macCtx->hmac, NULL, INVALID_DEVID); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacInit", rc); OPENSSL_free(macCtx); macCtx = NULL; } @@ -156,6 +157,7 @@ static int wp_hmac_set_key(wp_HmacCtx* macCtx, const unsigned char* key, int rc = wc_HmacSetKey(&macCtx->hmac, macCtx->type, macCtx->key, (word32)macCtx->keyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacSetKey", rc); ok = 0; } } @@ -250,6 +252,7 @@ static int wp_hmac_update(wp_HmacCtx* macCtx, const unsigned char* data, rc = wc_HmacUpdate(&macCtx->hmac, data, (word32)dataLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacUpdate", rc); ok = 0; } @@ -285,6 +288,7 @@ static int wp_hmac_final(wp_HmacCtx* macCtx, unsigned char* out, size_t* outl, if (ok) { rc = wc_HmacFinal(&macCtx->hmac, out); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacFinal", rc); ok = 0; } } diff --git a/src/wp_internal.c b/src/wp_internal.c index 59885e15..ae391527 100644 --- a/src/wp_internal.c +++ b/src/wp_internal.c @@ -58,6 +58,7 @@ int wp_provctx_lock_rng(WOLFPROV_CTX* provCtx) rc = wc_LockMutex(&provCtx->rng_mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } @@ -100,6 +101,7 @@ int wp_lock(wolfSSL_Mutex *mutex) else { rc = wc_LockMutex(mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } } @@ -137,6 +139,7 @@ int wp_unlock(wolfSSL_Mutex* mutex) else { rc = wc_UnLockMutex(mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_UnLockMutex", rc); ok = 0; } } @@ -490,6 +493,7 @@ int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst, enum wc_HashType hashType) break; } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wp_hash_copy", rc); ok = 0; #if LIBWOLFSSL_VERSION_HEX >= 0x05007004 } else { @@ -761,6 +765,7 @@ int wp_encrypt_key(WOLFPROV_CTX* provCtx, const char* cipherName, rc = wp_EncryptedInfoGet(info, info->name); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "EncryptedInfoGet", rc); ok = 0; } } @@ -776,6 +781,7 @@ int wp_encrypt_key(WOLFPROV_CTX* provCtx, const char* cipherName, wp_provctx_unlock_rng(provCtx); #endif if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RNG_GenerateBlock", rc); ok = 0; } } @@ -792,6 +798,7 @@ int wp_encrypt_key(WOLFPROV_CTX* provCtx, const char* cipherName, (int)passwordSz, WC_MD5); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "BufferKeyEncrypt", rc); ok = 0; } } @@ -812,6 +819,7 @@ int wp_encrypt_key(WOLFPROV_CTX* provCtx, const char* cipherName, rc = Base16_Encode(info->iv, info->ivSz, *cipherInfo + idx, &cipherInfoSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "Base16_Encode", rc); ok = 0; } } diff --git a/src/wp_kbkdf.c b/src/wp_kbkdf.c index 6b6ef977..d99496ef 100644 --- a/src/wp_kbkdf.c +++ b/src/wp_kbkdf.c @@ -399,6 +399,7 @@ static int wp_kbkdf_init_hmac(wp_KbkdfCtx* ctx, unsigned char* key, rc = wc_HmacSetKey(&ctx->hmacCtx, ctx->hashType, localKey, localKeyLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacSetKey", rc); ok = 0; } } @@ -431,6 +432,9 @@ static int wp_kbkdf_init_mac(wp_KbkdfCtx* ctx, unsigned char* key, #else rc = wc_InitCmac_ex(&ctx->cmacCtx, key, (word32)keyLen, WC_CMAC_AES, NULL); #endif + if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitCmac_ex", rc); + } break; #endif default: @@ -490,6 +494,7 @@ static int wp_kbkdf_mac_update(wp_KbkdfCtx* ctx, const unsigned char *data, } if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacUpdate/wc_CmacUpdate", rc); ok = 0; } @@ -534,6 +539,7 @@ static int wp_kbkdf_mac_final(wp_KbkdfCtx* ctx, unsigned char *out, case WP_MAC_TYPE_HMAC: rc = wc_HmacFinal(&ctx->hmacCtx, out); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HmacFinal", rc); ok = 0; } if (ok) { @@ -546,6 +552,7 @@ static int wp_kbkdf_mac_final(wp_KbkdfCtx* ctx, unsigned char *out, outSz = (word32)outSize; rc = wc_CmacFinal(&ctx->cmacCtx, out, &outSz); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_CmacFinal", rc); ok = 0; } if (ok) { diff --git a/src/wp_kdf_kmgmt.c b/src/wp_kdf_kmgmt.c index d51a2c52..d250f493 100644 --- a/src/wp_kdf_kmgmt.c +++ b/src/wp_kdf_kmgmt.c @@ -62,6 +62,7 @@ int wp_kdf_up_ref(wp_Kdf* kdf) rc = wc_LockMutex(&kdf->mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } if (ok) { @@ -98,6 +99,7 @@ static wp_Kdf* wp_kdf_new(WOLFPROV_CTX *provCtx) #ifndef SINGLE_THREADED int rc = wc_InitMutex(&kdf->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); OPENSSL_free(kdf); kdf = NULL; } diff --git a/src/wp_krb5kdf.c b/src/wp_krb5kdf.c index c1d4136f..2603bea4 100644 --- a/src/wp_krb5kdf.c +++ b/src/wp_krb5kdf.c @@ -475,6 +475,7 @@ static int wp_kdf_krb5kdf_derive(wp_Krb5kdfCtx* ctx, unsigned char* key, rc = wc_AesSetKey(&aes, ctx->key, (word32)ctx->keySz, NULL, AES_ENCRYPTION); if (rc != 0) { + WOLFPROV_MSG(WP_LOG_KRB5KDF, "wc_AesSetKey failed with rc=%d", rc); ok = 0; } } @@ -485,6 +486,7 @@ static int wp_kdf_krb5kdf_derive(wp_Krb5kdfCtx* ctx, unsigned char* key, for (osize = 0; ok && osize < keyLen; osize += cipherLen) { rc = wc_AesCbcEncrypt(&aes, cipher, plain, AES_BLOCK_SIZE); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesCbcEncrypt", rc); ok = 0; } @@ -497,6 +499,7 @@ static int wp_kdf_krb5kdf_derive(wp_Krb5kdfCtx* ctx, unsigned char* key, rc = wc_AesSetKey(&aes, ctx->key, (word32)ctx->keySz, NULL, AES_ENCRYPTION); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetKey", rc); ok = 0; } diff --git a/src/wp_logging.c b/src/wp_logging.c index 01648cdf..d60d79ab 100644 --- a/src/wp_logging.c +++ b/src/wp_logging.c @@ -264,6 +264,19 @@ void WOLFPROV_MSG_TRACE(int component, const char* fmt, ...) va_end(vlist); } +/** + * Log function for debug messages with return code, prints to WP_LOG_DEBUG level. + * Unified function to reduce code duplication for common "function failed with rc=%d" pattern. + * + * @param component [IN] Component type, from wolfProv_LogComponents enum. + * @param func_name [IN] Name of the function that failed. + * @param rc [IN] Return code value. + */ +void WOLFPROV_MSG_DEBUG_RETCODE(int component, const char* func_name, int rc) +{ + WOLFPROV_MSG_DEBUG(component, "%s failed with rc=%d", func_name, rc); +} + /** * Log function used to record function entry. * diff --git a/src/wp_mac_kmgmt.c b/src/wp_mac_kmgmt.c index 2dbaf426..2d96dcea 100644 --- a/src/wp_mac_kmgmt.c +++ b/src/wp_mac_kmgmt.c @@ -99,6 +99,7 @@ int wp_mac_up_ref(wp_Mac* mac) rc = wc_LockMutex(&mac->mutex); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_LockMutex", rc); ok = 0; } if (ok) { @@ -192,6 +193,7 @@ static wp_Mac* wp_mac_new(WOLFPROV_CTX *provCtx, int type) #ifndef SINGLE_THREADED int rc = wc_InitMutex(&mac->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); OPENSSL_free(mac); mac = NULL; } diff --git a/src/wp_params.c b/src/wp_params.c index 63511f87..7e293459 100644 --- a/src/wp_params.c +++ b/src/wp_params.c @@ -53,6 +53,7 @@ int wp_mp_read_unsigned_bin_le(mp_int* mp, const unsigned char* data, /* Read big-endian data in. */ rc = mp_read_unsigned_bin(mp, rdata, (word32)len); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } @@ -79,6 +80,7 @@ int wp_mp_to_unsigned_bin_le(mp_int* mp, unsigned char* data, size_t len) rc = mp_to_unsigned_bin(mp, data); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_to_unsigned_bin", rc); ok = 0; } #ifdef LITTLE_ENDIAN_ORDER diff --git a/src/wp_pbkdf2.c b/src/wp_pbkdf2.c index ed7411df..43518838 100644 --- a/src/wp_pbkdf2.c +++ b/src/wp_pbkdf2.c @@ -272,6 +272,7 @@ static int wp_kdf_pbkdf2_derive(wp_Pbkdf2Ctx* ctx, unsigned char* key, NULL, INVALID_DEVID); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_PBKDF2_ex", rc); ok = 0; } } @@ -388,6 +389,7 @@ static int wp_kdf_pkcs12_derive(wp_Pbkdf2Ctx* ctx, unsigned char* key, ctx->mdType, ctx->keyUse, NULL); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_PKCS12_PBKDF_ex", rc); ok = 0; } } diff --git a/src/wp_rsa_asym.c b/src/wp_rsa_asym.c index c44512fd..6ae92ebe 100644 --- a/src/wp_rsa_asym.c +++ b/src/wp_rsa_asym.c @@ -115,6 +115,7 @@ static wp_RsaAsymCtx* wp_rsaa_ctx_new(WOLFPROV_CTX* provCtx) if (ctx != NULL) { int rc = wc_InitRng(&ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); OPENSSL_free(ctx); ctx = NULL; } @@ -310,6 +311,7 @@ static int wp_rsaa_encrypt(wp_RsaAsymCtx* ctx, unsigned char* out, rc = wc_RsaPublicEncrypt(in, (word32)inLen, out, (word32)outSize, wp_rsa_get_key(ctx->rsa), &ctx->rng); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPublicEncrypt", rc); ok = 0; } } @@ -327,6 +329,7 @@ static int wp_rsaa_encrypt(wp_RsaAsymCtx* ctx, unsigned char* out, wp_rsa_get_key(ctx->rsa), &ctx->rng, WC_RSA_OAEP_PAD, ctx->oaepHashType, ctx->mgf, ctx->label, (word32)ctx->labelLen); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPublicEncrypt_ex", rc); ok = 0; } } @@ -335,6 +338,7 @@ static int wp_rsaa_encrypt(wp_RsaAsymCtx* ctx, unsigned char* out, rc = wc_RsaDirect((byte*)in, (word32)inLen, out, &sz, wp_rsa_get_key(ctx->rsa), RSA_PUBLIC_ENCRYPT, &ctx->rng); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); ok = 0; } } @@ -421,6 +425,7 @@ static int wp_rsaa_decrypt(wp_RsaAsymCtx* ctx, unsigned char* out, /* TODO: not thread safe */ rc = wc_RsaSetRNG(wp_rsa_get_key(ctx->rsa), &ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaSetRNG", rc); ok = 0; } if (!ok) { @@ -433,6 +438,7 @@ static int wp_rsaa_decrypt(wp_RsaAsymCtx* ctx, unsigned char* out, wp_rsa_get_key(ctx->rsa)); PRIVATE_KEY_LOCK(); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPrivateDecrypt", rc); ok = 0; } } @@ -447,6 +453,7 @@ static int wp_rsaa_decrypt(wp_RsaAsymCtx* ctx, unsigned char* out, ctx->oaepHashType, ctx->mgf, ctx->label, (word32)ctx->labelLen); PRIVATE_KEY_LOCK(); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPrivateDecrypt_ex", rc); ok = 0; } } @@ -476,6 +483,7 @@ static int wp_rsaa_decrypt(wp_RsaAsymCtx* ctx, unsigned char* out, rc &= (int)(char)mask; if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPrivateDecrypt TLS padding", rc); ok = 0; } } @@ -487,6 +495,7 @@ static int wp_rsaa_decrypt(wp_RsaAsymCtx* ctx, unsigned char* out, wp_rsa_get_key(ctx->rsa), RSA_PRIVATE_DECRYPT, &ctx->rng); PRIVATE_KEY_LOCK(); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect decrypt", rc); ok = 0; } } diff --git a/src/wp_rsa_kem.c b/src/wp_rsa_kem.c index 49827c7a..6c9cc2b3 100644 --- a/src/wp_rsa_kem.c +++ b/src/wp_rsa_kem.c @@ -76,6 +76,7 @@ static wp_RsaKemCtx* wp_rsakem_ctx_new(WOLFPROV_CTX* provCtx) if (ctx != NULL) { int rc = wc_InitRng(&ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); OPENSSL_free(ctx); ctx = NULL; } @@ -231,12 +232,14 @@ static int wp_rsasve_gen_rand_bytes(wp_RsaKemCtx* ctx, unsigned char* out) rc = mp_init_multi(&r, &mod, NULL, NULL, NULL, NULL); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_init_multi", rc); ok = 0; } if (ok) { /* mod = n - 3 */ rc = mp_sub_d(&key->n, 3, &mod); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_sub_d", rc); ok = 0; } } @@ -244,6 +247,7 @@ static int wp_rsasve_gen_rand_bytes(wp_RsaKemCtx* ctx, unsigned char* out) /* r = random number with all words filled. */ rc = wp_mp_rand(&r, mod.used, &ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wp_mp_rand", rc); ok = 0; } /* Done when random is less than modulus. */ @@ -255,6 +259,7 @@ static int wp_rsasve_gen_rand_bytes(wp_RsaKemCtx* ctx, unsigned char* out) /* r in range 0..n-4. Add 2 and r in range 2..n-2. */ rc = mp_add_d(&r, 2, &r); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_add_d", rc); ok = 0; } } @@ -262,6 +267,7 @@ static int wp_rsasve_gen_rand_bytes(wp_RsaKemCtx* ctx, unsigned char* out) /* Encode random number as a zero padded, big-endian array of bytes. */ rc = mp_to_unsigned_bin_len(&r, out, mp_unsigned_bin_size(&key->n)); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_to_unsigned_bin_len", rc); ok = 0; } } @@ -320,6 +326,7 @@ static int wp_rsasve_generate(wp_RsaKemCtx* ctx, unsigned char* out, rc = wc_RsaDirect(secret, nLen, out, &oLen, rsa, RSA_PUBLIC_ENCRYPT, &ctx->rng); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); OPENSSL_cleanse(secret, nLen); ok = 0; } @@ -422,6 +429,7 @@ static int wp_rsasve_recover(wp_RsaKemCtx* ctx, unsigned char* out, RSA_PRIVATE_DECRYPT, &ctx->rng); PRIVATE_KEY_LOCK(); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect decrypt", rc); ok = 0; } /* Front pad output with zeros if required. */ diff --git a/src/wp_rsa_kmgmt.c b/src/wp_rsa_kmgmt.c index 2c9feb13..da65b69d 100644 --- a/src/wp_rsa_kmgmt.c +++ b/src/wp_rsa_kmgmt.c @@ -462,6 +462,7 @@ static wp_Rsa* wp_rsa_base_new(WOLFPROV_CTX* provCtx, int type) rc = wc_InitRsaKey(&rsa->key, NULL); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRsaKey", rc); ok = 0; } @@ -469,6 +470,7 @@ static wp_Rsa* wp_rsa_base_new(WOLFPROV_CTX* provCtx, int type) if (ok) { rc = wc_InitMutex(&rsa->mutex); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitMutex", rc); wc_FreeRsaKey(&rsa->key); ok = 0; } @@ -559,6 +561,7 @@ static wp_Rsa* wp_rsa_dup(const wp_Rsa* src, int selection) rc = mp_copy(src_mp, dst_mp); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_copy", rc); ok = 0; break; } @@ -1092,6 +1095,7 @@ static int wp_rsa_validate(const wp_Rsa* rsa, int selection, int checkType) if (checkPub && checkPriv) { int rc = wc_CheckRsaKey((RsaKey*)&rsa->key); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_CheckRsaKey", rc); ok = 0; } } @@ -1457,6 +1461,7 @@ static wp_RsaGenCtx* wp_rsa_base_gen_init(WOLFPROV_CTX* provCtx, rc = wc_InitRng_ex(&ctx->rng, NULL, INVALID_DEVID); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng_ex", rc); ok = 0; } if (ok) { @@ -1517,6 +1522,7 @@ static wp_Rsa* wp_rsa_gen(wp_RsaGenCtx* ctx, OSSL_CALLBACK* cb, void* cbArg) /* retry */ } else if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_MakeRsaKey", rc); wp_rsa_free(rsa); rsa = NULL; break; diff --git a/src/wp_rsa_sig.c b/src/wp_rsa_sig.c index 0f2156ef..270f1cf4 100644 --- a/src/wp_rsa_sig.c +++ b/src/wp_rsa_sig.c @@ -171,6 +171,7 @@ static int wp_rsa_setup_md(wp_RsaSigCtx* ctx, const char* mdName, rc = wc_HashInit_ex(&ctx->hash, ctx->hashType, NULL, INVALID_DEVID); #endif if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashInit_ex", rc); ok = 0; } } @@ -261,6 +262,7 @@ static wp_RsaSigCtx* wp_rsa_ctx_new(WOLFPROV_CTX* provCtx, if (ok) { rc = wc_InitRng(&ctx->rng); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_InitRng", rc); ok = 0; } } @@ -631,6 +633,7 @@ static int wp_rsa_sign_pkcs1(wp_RsaSigCtx* ctx, unsigned char* sig, PRIVATE_KEY_LOCK(); wp_unlock(wp_rsa_get_mutex(ctx->rsa)); if (rc <= 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaSSL_Sign", rc); ok = 0; } } @@ -692,6 +695,7 @@ static int wp_rsa_sign_pss(wp_RsaSigCtx* ctx, unsigned char* sig, PRIVATE_KEY_LOCK(); wp_unlock(wp_rsa_get_mutex(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPSS_Sign_ex", rc); ok = 0; } else { @@ -791,6 +795,7 @@ static int wp_rsa_sign_no_pad(wp_RsaSigCtx* ctx, unsigned char* sig, PRIVATE_KEY_LOCK(); wp_unlock(wp_rsa_get_mutex(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); ok = 0; } else { @@ -890,6 +895,7 @@ static int wp_rsa_sign_x931(wp_RsaSigCtx* ctx, unsigned char* sig, PRIVATE_KEY_LOCK(); wp_unlock(wp_rsa_get_mutex(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); ok = 0; } else { @@ -906,12 +912,14 @@ static int wp_rsa_sign_x931(wp_RsaSigCtx* ctx, unsigned char* sig, if (ok) { rc = mp_init_multi(&toMp, &nMinusTo, NULL, NULL, NULL, NULL); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_init_multi", rc); ok = 0; } } if (ok) { rc = mp_read_unsigned_bin(&toMp, sig, (word32)*sigLen); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } } @@ -922,11 +930,13 @@ static int wp_rsa_sign_x931(wp_RsaSigCtx* ctx, unsigned char* sig, */ rc = mp_sub(&(wp_rsa_get_key(ctx->rsa)->n), &toMp, &nMinusTo); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_sub", rc); ok = 0; } else if (mp_cmp(&toMp, &nMinusTo) == MP_GT) { rc = mp_to_unsigned_bin_len(&nMinusTo, sig, (int)*sigLen); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_to_unsigned_bin_len", rc); ok = 0; } } @@ -1047,6 +1057,7 @@ static int wp_rsa_verify_pkcs1(wp_RsaSigCtx* ctx, const unsigned char* sig, rc = wc_RsaSSL_Verify(sig, (word32)sigLen, decryptedSig, (word32)sigLen, wp_rsa_get_key(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaSSL_Verify", rc); ok = 0; } @@ -1133,6 +1144,7 @@ static int wp_rsa_verify_pss(wp_RsaSigCtx* ctx, const unsigned char* sig, ctx->mgf, saltLen, wp_rsa_get_key(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPSS_Verify_ex", rc); ok = 0; } } @@ -1145,6 +1157,7 @@ static int wp_rsa_verify_pss(wp_RsaSigCtx* ctx, const unsigned char* sig, #endif saltLen, 0); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaPSS_CheckPadding_ex", rc); ok = 0; } } @@ -1178,6 +1191,7 @@ static int wp_rsa_verify_no_pad(wp_RsaSigCtx* ctx, const unsigned char* sig, rc = wc_RsaDirect((byte*)sig, (word32)sigLen, decryptedSig, &len, wp_rsa_get_key(ctx->rsa), RSA_PUBLIC_DECRYPT, &ctx->rng); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); ok = 0; } if (ok && (((size_t)rc != tbsLen) || ((XMEMCMP(tbs, decryptedSig, @@ -1282,6 +1296,7 @@ static int wp_rsa_verify_x931(wp_RsaSigCtx* ctx, const unsigned char* sig, rc = wc_RsaDirect((byte*)sig, (word32)sigLen, decryptedSig, &len, wp_rsa_get_key(ctx->rsa), RSA_PUBLIC_DECRYPT, &ctx->rng); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaDirect", rc); ok = 0; } if (ok) { @@ -1296,21 +1311,25 @@ static int wp_rsa_verify_x931(wp_RsaSigCtx* ctx, const unsigned char* sig, if ((decryptedSig[sigLen-1] & 0x0F) != 12) { rc = mp_init_multi(&toMp, &nMinusTo, NULL, NULL, NULL, NULL); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_init_multi", rc); ok = 0; } if (ok) { rc = mp_read_unsigned_bin(&toMp, decryptedSig, (int)sigLen); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_read_unsigned_bin", rc); ok = 0; } else { rc = mp_sub(&(wp_rsa_get_key(ctx->rsa)->n), &toMp, &nMinusTo); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_sub", rc); ok = 0; } else { rc = mp_to_unsigned_bin(&nMinusTo, decryptedSig); if (rc != MP_OKAY) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "mp_to_unsigned_bin", rc); ok = 0; } } @@ -1473,6 +1492,7 @@ static int wp_rsa_verify_recover(wp_RsaSigCtx* ctx, unsigned char* rout, rc = wc_RsaSSL_Verify(sig, (word32)sigLen, rout, (word32)routsize, wp_rsa_get_key(ctx->rsa)); if (rc < 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_RsaSSL_Verify", rc); ok = 0; } } @@ -1535,6 +1555,7 @@ static int wp_rsa_digest_signverify_update(wp_RsaSigCtx* ctx, #endif data, (word32)dataLen); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashUpdate", rc); ok = 0; } WOLFPROV_LEAVE(WP_LOG_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); @@ -1603,6 +1624,7 @@ static int wp_rsa_digest_sign_final(wp_RsaSigCtx* ctx, unsigned char* sig, #endif digest); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashFinal", rc); ok = 0; } } @@ -1680,6 +1702,7 @@ static int wp_rsa_digest_verify_final(wp_RsaSigCtx* ctx, unsigned char* sig, #endif digest); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_HashFinal", rc); ok = 0; } } diff --git a/src/wp_tls1_prf.c b/src/wp_tls1_prf.c index 4f35759c..cc4a59f4 100644 --- a/src/wp_tls1_prf.c +++ b/src/wp_tls1_prf.c @@ -176,6 +176,7 @@ static int wp_kdf_tls1_prf_derive(wp_Tls1Prf_Ctx* ctx, unsigned char* key, (word32)(ctx->seedSz), NULL, INVALID_DEVID); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_PRF_TLSv1", rc); ok = 0; } } @@ -189,6 +190,7 @@ static int wp_kdf_tls1_prf_derive(wp_Tls1Prf_Ctx* ctx, unsigned char* key, INVALID_DEVID); PRIVATE_KEY_LOCK(); if (rc != 0) { + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_PRF_TLS", rc); ok = 0; } } From 4b74109c37f5baca727254aad98809320836e202 Mon Sep 17 00:00:00 2001 From: JeremiahM37 Date: Wed, 10 Sep 2025 13:08:31 -0600 Subject: [PATCH 2/2] fix --- include/wolfprovider/wp_logging.h | 1 + src/wp_ecc_kmgmt.c | 2 +- src/wp_krb5kdf.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/wolfprovider/wp_logging.h b/include/wolfprovider/wp_logging.h index 51480857..4c7e09b8 100644 --- a/include/wolfprovider/wp_logging.h +++ b/include/wolfprovider/wp_logging.h @@ -280,6 +280,7 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer, #define WOLFPROV_MSG(t, m, ...) #define WOLFPROV_MSG_VERBOSE(t, m, ...) #define WOLFPROV_MSG_DEBUG(t, m, ...) +#define WOLFPROV_MSG_DEBUG_RETCODE(t, f, r) #define WOLFPROV_MSG_TRACE(t, m, ...) #define WOLFPROV_ERROR(t, e) #define WOLFPROV_ERROR_MSG(t, e) diff --git a/src/wp_ecc_kmgmt.c b/src/wp_ecc_kmgmt.c index 0bf6c5ac..6b076297 100644 --- a/src/wp_ecc_kmgmt.c +++ b/src/wp_ecc_kmgmt.c @@ -2060,7 +2060,7 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len) if (ok) { rc = wc_ecc_set_curve(&ecc->key, 0, ecc->curveId); if (rc != 0) { - WOLFPROV_MSG(WP_LOG_ECC, "Can't set curve: %d", rc); + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_ecc_set_curve", rc); ok = 0; } } diff --git a/src/wp_krb5kdf.c b/src/wp_krb5kdf.c index 2603bea4..0833d6b6 100644 --- a/src/wp_krb5kdf.c +++ b/src/wp_krb5kdf.c @@ -475,7 +475,7 @@ static int wp_kdf_krb5kdf_derive(wp_Krb5kdfCtx* ctx, unsigned char* key, rc = wc_AesSetKey(&aes, ctx->key, (word32)ctx->keySz, NULL, AES_ENCRYPTION); if (rc != 0) { - WOLFPROV_MSG(WP_LOG_KRB5KDF, "wc_AesSetKey failed with rc=%d", rc); + WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_DEBUG, "wc_AesSetKey", rc); ok = 0; } }