summaryrefslogtreecommitdiff
path: root/checksum.c
diff options
context:
space:
mode:
authorWayne Davison <wayne@opencoder.net>2022-08-14 10:09:34 -0700
committerWayne Davison <wayne@opencoder.net>2022-08-14 10:09:40 -0700
commitb7ea3fcd1999bb74a0210362e4b7f3ba80fe0069 (patch)
treeb9d4fd1b636015198592a76a84b08b04fde3c04a /checksum.c
parent9cb7529ba60cd59519489ad0fc7fbb69ced6411f (diff)
downloadrsync-b7ea3fcd1999bb74a0210362e4b7f3ba80fe0069.tar.gz
Ensure a dynamically linked xxhash lib is >= 0.8 for XX3.
Diffstat (limited to 'checksum.c')
-rw-r--r--checksum.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/checksum.c b/checksum.c
index 178b0f50..fb8c0a09 100644
--- a/checksum.c
+++ b/checksum.c
@@ -62,6 +62,8 @@ struct name_num_obj valid_checksums = {
int xfersum_type = 0; /* used for the file transfer checksums */
int checksum_type = 0; /* used for the pre-transfer (--checksum) checksums */
+static int initialized_choices = 0;
+
int parse_csum_name(const char *name, int len)
{
struct name_num_item *nni;
@@ -79,6 +81,9 @@ int parse_csum_name(const char *name, int len)
return CSUM_MD4_ARCHAIC;
}
+ if (!initialized_choices)
+ init_checksum_choices();
+
nni = get_nni_by_name(&valid_checksums, name, len);
if (!nni) {
@@ -623,3 +628,31 @@ int sum_end(char *sum)
return csum_len_for_type(cursum_type, 0);
}
+
+void init_checksum_choices()
+{
+#ifdef SUPPORT_XXH3
+ char buf[32816];
+ int j;
+ for (j = 0; j < (int)sizeof buf; j++) {
+ buf[j] = ' ' + (j % 96);
+ }
+ sum_init(CSUM_XXH3_64, 0);
+ sum_update(buf, 32816);
+ sum_update(buf, 31152);
+ sum_update(buf, 32474);
+ sum_update(buf, 9322);
+ if (XXH3_64bits_digest(xxh3_state) != 0xadbcf16d4678d1de) {
+ int t, f;
+ struct name_num_item *nni = valid_checksums.list;
+ for (t = f = 0; nni[f].name; f++) {
+ if (nni[f].num == CSUM_XXH3_64 || nni[f].num == CSUM_XXH3_128)
+ continue;
+ if (t != f)
+ nni[t++] = nni[f];
+ }
+ nni[t].name = NULL;
+ }
+#endif
+ initialized_choices = 1;
+}