Source-Changes-HG archive

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

[src/netbsd-3]: src/usr.bin/cksum Apply patch (requested by elad in ticket #7...



details:   https://anonhg.NetBSD.org/src/rev/5e540555e006
branches:  netbsd-3
changeset: 577148:5e540555e006
user:      tron <tron%NetBSD.org@localhost>
date:      Mon Sep 12 12:17:35 2005 +0000

description:
Apply patch (requested by elad in ticket #754):
- Deprecate -1, -2, -4, -5, -6, -m flags.
- Add -a <algorithm> flag.
- Support SHA2 hashing.
cksum(1) now supports ``sha256'', ``sha384'', and ``sha512''.

diffstat:

 usr.bin/cksum/Makefile |   3 +-
 usr.bin/cksum/cksum.1  |  61 ++++++++++++++++++++++++++++++++++++++-----------
 usr.bin/cksum/cksum.c  |  59 +++++++++++++++++++++++++++++++++++++++++++----
 usr.bin/cksum/extern.h |  17 +++++++++++++-
 usr.bin/cksum/md5.c    |  14 +++++-----
 usr.bin/cksum/sha256.c |  25 ++++++++++++++++++++
 usr.bin/cksum/sha384.c |  25 ++++++++++++++++++++
 usr.bin/cksum/sha512.c |  25 ++++++++++++++++++++
 8 files changed, 200 insertions(+), 29 deletions(-)

diffs (truncated from 387 to 300 lines):

diff -r 13d9dd0e9f6f -r 5e540555e006 usr.bin/cksum/Makefile
--- a/usr.bin/cksum/Makefile    Sun Sep 11 22:14:04 2005 +0000
+++ b/usr.bin/cksum/Makefile    Mon Sep 12 12:17:35 2005 +0000
@@ -1,9 +1,10 @@
-#      $NetBSD: Makefile,v 1.13 2005/01/12 16:42:45 xtraeme Exp $
+#      $NetBSD: Makefile,v 1.13.2.1 2005/09/12 12:17:35 tron Exp $
 #      @(#)Makefile    8.2 (Berkeley) 4/28/95
 
 WARNS= 3
 PROG=  cksum
 SRCS=  cksum.c crc.c md2.c md4.c md5.c sha1.c rmd160.c print.c sum1.c sum2.c
+SRCS+= sha256.c sha384.c sha512.c
 LINKS= ${BINDIR}/cksum ${BINDIR}/sum
 LINKS+=        ${BINDIR}/cksum ${BINDIR}/md2
 LINKS+=        ${BINDIR}/cksum ${BINDIR}/md4
diff -r 13d9dd0e9f6f -r 5e540555e006 usr.bin/cksum/cksum.1
--- a/usr.bin/cksum/cksum.1     Sun Sep 11 22:14:04 2005 +0000
+++ b/usr.bin/cksum/cksum.1     Mon Sep 12 12:17:35 2005 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: cksum.1,v 1.25 2004/07/09 11:47:59 wiz Exp $
+.\"    $NetBSD: cksum.1,v 1.25.2.1 2005/09/12 12:17:35 tron Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\"    @(#)cksum.1     8.2 (Berkeley) 4/28/95
 .\"
-.Dd July 9, 2004
+.Dd August 24, 2005
 .Dt CKSUM 1
 .Os
 .Sh NAME
@@ -48,12 +48,7 @@
 .Nm
 .Op Fl n
 .Oo
-.Fl m |
-.Fl 1 |
-.Fl 2 |
-.Fl 4 |
-.Fl 5 |
-.Fl 6 |
+.Fl a Ar algorithm |
 .Op Fl o Ar 1 | Ar 2
 .Oc
 .Op Ar
@@ -160,15 +155,53 @@
 The options are as follows:
 .Bl -tag -width indent
 .It Fl 1
-Use the SHA1 algorithm rather than the default one.
+Use the SHA1 algorithm.
+.Em This flag is deprecated and should not be used as it will be removed
+.Em in the future.
+.Em Please use the
+.Fl a
+.Em flag.
 .It Fl 2
-Use the MD2 algorithm rather than the default one.
+Use the MD2 algorithm.
+.Em This flag is deprecated and should not be used as it will be removed
+.Em in the future.
+.Em Please use the
+.Fl a
+.Em flag.
 .It Fl 4
-Use the MD4 algorithm rather than the default one.
-.It Fl m | 5
-Use the MD5 algorithm rather than the default one.
+Use the MD4 algorithm.
+.Em This flag is deprecated and should not be used as it will be removed
+.Em in the future.
+.Em Please use the
+.Fl a
+.Em flag.
+.It Fl 5 , Fl m
+Use the MD5 algorithm.
+.Em This flag is deprecated and should not be used as it will be removed
+.Em in the future.
+.Em Please use the
+.Fl a
+.Em flag.
 .It Fl 6
-Use the RMD160 algorithm rather than the default one.
+Use the RMD160 algorithm.
+.Em This flag is deprecated and should not be used as it will be removed
+.Em in the future.
+.Em Please use the
+.Fl a
+.Em flag.
+.It Fl a Ar algorithm
+When invoked as
+.Nm cksum ,
+use the specified
+.Pa algorithm .
+Valid algorithms are MD2, MD4, MD5, SHA1, RMD160, SHA256, SHA384, SHA512,
+CRC, old1, and old2.
+Old1 and old2 are equal to
+.Fl o Ar 1
+and
+.Fl o Ar 2 ,
+respectively.
+The default is CRC.
 .It Fl o
 Use historic algorithms instead of the (superior) default one.
 .Pp
diff -r 13d9dd0e9f6f -r 5e540555e006 usr.bin/cksum/cksum.c
--- a/usr.bin/cksum/cksum.c     Sun Sep 11 22:14:04 2005 +0000
+++ b/usr.bin/cksum/cksum.c     Mon Sep 12 12:17:35 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cksum.c,v 1.24 2005/02/05 00:13:34 simonb Exp $        */
+/*     $NetBSD: cksum.c,v 1.24.2.1 2005/09/12 12:17:35 tron Exp $      */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)cksum.c    8.2 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: cksum.c,v 1.24 2005/02/05 00:13:34 simonb Exp $");
+__RCSID("$NetBSD: cksum.c,v 1.24.2.1 2005/09/12 12:17:35 tron Exp $");
 #endif /* not lint */
 
 #include <sys/cdefs.h>
@@ -95,6 +95,7 @@
 #include <md4.h>
 #include <md2.h>
 #include <sha1.h>
+#include <crypto/sha2.h>
 #include <rmd160.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -135,6 +136,15 @@
        { "rmd160", "RMD160",
          RMD160String, RMD160TimeTrial, RMD160TestSuite,
          RMD160Filter, (_filefunc) RMD160File },
+       { "sha256", "SHA256",
+         SHA256_String, SHA256_TimeTrial, SHA256_TestSuite,
+         SHA256_Filter, (_filefunc) SHA256_File },
+       { "sha384", "SHA384",
+         SHA384_String, SHA384_TimeTrial, SHA384_TestSuite,
+         SHA384_Filter, (_filefunc) SHA384_File },
+       { "sha512", "SHA512",
+         SHA512_String, SHA512_TimeTrial, SHA512_TestSuite,
+         SHA512_Filter, (_filefunc) SHA512_File },
        { NULL }
 };
 
