Skip to content

Add pluggable logging hook to safe-crypto-lib (issue #184, PR A) - #185

Merged
dnovick merged 1 commit into
mainfrom
claude-logging-pr-a
May 21, 2026
Merged

Add pluggable logging hook to safe-crypto-lib (issue #184, PR A)#185
dnovick merged 1 commit into
mainfrom
claude-logging-pr-a

Conversation

@dnovick

@dnovick dnovick commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds safe-crypto-lib/crypto_log.hpp: a zero-dependency, opt-in logging hook
    • CryptoLogLevel enum (Debug/Info/Warn/Error/Off)
    • crypto_set_log_sink(fn, threshold) — register any callable once at startup; passing nullptr disables logging; default state is silent
    • crypto_log_enabled(level) — single relaxed atomic load for fast-path guarding of expensive message construction
    • crypto_log(level, msg) — emit; no-op when below threshold
    • crypto_log_detail::msg(op, k, v...) — helper building "op: k=N bytes" strings without <format>
  • Instruments every public API wrapper across all operation headers with Debug entry/success traces and Error traces forwarding CryptoError::message()_impl functions are completely untouched
  • Covered operations: sha, hmac_generate/verify, aes256_gcm_encrypt/decrypt, chacha20_poly1305_encrypt/decrypt, symmetric_encrypt/decrypt, random_bytes, ecdsa_*, ecdh_*, rsa_oaep_*, rsa_pss_*, hkdf_derive/expand, generate_rsa_key, slh_dsa_*, ml_dsa_*, ml_kem_*
  • Security: key material, IVs, and payload bytes are never included in any log message — only algorithm names and byte-count sizes

Test plan

  • All existing lib tests pass (safe_crypto_lib_test — verified locally, all pass)
  • Verify logging is silent by default (no sink registered = zero allocations on hot path)
  • PRs B (spdlog CLI integration) and C (JSON config) follow

Closes part of #184

🤖 Generated with Claude Code

Introduces crypto_log.hpp: a zero-dependency, opt-in logging hook with
CryptoLogLevel (Debug/Info/Warn/Error/Off), crypto_set_log_sink() for
registration, crypto_log_enabled() for cheap fast-path guards, and
crypto_log() for emission. Default state is no-op; existing callers are
unaffected.

Instruments every public API wrapper (sha, hmac_generate/verify,
aes256_gcm_encrypt/decrypt, chacha20_poly1305_encrypt/decrypt,
symmetric_encrypt/decrypt, random_bytes, ecdsa_*, ecdh_*, rsa_*,
hkdf_derive/expand, generate_rsa_key, slh_dsa_*, ml_dsa_*, ml_kem_*)
with Debug traces at entry and success, and Error traces forwarding
CryptoError::message() on failure. _impl functions are untouched.
Key material, IVs, and payload bytes are never included in log messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dnovick

dnovick commented May 21, 2026

Copy link
Copy Markdown
Owner Author

Reviewed latest head 4519e82. I do not see a code blocker in this logging PR.

What I checked:

  • crypto_log.hpp sink/threshold behavior and callsite coverage across the public wrappers.
  • Debug messages log operation names and sizes/status only; I did not see key material, IV bytes, payload bytes, or shared-secret bytes being emitted.
  • Error logging forwards existing CryptoError::message() strings.

Local verification:

  • Configured PSA_MBEDTLS Debug build in /private/tmp/claude-crypto-pr185-build.
  • Built safe_crypto_lib_test successfully.
  • Ran ctest --test-dir /private/tmp/claude-crypto-pr185-build --output-on-failure -E safe_crypto_cli_test_NOT_BUILT: 495/495 passed.

GitHub CI is almost green: all reported jobs pass except ARM_ASM / Debug, which is still pending. I would wait for that final required check before merging.

@dnovick
dnovick merged commit 9f31956 into main May 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant