]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
The xxh* checksums don't need to be reversed on output.
authorWayne Davison <wayne@opencoder.net>
Thu, 28 May 2020 19:05:54 +0000 (12:05 -0700)
committerWayne Davison <wayne@opencoder.net>
Thu, 28 May 2020 19:33:36 +0000 (12:33 -0700)
checksum.c
log.c
util2.c

index 5576ede95ed549c6111b0adca26ef90fa97e2651..cf3000d918c1eeedbc400f227813b6a28bc0dd0a 100644 (file)
@@ -162,9 +162,29 @@ int csum_len_for_type(int cst, BOOL flist_csum)
        return 0;
 }
 
+/* Returns 0 if the checksum is not canonical (i.e. it includes a seed value).
+ * Returns 1 if the public sum order matches our internal sum order.
+ * Returns -1 if the public sum order is the reverse of our internal sum order.
+ */
 int canonical_checksum(int csum_type)
 {
-       return csum_type >= CSUM_MD4 ? 1 : 0;
+       switch (csum_type) {
+         case CSUM_NONE:
+         case CSUM_MD4_ARCHAIC:
+         case CSUM_MD4_OLD:
+         case CSUM_MD4_BUSTED:
+               break;
+         case CSUM_MD4:
+         case CSUM_MD5:
+               return -1;
+#ifdef SUPPORT_XXHASH
+         case CSUM_XXH64:
+               return 1;
+#endif
+         default: /* paranoia to prevent missing case values */
+               exit_cleanup(RERR_UNSUPPORTED);
+       }
+       return 0;
 }
 
 #ifndef HAVE_SIMD /* See simd-checksum-*.cpp. */
diff --git a/log.c b/log.c
index 4cd3aa611aabd674f6c78ac968e071e02f3dd7b8..c2e7fde8e45924a7f4140feda4e31819dc6a5c6e 100644 (file)
--- a/log.c
+++ b/log.c
@@ -679,9 +679,9 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
                case 'C':
                        n = NULL;
                        if (S_ISREG(file->mode)) {
-                               if (always_checksum && canonical_checksum(checksum_type))
+                               if (always_checksum)
                                        n = sum_as_hex(checksum_type, F_SUM(file), 1);
-                               else if (iflags & ITEM_TRANSFER && canonical_checksum(xfersum_type))
+                               else if (iflags & ITEM_TRANSFER)
                                        n = sum_as_hex(xfersum_type, sender_file_sum, 0);
                        }
                        if (!n) {
diff --git a/util2.c b/util2.c
index 488d673a0b0e018a096c7bafe7cab8f4f3154a0a..ad7b0636723cd87c9d7c135a1b7f7521e70a56c9 100644 (file)
--- a/util2.c
+++ b/util2.c
@@ -89,21 +89,26 @@ const char *sum_as_hex(int csum_type, const char *sum, int flist_csum)
 {
        static char buf[MAX_DIGEST_LEN*2+1];
        int i, x1, x2;
+       int canonical = canonical_checksum(csum_type);
        int sum_len = csum_len_for_type(csum_type, flist_csum);
-       char *c = buf + sum_len*2;
+       char *c;
 
-       assert(c - buf < (int)sizeof buf);
+       if (!canonical)
+               return NULL;
 
-       *c = '\0';
+       assert(sum_len*2 < (int)sizeof buf);
 
-       for (i = sum_len; --i >= 0; ) {
-               x1 = CVAL(sum, i);
-               x2 = x1 >> 4;
-               x1 &= 0xF;
-               *--c = x1 <= 9 ? x1 + '0' : x1 + 'a' - 10;
-               *--c = x2 <= 9 ? x2 + '0' : x2 + 'a' - 10;
+       for (i = sum_len, c = buf; --i >= 0; ) {
+               int ndx = canonical < 0 ? sum_len - i - 1 : i;
+               x2 = CVAL(sum, ndx);
+               x1 = x2 >> 4;
+               x2 &= 0xF;
+               *c++ = x1 <= 9 ? x1 + '0' : x1 + 'a' - 10;
+               *c++ = x2 <= 9 ? x2 + '0' : x2 + 'a' - 10;
        }
 
+       *c = '\0';
+
        return buf;
 }