From 3a9b3d2d93017014032d1bbed3e4193bb423eaae Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Thu, 13 Dec 2018 01:53:13 +0100 Subject: [PATCH] Adapt OPENSSL_DEBUG_PKCS5V2 to the new generic trace API Co-authored-by: Dr. Matthias St. Pierre Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/8198) --- crypto/evp/p5_crpt2.c | 41 ++++++++++++++++------------------------- crypto/trace.c | 1 + include/openssl/trace.h | 3 ++- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/crypto/evp/p5_crpt2.c b/crypto/evp/p5_crpt2.c index 4210e51678..ac5b974e54 100644 --- a/crypto/evp/p5_crpt2.c +++ b/crypto/evp/p5_crpt2.c @@ -14,16 +14,10 @@ #include #include #include +#include #include "internal/evp_int.h" #include "evp_locl.h" -/* set this to print out info about the keygen algorithm */ -/* #define OPENSSL_DEBUG_PKCS5V2 */ - -#ifdef OPENSSL_DEBUG_PKCS5V2 -static void h__dump(const unsigned char *p, int len); -#endif - int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out) @@ -55,15 +49,21 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, EVP_KDF_CTX_free(kctx); -# ifdef OPENSSL_DEBUG_PKCS5V2 - fprintf(stderr, "Password:\n"); - h__dump(pass, passlen); - fprintf(stderr, "Salt:\n"); - h__dump(salt, saltlen); - fprintf(stderr, "Iteration count %d\n", iter); - fprintf(stderr, "Key:\n"); - h__dump(out, keylen); -# endif + OSSL_TRACE_BEGIN(PKCS5V2) { + BIO_printf(trc_out, "Password:\n"); + BIO_hex_string(trc_out, + 0, passlen, pass, passlen); + BIO_printf(trc_out, "\n"); + BIO_printf(trc_out, "Salt:\n"); + BIO_hex_string(trc_out, + 0, saltlen, salt, saltlen); + BIO_printf(trc_out, "\n"); + BIO_printf(trc_out, "Iteration count %d\n", iter); + BIO_printf(trc_out, "Key:\n"); + BIO_hex_string(trc_out, + 0, keylen, out, keylen); + BIO_printf(trc_out, "\n"); + } OSSL_TRACE_END(PKCS5V2); return rv; } @@ -200,12 +200,3 @@ int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, PBKDF2PARAM_free(kdf); return rv; } - -# ifdef OPENSSL_DEBUG_PKCS5V2 -static void h__dump(const unsigned char *p, int len) -{ - for (; len--; p++) - fprintf(stderr, "%02X ", *p); - fprintf(stderr, "\n"); -} -# endif diff --git a/crypto/trace.c b/crypto/trace.c index 8e1db68190..904f3f6b33 100644 --- a/crypto/trace.c +++ b/crypto/trace.c @@ -126,6 +126,7 @@ static const struct trace_category_st trace_categories[] = { TRACE_CATEGORY_(ENGINE_CONF), TRACE_CATEGORY_(ENGINE_TABLE), TRACE_CATEGORY_(ENGINE_REF_COUNT), + TRACE_CATEGORY_(PKCS5V2), }; const char *OSSL_trace_get_category_name(int num) diff --git a/include/openssl/trace.h b/include/openssl/trace.h index 47da0d66a6..f75d75c6db 100644 --- a/include/openssl/trace.h +++ b/include/openssl/trace.h @@ -39,7 +39,8 @@ extern "C" { # define OSSL_TRACE_CATEGORY_ENGINE_CONF 4 # define OSSL_TRACE_CATEGORY_ENGINE_TABLE 5 # define OSSL_TRACE_CATEGORY_ENGINE_REF_COUNT 6 -# define OSSL_TRACE_CATEGORY_NUM 7 +# define OSSL_TRACE_CATEGORY_PKCS5V2 7 +# define OSSL_TRACE_CATEGORY_NUM 8 /* Returns the trace category number for the given |name| */ int OSSL_trace_get_category_num(const char *name); -- 2.25.1