Skip to content

Commit ae16850

Browse files
committed
Add support for various SHA checksum digests
The main purpose of the SHA checksums are to allow the daemon auth code to pick a stonger digest method when negotiating the auth digest to use. However, the SHA digests are also available for use in file checksums, should someon really want to use one of them. The new digests are listed from strongest to weakest at the start of the daemon auth list, giving them the highest priority. The new digests are listed from weakest to strongest near the end of the checksum list, giving them the lowest priority of use for file checksums.
1 parent 7e2711b commit ae16850

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

NEWS.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
### ENHANCEMENTS:
1010

1111
- Added negotiated daemon-auth support that allows a stronger checksum digest
12-
to be used.
12+
to be used. Added SHA512, SHA256, and SHA1 digests to MD5 & MD4. These new
13+
digests are at the highest priority in the new negotiation list.
14+
15+
- Added support for SHA1, SHA256, and SHA512 digests in file checksums. While
16+
This tends to be overkill, if someone needs it, it is available. These
17+
overly-long checksums are at the lowest priority in the normal checksum
18+
negotation list.
1319

1420
### PACKAGING RELATED:
1521

checksum.c

+33
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ struct name_num_item valid_checksums_items[] = {
5757
#endif
5858
{ CSUM_MD5, NNI_BUILTIN|NNI_EVP, "md5", NULL },
5959
{ CSUM_MD4, NNI_BUILTIN|NNI_EVP, "md4", NULL },
60+
#ifdef SHA_DIGEST_LENGTH
61+
{ CSUM_SHA1, NNI_EVP, "sha1", NULL },
62+
#endif
63+
#ifdef SHA256_DIGEST_LENGTH
64+
{ CSUM_SHA256, NNI_EVP, "sha256", NULL },
65+
#endif
66+
#ifdef SHA512_DIGEST_LENGTH
67+
{ CSUM_SHA512, NNI_EVP, "sha512", NULL },
68+
#endif
6069
{ CSUM_NONE, 0, "none", NULL },
6170
{ 0, 0, NULL, NULL }
6271
};
@@ -66,6 +75,15 @@ struct name_num_obj valid_checksums = {
6675
};
6776

6877
struct name_num_item valid_auth_checksums_items[] = {
78+
#ifdef SHA512_DIGEST_LENGTH
79+
{ CSUM_SHA512, NNI_EVP, "sha512", NULL },
80+
#endif
81+
#ifdef SHA256_DIGEST_LENGTH
82+
{ CSUM_SHA256, NNI_EVP, "sha256", NULL },
83+
#endif
84+
#ifdef SHA_DIGEST_LENGTH
85+
{ CSUM_SHA1, NNI_EVP, "sha1", NULL },
86+
#endif
6987
{ CSUM_MD5, NNI_BUILTIN|NNI_EVP, "md5", NULL },
7088
{ CSUM_MD4, NNI_BUILTIN|NNI_EVP, "md4", NULL },
7189
{ 0, 0, NULL, NULL }
@@ -211,6 +229,18 @@ int csum_len_for_type(int cst, BOOL flist_csum)
211229
return MD4_DIGEST_LEN;
212230
case CSUM_MD5:
213231
return MD5_DIGEST_LEN;
232+
#ifdef SHA_DIGEST_LENGTH
233+
case CSUM_SHA1:
234+
return SHA_DIGEST_LENGTH;
235+
#endif
236+
#ifdef SHA256_DIGEST_LENGTH
237+
case CSUM_SHA256:
238+
return SHA256_DIGEST_LENGTH;
239+
#endif
240+
#ifdef SHA512_DIGEST_LENGTH
241+
case CSUM_SHA512:
242+
return SHA512_DIGEST_LENGTH;
243+
#endif
214244
case CSUM_XXH64:
215245
case CSUM_XXH3_64:
216246
return 64/8;
@@ -236,6 +266,9 @@ int canonical_checksum(int csum_type)
236266
break;
237267
case CSUM_MD4:
238268
case CSUM_MD5:
269+
case CSUM_SHA1:
270+
case CSUM_SHA256:
271+
case CSUM_SHA512:
239272
return -1;
240273
case CSUM_XXH64:
241274
case CSUM_XXH3_64:

lib/md-defines.h

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
/* Keep this simple so both C and ASM can use it */
22

3+
/* These allow something like CFLAGS=-DDISABLE_SHA512_DIGEST */
4+
#ifdef DISABLE_SHA256_DIGEST
5+
#undef SHA256_DIGEST_LENGTH
6+
#endif
7+
#ifdef DISABLE_SHA512_DIGEST
8+
#undef SHA512_DIGEST_LENGTH
9+
#endif
10+
311
#define MD4_DIGEST_LEN 16
412
#define MD5_DIGEST_LEN 16
13+
#if defined SHA512_DIGEST_LENGTH
14+
#define MAX_DIGEST_LEN SHA512_DIGEST_LENGTH
15+
#elif defined SHA256_DIGEST_LENGTH
16+
#define MAX_DIGEST_LEN SHA256_DIGEST_LENGTH
17+
#elif defined SHA_DIGEST_LENGTH
18+
#define MAX_DIGEST_LEN SHA_DIGEST_LENGTH
19+
#else
520
#define MAX_DIGEST_LEN MD5_DIGEST_LEN
21+
#endif
622

723
#define CSUM_CHUNK 64
824

@@ -16,3 +32,6 @@
1632
#define CSUM_XXH64 6
1733
#define CSUM_XXH3_64 7
1834
#define CSUM_XXH3_128 8
35+
#define CSUM_SHA1 9
36+
#define CSUM_SHA256 10
37+
#define CSUM_SHA512 11

lib/mdigest.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* The include file for both the MD4 and MD5 routines. */
22

33
#ifdef USE_OPENSSL
4+
#include <openssl/sha.h>
45
#include <openssl/evp.h>
56
#endif
67
#include "md-defines.h"

rsync.1.md

+3
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,9 @@ expand it.
17271727
- `xxh64` (aka `xxhash`)
17281728
- `md5`
17291729
- `md4`
1730+
- `sha1`
1731+
- `sha256`
1732+
- `sha512`
17301733
- `none`
17311734

17321735
Run `rsync --version` to see the default checksum list compiled into your

0 commit comments

Comments
 (0)