Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib more uses of hexdump...



details:   https://anonhg.NetBSD.org/src/rev/220dd2dac8b6
branches:  trunk
changeset: 754663:220dd2dac8b6
user:      agc <agc%NetBSD.org@localhost>
date:      Sat May 08 02:17:15 2010 +0000

description:
more uses of hexdump() rather than open-coded equivalents

diffstat:

 crypto/external/bsd/netpgp/dist/src/lib/create.c       |  37 ++++-------------
 crypto/external/bsd/netpgp/dist/src/lib/crypto.c       |  33 +++++----------
 crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c |  21 +++------
 crypto/external/bsd/netpgp/dist/src/lib/reader.c       |  17 +------
 crypto/external/bsd/netpgp/dist/src/lib/writer.c       |  12 +----
 5 files changed, 35 insertions(+), 85 deletions(-)

diffs (278 lines):

diff -r 35987d2faad9 -r 220dd2dac8b6 crypto/external/bsd/netpgp/dist/src/lib/create.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/create.c  Sat May 08 01:33:00 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/create.c  Sat May 08 02:17:15 2010 +0000
@@ -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,
diff -r 35987d2faad9 -r 220dd2dac8b6 crypto/external/bsd/netpgp/dist/src/lib/crypto.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/crypto.c  Sat May 08 01:33:00 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/crypto.c  Sat May 08 02:17:15 2010 +0000
@@ -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;
diff -r 35987d2faad9 -r 220dd2dac8b6 crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c    Sat May 08 01:33:00 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c    Sat May 08 02:17:15 2010 +0000
@@ -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);
diff -r 35987d2faad9 -r 220dd2dac8b6 crypto/external/bsd/netpgp/dist/src/lib/reader.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/reader.c  Sat May 08 01:33:00 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/reader.c  Sat May 08 02:17:15 2010 +0000
@@ -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 {
diff -r 35987d2faad9 -r 220dd2dac8b6 crypto/external/bsd/netpgp/dist/src/lib/writer.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/writer.c  Sat May 08 01:33:00 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/writer.c  Sat May 08 02:17:15 2010 +0000
@@ -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)) {



Home | Main Index | Thread Index | Old Index