Skip to content

Commit

Permalink
Debug logger: Added logging in error, rng, drbg, cipher_segment CAPIs
Browse files Browse the repository at this point in the history
Signed-off-by: Pranoy Jayaraj <[email protected]>
  • Loading branch information
pjayaraj-amd committed Dec 16, 2024
1 parent bce70d4 commit 5f28345
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/capi/c_cipher_segment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ alcp_cipher_segment_request(const alc_cipher_mode_t mode,
const Uint64 keyLen,
alc_cipher_handle_p pCipherHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG, "KeyLen %6ld", keyLen);
#endif
alc_error_t err = ALC_ERROR_NONE;

ALCP_BAD_PTR_ERR_RET(pCipherHandle, err);
Expand Down Expand Up @@ -96,6 +99,9 @@ alcp_cipher_segment_init(const alc_cipher_handle_p pCipherHandle,
const Uint8* pIv,
Uint64 ivLen)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG, "KeyLen %6ld,IVLen %6ld", keyLen, ivLen);
#endif
alc_error_t err = ALC_ERROR_NONE;

ALCP_BAD_PTR_ERR_RET(pCipherHandle, err);
Expand Down Expand Up @@ -125,6 +131,12 @@ alcp_cipher_segment_encrypt_xts(const alc_cipher_handle_p pCipherHandle,
Uint64 currPlainTextLen,
Uint64 startBlockNum)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG,
"CurrentPTLen %6ld,BlkNo %6ld",
currPlainTextLen,
startBlockNum);
#endif
alc_error_t err = ALC_ERROR_NONE;

ALCP_BAD_PTR_ERR_RET(pCipherHandle, err);
Expand All @@ -151,6 +163,12 @@ alcp_cipher_segment_decrypt_xts(const alc_cipher_handle_p pCipherHandle,
Uint64 currCipherTextLen,
Uint64 startBlockNum)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG,
"CurrentPTLen %6ld,BlkNo %6ld",
currPlainTextLen,
startBlockNum);
#endif
alc_error_t err = ALC_ERROR_NONE;

ALCP_BAD_PTR_ERR_RET(pCipherHandle, err);
Expand All @@ -173,6 +191,9 @@ alcp_cipher_segment_decrypt_xts(const alc_cipher_handle_p pCipherHandle,
void
alcp_cipher_segment_finish(const alc_cipher_handle_p pCipherHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
if (pCipherHandle == nullptr || pCipherHandle->ch_context == nullptr)
return;

Expand Down
25 changes: 25 additions & 0 deletions lib/capi/c_drbg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ Uint64
alcp_drbg_context_size(const alc_drbg_info_p pDrbgInfo)
{
Uint64 size = sizeof(Context) + DrbgBuilder::getSize(*pDrbgInfo);
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG, "CtxSize %6ld", size);
#endif
return size;
}

alc_error_t
alcp_drbg_supported(const alc_drbg_info_p pcDrbgInfo)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
alc_error_t err = ALC_ERROR_NONE;
ALCP_BAD_PTR_ERR_RET(pcDrbgInfo, err);
// FIXME: Implement Digest Support check
Expand All @@ -62,6 +68,9 @@ alc_error_t
alcp_drbg_request(alc_drbg_handle_p pDrbgHandle,
const alc_drbg_info_p pDrbgInfo)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
alc_error_t err = ALC_ERROR_NONE;

ALCP_BAD_PTR_ERR_RET(pDrbgHandle, err);
Expand All @@ -81,6 +90,11 @@ alcp_drbg_initialize(alc_drbg_handle_p pDrbgHandle,
Uint8* personalization_string,
Uint64 personalization_string_length)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG,
"personalization_string_length %6ld",
personalization_string_length);
#endif
alc_error_t err = ALC_ERROR_NONE;
ALCP_BAD_PTR_ERR_RET(pDrbgHandle, err);
ALCP_BAD_PTR_ERR_RET(pDrbgHandle->ch_context, err);
Expand All @@ -105,6 +119,14 @@ alcp_drbg_randomize(alc_drbg_handle_p pDrbgHandle,
const Uint8 cAdditionalInput[],
const size_t cAdditionalInputLength)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG,
"OutputLength %6ld, cSecurityStrength %6ld, "
"cAdditionalInputLength %6ld",
cOutputLength,
cSecurityStrength,
cAdditionalInputLength);
#endif
alc_error_t err = ALC_ERROR_NONE;
ALCP_BAD_PTR_ERR_RET(pDrbgHandle, err);
ALCP_BAD_PTR_ERR_RET(pDrbgHandle->ch_context, err);
Expand All @@ -126,6 +148,9 @@ alcp_drbg_randomize(alc_drbg_handle_p pDrbgHandle,
alc_error_t
alcp_drbg_finish(alc_drbg_handle_p pDrbgHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
alc_error_t err = ALC_ERROR_NONE;
ALCP_BAD_PTR_ERR_RET(pDrbgHandle, err);
ALCP_BAD_PTR_ERR_RET(pDrbgHandle->ch_context, err);
Expand Down
3 changes: 3 additions & 0 deletions lib/capi/c_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ using namespace alcp::base;
Uint8
alcp_is_error(alc_error_t err)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
return err != 0;
}

Expand Down
18 changes: 18 additions & 0 deletions lib/capi/c_rng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ alcp_rng_context_size(const alc_rng_info_p pRngInfo)
}

