use hexdump() where possible.

get rid of all traces of dmalloc - it's not used anymore. we can now g/c
initialisation functions which do not do anything.

also get rid of the pkeyid() functions, which just prints a
hexadecimal string
This commit is contained in:
agc 2010-05-08 00:33:28 +00:00
parent afcc02d5b5
commit 651dd2889a
9 changed files with 31 additions and 132 deletions

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: create.c,v 1.25 2010/04/14 00:25:10 agc Exp $");
__RCSID("$NetBSD: create.c,v 1.26 2010/05/08 00:33:28 agc Exp $");
#endif
#include <sys/types.h>
@ -425,21 +425,11 @@ write_seckey_body(const __ops_seckey_t *key,
__ops_encrypt_init(&crypted);
if (__ops_get_debug_level(__FILE__)) {
unsigned i2;
(void) fprintf(stderr, "\nWRITING:\niv=");
for (i2 = 0; i2 < __ops_block_size(key->alg); i2++) {
(void) fprintf(stderr, "%02x ", key->iv[i2]);
}
(void) fprintf(stderr, "\n");
(void) fprintf(stderr, "key=");
for (i2 = 0; i2 < CAST_KEY_LENGTH; i2++) {
(void) fprintf(stderr, "%02x ", sesskey[i2]);
}
(void) fprintf(stderr, "\n");
(void) fprintf(stderr, "turning encryption on...\n");
hexdump(stderr, key->iv, __ops_block_size(key->alg), " ");
(void) fprintf(stderr, "\nkey=");
hexdump(stderr, sesskey, CAST_KEY_LENGTH, " ");
(void) fprintf(stderr, "\nturning encryption on...\n");
}
__ops_push_enc_crypt(output, &crypted);

View File

@ -116,7 +116,6 @@ struct _ops_crypt_t {
void *decrypt_key;
};
void __ops_crypto_init(void);
void __ops_crypto_finish(void);
void __ops_hash_md5(__ops_hash_t *);
void __ops_hash_sha1(__ops_hash_t *);

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: keyring.c,v 1.34 2010/04/14 00:23:09 agc Exp $");
__RCSID("$NetBSD: keyring.c,v 1.35 2010/05/08 00:33:28 agc Exp $");
#endif
#ifdef HAVE_FCNTL_H
@ -86,6 +86,7 @@ __RCSID("$NetBSD: keyring.c,v 1.34 2010/04/14 00:23:09 agc Exp $");
#include "packet.h"
#include "crypto.h"
#include "validate.h"
#include "netpgpdefs.h"
#include "netpgpdigest.h"
@ -801,17 +802,6 @@ __ops_keyring_free(__ops_keyring_t *keyring)
keyring->keyc = keyring->keyvsize = 0;
}
/* simple function to print out a binary keyid */
void
__ops_pkeyid(FILE *fp, const uint8_t *keyid, size_t size)
{
size_t i;
for (i = 0 ; i < size ; i++) {
(void) fprintf(fp, "%02x", keyid[i]);
}
}
/**
\ingroup HighLevel_KeyringFind
@ -834,10 +824,9 @@ __ops_getkeybyid(__ops_io_t *io, const __ops_keyring_t *keyring,
if (__ops_get_debug_level(__FILE__)) {
(void) fprintf(io->errs,
"__ops_getkeybyid: keyring keyid ");
__ops_pkeyid(io->errs, keyring->keys[*from].key_id,
OPS_KEY_ID_SIZE);
hexdump(io->errs, keyring->keys[*from].key_id, OPS_KEY_ID_SIZE, "");
(void) fprintf(io->errs, ", keyid ");
__ops_pkeyid(io->errs, keyid, OPS_KEY_ID_SIZE);
hexdump(io->errs, keyid, OPS_KEY_ID_SIZE, "");
(void) fprintf(io->errs, "\n");
}
if (memcmp(keyring->keys[*from].key_id, keyid,
@ -915,10 +904,7 @@ getkeybyname(__ops_io_t *io,
(void) memset(keyid, 0x0, sizeof(keyid));
str2keyid(name, keyid, sizeof(keyid));
if (__ops_get_debug_level(__FILE__)) {
(void) fprintf(io->outs,
"name \"%s\", keyid %02x%02x%02x%02x\n",
name,
keyid[0], keyid[1], keyid[2], keyid[3]);
hexdump(io->outs, keyid, 4, "");
}
savedstart = *from;
if ((kp = __ops_getkeybyid(io, keyring, keyid, from)) != NULL) {

View File

@ -114,8 +114,6 @@ void __ops_keydata_init(__ops_key_t *, const __ops_content_tag_t);
int __ops_parse_and_accumulate(__ops_keyring_t *, __ops_stream_t *);
void __ops_pkeyid(FILE *, const uint8_t *, size_t);
int __ops_sprint_keydata(__ops_io_t *, const __ops_keyring_t *,
const __ops_key_t *, char **, const char *,
const __ops_pubkey_t *, const int);

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: misc.c,v 1.28 2010/04/02 15:28:16 christos Exp $");
__RCSID("$NetBSD: misc.c,v 1.29 2010/05/08 00:33:28 agc Exp $");
#endif
#include <sys/types.h>
@ -698,16 +698,10 @@ __ops_calc_mdc_hash(const uint8_t *preamble,
uint8_t c;
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
(void) fprintf(stderr, "__ops_calc_mdc_hash():\n");
(void) fprintf(stderr, "\npreamble: ");
for (i = 0; i < sz_preamble; i++)
(void) fprintf(stderr, " 0x%02x", preamble[i]);
(void) fprintf(stderr, "\n");
(void) fprintf(stderr, "__ops_calc_mdc_hash():\npreamble: ");
hexdump(stderr, preamble, sz_preamble, " ");
(void) fprintf(stderr, "\nplaintext (len=%u): ", sz_plaintext);
for (i = 0; i < sz_plaintext; i++)
(void) fprintf(stderr, " 0x%02x", plaintext[i]);
hexdump(stderr, plaintext, sz_plaintext, " ");
(void) fprintf(stderr, "\n");
}
/* init */
@ -733,13 +727,8 @@ __ops_calc_mdc_hash(const uint8_t *preamble,
hash.finish(&hash, hashed);
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
(void) fprintf(stderr, "\nhashed (len=%d): ",
OPS_SHA1_HASH_SIZE);
for (i = 0; i < OPS_SHA1_HASH_SIZE; i++) {
(void) fprintf(stderr, " 0x%02x", hashed[i]);
}
(void) fprintf(stderr, "\nhashed (len=%d): ", OPS_SHA1_HASH_SIZE);
hexdump(stderr, hashed, OPS_SHA1_HASH_SIZE, " ");
(void) fprintf(stderr, "\n");
}
}
@ -1063,26 +1052,12 @@ hexdump(FILE *fp, const uint8_t *src, size_t length, const char *sep)
}
}
/**
* \ingroup HighLevel_Functions
* \brief Initialises OpenPGP::SDK. To be called before any other OPS function.
*
* Initialises OpenPGP::SDK and the underlying openssl library.
*/
void
__ops_init(void)
{
__ops_crypto_init();
}
/**
* \ingroup HighLevel_Functions
* \brief Closes down OpenPGP::SDK.
*
* Close down OpenPGP:SDK, release any resources under the control of
* the library. No OpenPGP:SDK function other than __ops_init() should
* be called after this function.
* the library.
*/
void

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: openssl_crypto.c,v 1.21 2010/04/14 00:21:40 agc Exp $");
__RCSID("$NetBSD: openssl_crypto.c,v 1.22 2010/05/08 00:33:28 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_DSA_H
@ -538,18 +538,12 @@ __ops_dsa_verify(const uint8_t *hash, size_t hash_length,
odsa->pub_key = dsa->y;
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
(void) fprintf(stderr, "hash passed in:\n");
for (i = 0; i < hash_length; i++) {
(void) fprintf(stderr, "%02x ", hash[i]);
}
(void) fprintf(stderr, "\n");
printf("hash_length=%" PRIsize "d\n", hash_length);
printf("Q=%d\n", BN_num_bytes(odsa->q));
hexdump(stderr, hash, hash_length, " ");
(void) fprintf(stderr, "\nhash_length=%" PRIsize "d\n", hash_length);
(void) fprintf(stderr, "Q=%d\n", BN_num_bytes(odsa->q));
}
/* XXX - Flexelint - Info 732: Loss of sign (assignment) (int to unsigned) */
if ((qlen = BN_num_bytes(odsa->q)) < hash_length) {
if ((qlen = (unsigned)BN_num_bytes(odsa->q)) < hash_length) {
hash_length = qlen;
}
ret = DSA_do_verify(hash, (int)hash_length, osig, odsa);
@ -621,7 +615,7 @@ __ops_rsa_private_encrypt(uint8_t *out,
int n;
orsa = RSA_new();
orsa->n = BN_dup(pubkey->n); /* XXX: do we need n? */
orsa->n = BN_dup(pubkey->n);
orsa->d = seckey->d;
orsa->p = seckey->q;
orsa->q = seckey->p;
@ -743,22 +737,6 @@ __ops_rsa_public_encrypt(uint8_t *out,
return n;
}
/**
\ingroup Core_Crypto
\brief initialises openssl
\note Would usually call __ops_init() instead
\sa __ops_init()
*/
void
__ops_crypto_init(void)
{
#ifdef DMALLOC
CRYPTO_malloc_debug_init();
CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
#endif
}
/**
\ingroup Core_Crypto
\brief Finalise openssl
@ -770,9 +748,6 @@ __ops_crypto_finish(void)
{
CRYPTO_cleanup_all_ex_data();
ERR_remove_state((unsigned long)0);
#ifdef DMALLOC
CRYPTO_mem_leaks_fp(stderr);
#endif
}
/**

View File

@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: packet-parse.c,v 1.31 2010/03/08 07:37:24 agc Exp $");
__RCSID("$NetBSD: packet-parse.c,v 1.32 2010/05/08 00:33:28 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_CAST_H
@ -2669,18 +2669,10 @@ parse_seckey(__ops_region_t *region, __ops_stream_t *stream)
__ops_crypt_any(&decrypt, pkt.u.seckey.alg);
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
fprintf(stderr, "\nREADING:\niv=");
for (i = 0;
i < __ops_block_size(pkt.u.seckey.alg);
i++) {
fprintf(stderr, "%02x ", pkt.u.seckey.iv[i]);
}
hexdump(stderr, pkt.u.seckey.iv, __ops_block_size(pkt.u.seckey.alg), " ");
fprintf(stderr, "\nkey=");
for (i = 0; i < CAST_KEY_LENGTH; i++) {
fprintf(stderr, "%02x ", key[i]);
}
hexdump(stderr, key, CAST_KEY_LENGTH, " ");
fprintf(stderr, "\n");
}
decrypt.set_iv(&decrypt, pkt.u.seckey.iv);

View File

@ -1046,7 +1046,6 @@ typedef struct {
unsigned length;
} __ops_fingerprint_t;
void __ops_init(void);
void __ops_finish(void);
void __ops_keyid(uint8_t *, const size_t, const __ops_pubkey_t *);
void __ops_fingerprint(__ops_fingerprint_t *, const __ops_pubkey_t *);

View File

@ -54,7 +54,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: reader.c,v 1.33 2010/04/14 00:19:52 agc Exp $");
__RCSID("$NetBSD: reader.c,v 1.34 2010/05/08 00:33:28 agc Exp $");
#endif
#include <sys/types.h>
@ -1611,25 +1611,16 @@ se_ip_data_reader(void *dest_,
return -1;
}
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
fprintf(stderr, "\n\nentire SE IP packet (len=%d):\n",
decrypted_region.length);
for (i = 0; i < decrypted_region.length; i++) {
fprintf(stderr, "0x%02x ", buf[i]);
if (!((i + 1) % 8))
fprintf(stderr, "\n");
}
hexdump(stderr, buf, decrypted_region.length, " ");
fprintf(stderr, "\n\n");
}
/* verify leading preamble */
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
fprintf(stderr, "\npreamble: ");
for (i = 0; i < se_ip->decrypt->blocksize + 2; i++)
fprintf(stderr, " 0x%02x", buf[i]);
hexdump(stderr, buf, se_ip->decrypt->blocksize , " ");
fprintf(stderr, "\n");
}
b = se_ip->decrypt->blocksize;
@ -1655,17 +1646,11 @@ se_ip_data_reader(void *dest_,
mdc_hash = mdc + 2;
if (__ops_get_debug_level(__FILE__)) {
unsigned i;
fprintf(stderr, "\nplaintext (len=%" PRIsize "u): ",
sz_plaintext);
for (i = 0; i < sz_plaintext; i++)
fprintf(stderr, " 0x%02x", plaintext[i]);
fprintf(stderr, "\n");
hexdump(stderr, plaintext, sz_plaintext, " ");
fprintf(stderr, "\nmdc (len=%" PRIsize "u): ", sz_mdc);
for (i = 0; i < sz_mdc; i++)
fprintf(stderr, " 0x%02x", mdc[i]);
hexdump(stderr, mdc, sz_mdc, " ");
fprintf(stderr, "\n");
}
__ops_calc_mdc_hash(preamble, sz_preamble, plaintext,