Skip to content
Merged
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
8 changes: 6 additions & 2 deletions include/wolfprovider/wp_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 */

Expand All @@ -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 */
Expand Down Expand Up @@ -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,
Expand All @@ -277,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)
Expand Down
28 changes: 26 additions & 2 deletions src/wp_aes_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -1849,13 +1867,15 @@ 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 {
rc = wc_AesCcmEncrypt_ex(&ctx->aes, out, in, (word32)len,
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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/wp_aes_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/wp_aes_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/wp_aes_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -365,13 +366,15 @@ 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;
}
}
else {
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;
}
}
Expand All @@ -380,13 +383,15 @@ 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;
}
}
else {
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
Expand Down
Loading
Loading