Uint64 size = sizeof(alcp::rng::Context) + RngBuilder::getSize(*pRngInfo);
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG, "CtxSize %6ld", size);
#endif
return size;
}

alc_error_t
alcp_rng_supported(const alc_rng_info_p pRngInfo)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
ALCP_BAD_PTR_ERR_RET(pRngInfo, error);
alc_error_t error = ALC_ERROR_NONE;

Expand Down Expand Up @@ -92,6 +98,9 @@ alcp_rng_supported(const alc_rng_info_p pRngInfo)
alc_error_t
alcp_rng_request(const alc_rng_info_p pRngInfo, alc_rng_handle_p pHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
alc_error_t error = ALC_ERROR_NOT_SUPPORTED;
auto ctx = static_cast<alcp::rng::Context*>(pHandle->rh_context);

Expand Down Expand Up @@ -130,6 +139,9 @@ alcp_rng_gen_random(alc_rng_handle_p pRngHandle,
Uint64 size /* output buffer size */
)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_DBG, "OutputBuff size %6ld", size);
#endif
ALCP_BAD_PTR_ERR_RET(pRngHandle, error);
ALCP_BAD_PTR_ERR_RET(pRngHandle->rh_context, error);

Expand All @@ -150,6 +162,9 @@ alcp_rng_gen_random(alc_rng_handle_p pRngHandle,
alc_error_t
alcp_rng_reseed(alc_rng_handle_p pRngHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
ALCP_BAD_PTR_ERR_RET(pRngHandle, error);
ALCP_BAD_PTR_ERR_RET(pRngHandle->rh_context, error);
alcp::rng::Context* ctx = (alcp::rng::Context*)pRngHandle->rh_context;
Expand All @@ -161,6 +176,9 @@ alcp_rng_reseed(alc_rng_handle_p pRngHandle)
alc_error_t
alcp_rng_finish(alc_rng_handle_p pRngHandle)
{
#ifdef ALCP_ENABLE_DEBUG_LOGGING
ALCP_DEBUG_LOG(LOG_INFO);
#endif
ALCP_BAD_PTR_ERR_RET(pRngHandle, error);
ALCP_BAD_PTR_ERR_RET(pRngHandle->rh_context, error);
alcp::rng::Context* ctx = (alcp::rng::Context*)pRngHandle->rh_context;
Expand Down

0 comments on commit 5f28345

Please sign in to comment.