Adapt OPENSSL_DEBUG_PKCS5V2 to the new generic trace API

Co-authored-by: Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8198)
This commit is contained in:
Richard Levitte 2018-12-13 01:53:13 +01:00
parent f518e3e802
commit 3a9b3d2d93
3 changed files with 19 additions and 26 deletions

View File

@ -14,16 +14,10 @@
#include <openssl/evp.h>
#include <openssl/kdf.h>
#include <openssl/hmac.h>
#include <openssl/trace.h>
#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

View File

@ -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)

View File

@ -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);