@@ -153,7 +163,7 @@
        int (*cfncn) (int, u_int32_t *, off_t *);
        void (*pfncn) (char *, u_int32_t, off_t);
        struct hash *hash;
-       int normal;
+       int normal, i;
 
        cfncn = NULL;
        pfncn = NULL;
@@ -181,8 +191,42 @@
                }
        }
 
-       while ((ch = getopt(argc, argv, "mno:ps:tx12456")) != -1)
+       /*
+        * The -1, -2, -4, -5, -6, and -m flags should be deprecated, but
+        * are still supported in code to not break anything that might
+        * be using them.
+        */
+       while ((ch = getopt(argc, argv, "a:mno:ps:tx12456")) != -1)
                switch(ch) {
+               case 'a':
+                       if (hash != NULL || dosum) {
+                               warnx("illegal use of -a option\n");
+                               usage();
+                       }
+                       i = 0;
+                       while (hashes[i].hashname != NULL) {
+                               if (!strcasecmp(hashes[i].hashname, optarg)) {
+                                       hash = &hashes[i];
+                                       break;
+                               }
+                               i++;
+                       }
+                       if (hash == NULL) {
+                               if (!strcasecmp(optarg, "old1")) {
+                                       cfncn = csum1;
+                                       pfncn = psum1;
+                               } else if (!strcasecmp(optarg, "old2")) {
+                                       cfncn = csum2;
+                                       pfncn = psum2;
+                               } else if (!strcasecmp(optarg, "crc")) {
+                                       cfncn = crc;
+                                       pfncn = pcrc;
+                               } else {
+                                       warnx("illegal argument to -a option");
+                                       usage();
+                               }
+                       }
+                       break;
                case '2':
                        if (dosum) {
                                warnx("sum mutually exclusive with md2");
@@ -306,9 +350,9 @@
 int
 hash_digest_file(char *fn, struct hash *hash, int normal)
 {
-       char buf[41], *cp;
+       char *cp;
 
-       cp = hash->filefunc(fn, buf);
+       cp = hash->filefunc(fn, NULL);
        if (cp == NULL)
                return 1;
 
@@ -316,6 +360,9 @@
                printf("%s %s\n", cp, fn);
        else
                printf("%s (%s) = %s\n", hash->hashname, fn, cp);
+
+       free(cp);
+
        return 0;
 }
 
diff -r 13d9dd0e9f6f -r 5e540555e006 usr.bin/cksum/extern.h
--- a/usr.bin/cksum/extern.h    Sun Sep 11 22:14:04 2005 +0000
+++ b/usr.bin/cksum/extern.h    Mon Sep 12 12:17:35 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.15 2005/01/20 15:44:59 xtraeme Exp $      */
+/*     $NetBSD: extern.h,v 1.15.2.1 2005/09/12 12:17:35 tron Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -70,4 +70,19 @@
 void   RMD160TimeTrial(void);
 void   RMD160TestSuite(void);
 void   RMD160Filter(int);
+
+void   SHA256_String(const char *);
+void   SHA256_TimeTrial(void);
+void   SHA256_TestSuite(void);
+void   SHA256_Filter(int);
+
+void   SHA384_String(const char *);
+void   SHA384_TimeTrial(void);
+void   SHA384_TestSuite(void);
+void   SHA384_Filter(int);
+
+void   SHA512_String(const char *);
+void   SHA512_TimeTrial(void);
+void   SHA512_TestSuite(void);
+void   SHA512_Filter(int);
 __END_DECLS
diff -r 13d9dd0e9f6f -r 5e540555e006 usr.bin/cksum/md5.c
--- a/usr.bin/cksum/md5.c       Sun Sep 11 22:14:04 2005 +0000
+++ b/usr.bin/cksum/md5.c       Mon Sep 12 12:17:35 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md5.c,v 1.8 2005/01/20 15:44:59 xtraeme Exp $  */
+/*     $NetBSD: md5.c,v 1.8.2.1 2005/09/12 12:17:35 tron Exp $ */
 
 /*
  * MDDRIVER.C - test driver for MD2, MD4 and MD5
@@ -23,7 +23,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: md5.c,v 1.8 2005/01/20 15:44:59 xtraeme Exp $");
+__RCSID("$NetBSD: md5.c,v 1.8.2.1 2005/09/12 12:17:35 tron Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -63,7 +63,7 @@
        char buf[HASHLEN + 1];
 
        printf("%s (\"%s\") = %s\n", HASHTYPE, string,
-              MD5Data(string, len, buf));
+              MD5Data((const unsigned char *)string, len, buf));
 }
 
 /*
@@ -139,15 +139,15 @@
 MD5Filter(int pipe)
 {
        MD5_CTX context;
-       int len;
+       size_t len;
        unsigned char buffer[BUFSIZ];
        char buf[HASHLEN + 1];
 
        MD5Init(&context);
-       while ((len = fread(buffer, 1, BUFSIZ, stdin)) > 0) {
-               if (pipe && (len != fwrite(buffer, 1, len, stdout)))
+       while ((len = fread(buffer, (size_t)1, (size_t)BUFSIZ, stdin)) > 0) {
+               if (pipe && (len != fwrite(buffer, (size_t)1, len, stdout)))
                        err(1, "stdout");
-               MD5Update(&context, buffer, len);
+               MD5Update(&context, buffer, (unsigned int)len);
        }
        printf("%s\n", MD5End(&context,buf));
 }



Home | Main Index | Thread Index | Old Index