Module Name: src Committed By: agc Date: Sat May 8 02:17:16 UTC 2010
Modified Files: src/crypto/external/bsd/netpgp/dist/src/lib: create.c crypto.c packet-parse.c reader.c writer.c Log Message: more uses of hexdump() rather than open-coded equivalents To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 \ src/crypto/external/bsd/netpgp/dist/src/lib/create.c cvs rdiff -u -r1.21 -r1.22 \ src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c \ src/crypto/external/bsd/netpgp/dist/src/lib/writer.c cvs rdiff -u -r1.32 -r1.33 \ src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c cvs rdiff -u -r1.34 -r1.35 \ src/crypto/external/bsd/netpgp/dist/src/lib/reader.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/crypto/external/bsd/netpgp/dist/src/lib/create.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/create.c:1.26 src/crypto/external/bsd/netpgp/dist/src/lib/create.c:1.27 --- src/crypto/external/bsd/netpgp/dist/src/lib/create.c:1.26 Sat May 8 00:33:28 2010 +++ src/crypto/external/bsd/netpgp/dist/src/lib/create.c Sat May 8 02:17:15 2010 @@ -57,7 +57,7 @@ #if defined(__NetBSD__) __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); -__RCSID("$NetBSD: create.c,v 1.26 2010/05/08 00:33:28 agc Exp $"); +__RCSID("$NetBSD: create.c,v 1.27 2010/05/08 02:17:15 agc Exp $"); #endif #include <sys/types.h> @@ -842,8 +842,8 @@ if (__ops_get_debug_level(__FILE__)) { (void) fprintf(stderr,"\nm buf checksum: "); - (void) fprintf(stderr," %2x",cs[0]); - (void) fprintf(stderr," %2x\n",cs[1]); + hexdump(stderr, cs, 2, " "); + (void) fprintf(stderr,"\n"); } return 1; } @@ -925,12 +925,8 @@ (void) memcpy(EM + i, M, mLen); if (__ops_get_debug_level(__FILE__)) { - unsigned i2; - (void) fprintf(stderr, "Encoded Message: \n"); - for (i2 = 0; i2 < mLen; i2++) { - (void) fprintf(stderr, "%2x ", EM[i2]); - } + hexdump(stderr, EM, mLen, " "); (void) fprintf(stderr, "\n"); } return 1; @@ -991,12 +987,8 @@ sizeof(sesskey->key_id)); if (__ops_get_debug_level(__FILE__)) { - unsigned i; - (void) fprintf(stderr, "Encrypting for RSA key id : "); - for (i = 0; i < sizeof(sesskey->key_id); i++) { - (void) fprintf(stderr, "%2x ", key->key_id[i]); - } + hexdump(stderr, key->key_id, sizeof(sesskey->key_id), " "); (void) fprintf(stderr, "\n"); } if (key->key.pubkey.alg != OPS_PKA_RSA) { @@ -1013,14 +1005,10 @@ __ops_random(sesskey->key, CAST_KEY_LENGTH); if (__ops_get_debug_level(__FILE__)) { - unsigned i; - (void) fprintf(stderr, "CAST5 session key created (len=%d):\n ", CAST_KEY_LENGTH); - for (i = 0; i < CAST_KEY_LENGTH; i++) { - (void) fprintf(stderr, "%2x ", sesskey->key[i]); - } + hexdump(stderr, sesskey->key, CAST_KEY_LENGTH, " "); (void) fprintf(stderr, "\n"); } if (create_unencoded_m_buf(sesskey, &unencoded_m_buf[0]) == 0) { @@ -1029,16 +1017,11 @@ return NULL; } if (__ops_get_debug_level(__FILE__)) { - unsigned i; - - printf("unencoded m buf:\n"); - for (i = 0; i < SZ_UNENCODED_M_BUF; i++) { - printf("%2x ", unencoded_m_buf[i]); - } - printf("\n"); + fprintf(stderr, "unencoded m buf:\n"); + hexdump(stderr, unencoded_m_buf, SZ_UNENCODED_M_BUF, " "); + fprintf(stderr, "\n"); } - encode_m_buf(&unencoded_m_buf[0], SZ_UNENCODED_M_BUF, pubkey, - &encoded_m_buf[0]); + encode_m_buf(unencoded_m_buf, SZ_UNENCODED_M_BUF, pubkey, encoded_m_buf); /* and encrypt it */ if (!__ops_rsa_encrypt_mpi(encoded_m_buf, sz_encoded_m_buf, pubkey, Index: src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c:1.21 src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c:1.22 --- src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c:1.21 Fri Mar 5 16:01:09 2010 +++ src/crypto/external/bsd/netpgp/dist/src/lib/crypto.c Sat May 8 02:17:15 2010 @@ -54,7 +54,7 @@ #if defined(__NetBSD__) __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); -__RCSID("$NetBSD: crypto.c,v 1.21 2010/03/05 16:01:09 agc Exp $"); +__RCSID("$NetBSD: crypto.c,v 1.22 2010/05/08 02:17:15 agc Exp $"); #endif #include <sys/types.h> @@ -109,11 +109,8 @@ } if (__ops_get_debug_level(__FILE__)) { - (void) fprintf(stderr, "\nDECRYPTING\n"); - (void) fprintf(stderr, "encrypted data : "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", encmpibuf[i]); - } + (void) fprintf(stderr, "\nDECRYPTING\nencrypted data : "); + hexdump(stderr, encmpibuf, 16, " "); (void) fprintf(stderr, "\n"); } n = __ops_rsa_private_decrypt(mpibuf, encmpibuf, @@ -126,9 +123,7 @@ if (__ops_get_debug_level(__FILE__)) { (void) fprintf(stderr, "decrypted encoded m buf : "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", mpibuf[i]); - } + hexdump(stderr, mpibuf, 16, " "); (void) fprintf(stderr, "\n"); } if (n <= 0) { @@ -136,9 +131,9 @@ } if (__ops_get_debug_level(__FILE__)) { - printf(" decrypted=%d ", n); - hexdump(stdout, mpibuf, (unsigned)n, ""); - printf("\n"); + fprintf(stderr, " decrypted=%d ", n); + hexdump(stderr, mpibuf, (unsigned)n, ""); + fprintf(stderr, "\n"); } /* Decode EME-PKCS1_V1_5 (RFC 2437). */ @@ -163,12 +158,9 @@ } if (__ops_get_debug_level(__FILE__)) { - int j; - - printf("decoded m buf:\n"); - for (j = 0; j < n - i; j++) - printf("%2x ", buf[j]); - printf("\n"); + fprintf(stderr, "decoded m buf:\n"); + hexdump(stderr, buf, n - i, " "); + fprintf(stderr, "\n"); } return n - i; } @@ -205,11 +197,8 @@ skp->rsa.encrypted_m = BN_bin2bn(encmpibuf, n, NULL); if (__ops_get_debug_level(__FILE__)) { - int i; (void) fprintf(stderr, "encrypted mpi buf : "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", encmpibuf[i]); - } + hexdump(stderr, encmpibuf, 16, " "); (void) fprintf(stderr, "\n"); } return 1; Index: src/crypto/external/bsd/netpgp/dist/src/lib/writer.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.21 src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.22 --- src/crypto/external/bsd/netpgp/dist/src/lib/writer.c:1.21 Sat May 8 00:24:47 2010 +++ src/crypto/external/bsd/netpgp/dist/src/lib/writer.c Sat May 8 02:17:16 2010 @@ -58,7 +58,7 @@ #if defined(__NetBSD__) __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); -__RCSID("$NetBSD: writer.c,v 1.21 2010/05/08 00:24:47 agc Exp $"); +__RCSID("$NetBSD: writer.c,v 1.22 2010/05/08 02:17:16 agc Exp $"); #endif #include <sys/types.h> @@ -955,16 +955,10 @@ src + done, size); if (__ops_get_debug_level(__FILE__)) { - int i = 0; - (void) fprintf(stderr, "WRITING:\nunencrypted: "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", src[done + i]); - } + hexdump(stderr, &src[done], 16, " "); (void) fprintf(stderr, "\nencrypted: "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", encbuf[i]); - } + hexdump(stderr, encbuf, 16, " "); (void) fprintf(stderr, "\n"); } if (!stacked_write(writer, encbuf, size, errors)) { Index: src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.32 src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.33 --- src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c:1.32 Sat May 8 00:33:28 2010 +++ src/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c Sat May 8 02:17:15 2010 @@ -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.32 2010/05/08 00:33:28 agc Exp $"); +__RCSID("$NetBSD: packet-parse.c,v 1.33 2010/05/08 02:17:15 agc Exp $"); #endif #ifdef HAVE_OPENSSL_CAST_H @@ -2842,14 +2842,9 @@ return 0; } if (__ops_get_debug_level(__FILE__)) { - int i; - int x = sizeof(pkt.u.pk_sesskey.key_id); - - printf("session key: public key id: x=%d\n", x); - for (i = 0; i < x; i++) { - printf("%2x ", pkt.u.pk_sesskey.key_id[i]); - } - printf("\n"); + fprintf(stderr, "session key: public key id: x=%d\n", sizeof(pkt.u.pk_sesskey.key_id)); + hexdump(stderr, pkt.u.pk_sesskey.key_id, sizeof(pkt.u.pk_sesskey.key_id), " "); + fprintf(stderr, "\n"); } if (!limread(&c, 1, region, stream)) { return 0; @@ -2929,11 +2924,9 @@ (void) memcpy(pkt.u.pk_sesskey.key, unencoded_m_buf + 1, k); if (__ops_get_debug_level(__FILE__)) { - unsigned j; - printf("session key recovered (len=%u):\n", k); - for (j = 0; j < k; j++) - printf("%2x ", pkt.u.pk_sesskey.key[j]); - printf("\n"); + fprintf(stderr, "session key recovered (len=%u):\n", k); + hexdump(stderr, pkt.u.pk_sesskey.key, k, " "); + fprintf(stderr, "\n"); } pkt.u.pk_sesskey.checksum = unencoded_m_buf[k + 1] + (unencoded_m_buf[k + 2] << 8); Index: src/crypto/external/bsd/netpgp/dist/src/lib/reader.c diff -u src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.34 src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.35 --- src/crypto/external/bsd/netpgp/dist/src/lib/reader.c:1.34 Sat May 8 00:33:28 2010 +++ src/crypto/external/bsd/netpgp/dist/src/lib/reader.c Sat May 8 02:17:15 2010 @@ -54,7 +54,7 @@ #if defined(__NetBSD__) __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved."); -__RCSID("$NetBSD: reader.c,v 1.34 2010/05/08 00:33:28 agc Exp $"); +__RCSID("$NetBSD: reader.c,v 1.35 2010/05/08 02:17:15 agc Exp $"); #endif #include <sys/types.h> @@ -1466,19 +1466,10 @@ encrypted->decrypted, buffer, n); if (__ops_get_debug_level(__FILE__)) { - int i; - - (void) fprintf(stderr, - "READING:\nencrypted: "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, - "%2x ", buffer[i]); - } + (void) fprintf(stderr, "READING:\nencrypted: "); + hexdump(stderr, buffer, 16, " "); (void) fprintf(stderr, "\ndecrypted: "); - for (i = 0; i < 16; i++) { - (void) fprintf(stderr, "%2x ", - encrypted->decrypted[i]); - } + hexdump(stderr, encrypted->decrypted, 16, " "); (void) fprintf(stderr, "\n"); } } else {