From a143c6d67dd9c864c245c149045845f4a3494d09 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 15 Dec 2015 10:27:54 +0100 Subject: [PATCH] remove the util function dump_hex() in favor of dump_data() --- tool/util.c | 4 ---- tool/util.h | 1 - tool/yubico-piv-tool.c | 20 ++++++++++---------- ykcs11/ykcs11.c | 8 ++++---- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tool/util.c b/tool/util.c index 56a9588..aeb40c2 100644 --- a/tool/util.c +++ b/tool/util.c @@ -218,10 +218,6 @@ void dump_data(const unsigned char *buf, unsigned int len, FILE *output, bool sp } } -void dump_hex(const unsigned char *buf, unsigned int len, FILE *output, bool space) { - dump_data(buf, len, output, space, format_arg_hex); -} - int get_length(const unsigned char *buffer, int *len) { if(buffer[0] < 0x81) { *len = buffer[0]; diff --git a/tool/util.h b/tool/util.h index 8b2b728..e045b07 100644 --- a/tool/util.h +++ b/tool/util.h @@ -40,7 +40,6 @@ size_t read_data(unsigned char*, size_t, FILE*, enum enum_format); void dump_data(unsigned const char*, unsigned int, FILE*, bool, enum enum_format); -void dump_hex(unsigned const char*, unsigned int, FILE*, bool); int set_length(unsigned char*, int); int get_length(const unsigned char*, int*); X509_NAME *parse_name(const char*); diff --git a/tool/yubico-piv-tool.c b/tool/yubico-piv-tool.c index 40b71c3..9ee73ee 100644 --- a/tool/yubico-piv-tool.c +++ b/tool/yubico-piv-tool.c @@ -631,7 +631,7 @@ static bool set_dataobject(ykpiv_state *state, int verbose, int type) { } if(verbose) { fprintf(stderr, "Setting the %s to: ", type == CHUID ? "CHUID" : "CCC"); - dump_hex(obj, len, stderr, true); + dump_data(obj, len, stderr, true, format_arg_hex); } if((res = ykpiv_save_object(state, id, obj, len)) != YKPIV_OK) { fprintf(stderr, "Failed communicating with device: %s\n", ykpiv_strerror(res)); @@ -1157,7 +1157,7 @@ static bool sign_file(ykpiv_state *state, const char *input, const char *output, if(verbosity) { fprintf(stderr, "file hashed as: "); - dump_hex(hashed, hash_len, stderr, true); + dump_data(hashed, hash_len, stderr, true, format_arg_hex); } EVP_MD_CTX_destroy(mdctx); } @@ -1176,7 +1176,7 @@ static bool sign_file(ykpiv_state *state, const char *input, const char *output, if(verbosity) { fprintf(stderr, "file signed as: "); - dump_hex(buf, len, stderr, true); + dump_data(buf, len, stderr, true, format_arg_hex); } fwrite(buf, 1, len, output_file); ret = true; @@ -1276,7 +1276,7 @@ static void print_cert_info(ykpiv_state *state, enum enum_slot slot, const EVP_M fprintf(output, "\n"); X509_digest(x509, md, data, &md_len); fprintf(output, "\tFingerprint:\t"); - dump_hex(data, md_len, output, false); + dump_data(data, md_len, output, false, format_arg_hex); bio = BIO_new_fp(output, BIO_NOCLOSE | BIO_FP_TEXT); not_before = X509_get_notBefore(x509); @@ -1325,7 +1325,7 @@ static bool status(ykpiv_state *state, enum enum_hash hash, if(ykpiv_fetch_object(state, YKPIV_OBJ_CHUID, chuid, &len) != YKPIV_OK) { fprintf(output_file, "No data available\n"); } else { - dump_hex(chuid, len, output_file, false); + dump_data(chuid, len, output_file, false, format_arg_hex); } if (slot == slot__NULL) @@ -1405,7 +1405,7 @@ static bool test_signature(ykpiv_state *state, enum enum_slot slot, EVP_DigestFinal_ex(mdctx, data, &data_len); if(verbose) { fprintf(stderr, "Test data hashes as: "); - dump_hex(data, data_len, stderr, true); + dump_data(data, data_len, stderr, true, format_arg_hex); } } @@ -1561,9 +1561,9 @@ static bool test_decipher(ykpiv_state *state, enum enum_slot slot, if(len == sizeof(secret)) { if(verbose) { fprintf(stderr, "Generated nonce: "); - dump_hex(secret, sizeof(secret), stderr, true); + dump_data(secret, sizeof(secret), stderr, true, format_arg_hex); fprintf(stderr, "Decrypted nonce: "); - dump_hex(secret2, sizeof(secret2), stderr, true); + dump_data(secret2, sizeof(secret2), stderr, true, format_arg_hex); } if(memcmp(secret, secret2, sizeof(secret)) == 0) { fprintf(stderr, "Successfully performed RSA decryption!\n"); @@ -1603,9 +1603,9 @@ static bool test_decipher(ykpiv_state *state, enum enum_slot slot, } if(verbose) { fprintf(stderr, "ECDH host generated: "); - dump_hex(secret, len, stderr, true); + dump_data(secret, len, stderr, true, format_arg_hex); fprintf(stderr, "ECDH card generated: "); - dump_hex(secret2, len, stderr, true); + dump_data(secret2, len, stderr, true, format_arg_hex); } if(memcmp(secret, secret2, key_len) == 0) { fprintf(stderr, "Successfully performed ECDH exchange with card.\n"); diff --git a/ykcs11/ykcs11.c b/ykcs11/ykcs11.c index 23e290d..fa4458e 100644 --- a/ykcs11/ykcs11.c +++ b/ykcs11/ykcs11.c @@ -1840,7 +1840,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Sign)( DBG("Sending %lu bytes to sign", ulDataLen); #if YKCS11_DBG == 1 - dump_hex(pData, ulDataLen, stderr, CK_TRUE); + dump_data(pData, ulDataLen, stderr, CK_TRUE, format_arg_hex); #endif if (is_hashed_mechanism(op_info.mechanism.mechanism) == CK_TRUE) { @@ -1882,7 +1882,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Sign)( DBG("Using key %lx", op_info.op.sign.key_id); DBG("After padding and transformation there are %lu bytes", op_info.buf_len); #if YKCS11_DBG == 1 - dump_hex(op_info.buf, op_info.buf_len, stderr, CK_TRUE); + dump_data(op_info.buf, op_info.buf_len, stderr, CK_TRUE, format_arg_hex); #endif *pulSignatureLen = sizeof(op_info.buf); @@ -1903,7 +1903,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Sign)( DBG("Got %lu bytes back", *pulSignatureLen); #if YKCS11_DBG == 1 - dump_hex(pSignature, *pulSignatureLen, stderr, CK_TRUE); + dump_data(pSignature, *pulSignatureLen, stderr, CK_TRUE, format_arg_hex); #endif if (!is_RSA_mechanism(op_info.mechanism.mechanism)) { @@ -1913,7 +1913,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Sign)( DBG("After removing DER encoding %lu", *pulSignatureLen); #if YKCS11_DBG == 1 - dump_hex(pSignature, *pulSignatureLen, stderr, CK_TRUE); + dump_data(pSignature, *pulSignatureLen, stderr, CK_TRUE, format_arg_hex); #endif }