]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
md5: use symbolical digest length
authorSami Kerola <kerolasa@iki.fi>
Wed, 20 Jul 2011 20:13:32 +0000 (22:13 +0200)
committerSami Kerola <kerolasa@iki.fi>
Thu, 21 Jul 2011 21:56:48 +0000 (23:56 +0200)
Magic hash lenght number 16 is turned to a definition MD5LENGTH,
and put into use everywhere where md5 checksum is in use.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/mkfs.cramfs.c
include/md5.h
lib/md5.c
libblkid/src/superblocks/hfs.c
misc-utils/mcookie.c
tests/helpers/test_md5.c

index 545585ad5311a6cb3070ceba8a090679aae7d100..c1b21ade3ef05b46d1c4c57ae12f675cc3c50d4a 100644 (file)
@@ -90,7 +90,7 @@ struct entry {
        /* stats */
        unsigned char *name;
        unsigned int mode, size, uid, gid;
-       unsigned char md5sum[16];
+       unsigned char md5sum[MD5LENGTH];
        unsigned char flags;       /* CRAMFS_EFLAG_* */
 
        /* FS data */
@@ -247,7 +247,7 @@ static int find_identical_file(struct entry *orig, struct entry *new, loff_t *fs
 
                if ((orig->flags & CRAMFS_EFLAG_MD5) &&
                    (new->flags & CRAMFS_EFLAG_MD5) &&
-                   !memcmp(orig->md5sum, new->md5sum, 16) &&
+                   !memcmp(orig->md5sum, new->md5sum, MD5LENGTH) &&
                    identical_file(orig, new)) {
                        new->same = orig;
                        *fslen_ub -= new->size;
index d598e81bec2dcb96303f5ea5664412e2fcfbb981..1222cf03014d640e1214a11940f7fe7779ee3e4b 100644 (file)
@@ -7,6 +7,8 @@
 typedef unsigned int uint32_t;
 #endif
 
+#define MD5LENGTH 16
+
 struct MD5Context {
        uint32_t buf[4];
        uint32_t bits[2];
@@ -16,7 +18,7 @@ struct MD5Context {
 void MD5Init(struct MD5Context *context);
 void MD5Update(struct MD5Context *context, unsigned char const *buf,
               unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
+void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *context);
 void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
 
 /*
index 071630f1954e3a2879ecf1bce931677a71875e14..26ec4bbd8d44bf6a200b69ca821c651605dd5ecf 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -107,7 +107,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
  * Final wrapup - pad to 64-byte boundary with the bit pattern 
  * 1 0* (64-bit count of bits processed, MSB-first)
  */
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
+void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *ctx)
 {
     unsigned count;
     unsigned char *p;
@@ -144,7 +144,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
 
     MD5Transform(ctx->buf, (uint32_t *) ctx->in);
     byteReverse((unsigned char *) ctx->buf, 4);
-    memcpy(digest, ctx->buf, 16);
+    memcpy(digest, ctx->buf, MD5LENGTH);
     memset(ctx, 0, sizeof(*ctx));      /* In case it's sensitive */
 }
 
index e043994e321240b6ef99efee1d33c9adb2913f37..6d960e9e71f09d5cf8cfae4cad22992abfd95998 100644 (file)
@@ -130,17 +130,17 @@ struct hfsplus_vol_header {
 
 static int hfs_set_uuid(blkid_probe pr, unsigned char const *hfs_info, size_t len)
 {
-       static unsigned char const hash_init[16] = {
+       static unsigned char const hash_init[MD5LENGTH] = {
                0xb3, 0xe2, 0x0f, 0x39, 0xf2, 0x92, 0x11, 0xd6,
                0x97, 0xa4, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac
        };
-       unsigned char uuid[16];
+       unsigned char uuid[MD5LENGTH];
        struct MD5Context md5c;
 
        if (memcmp(hfs_info, "\0\0\0\0\0\0\0\0", len) == 0)
                return -1;
        MD5Init(&md5c);
-       MD5Update(&md5c, hash_init, 16);
+       MD5Update(&md5c, hash_init, MD5LENGTH);
        MD5Update(&md5c, hfs_info, len);
        MD5Final(uuid, &md5c);
        uuid[6] = 0x30 | (uuid[6] & 0x0f);
index 61896e17da7c1e41f1192c55767545b9ecbbee71..1e6b64b08ff74f91c300aa8fad8fbf8ca8646447 100644 (file)
@@ -79,7 +79,7 @@ int main(int argc, char **argv)
 {
        size_t i;
        struct MD5Context ctx;
-       unsigned char digest[16];
+       unsigned char digest[MD5LENGTH];
        unsigned char buf[BUFFERSIZE];
        int fd;
        int c;
@@ -178,7 +178,7 @@ int main(int argc, char **argv)
        }
 
        MD5Final(digest, &ctx);
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < MD5LENGTH; i++)
                printf("%02x", digest[i]);
        putchar('\n');
 
index b99882b53f9bc2af7c9edcd938422a5ed914959a..7f1e4f358953af21198fa5d92b53697f5b783591 100644 (file)
@@ -9,7 +9,7 @@ main(int argc, char *argv[])
 {
        int i, ret;
        struct MD5Context ctx;
-       unsigned char digest[16];
+       unsigned char digest[MD5LENGTH];
        unsigned char buf[BUFSIZ];
 
        MD5Init( &ctx );
@@ -23,7 +23,7 @@ main(int argc, char *argv[])
        fclose(stdin);
        MD5Final( digest, &ctx );
 
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < MD5LENGTH; i++)
                printf( "%02x", digest[i] );
        printf("  -\n");
        return 0;