Fix conflicts.
[rsync-patches.git] / sha1.diff
1 This patch adds sha1 to the checksum code when the openssl library is available.
2 It also enables SHA1 checksum hashing in the daemon auth code.
3
4 To use this patch, run these commands for a successful build:
5
6     patch -p1 <patches/fix-checksums.diff
7     patch -p1 <patches/sha1.diff
8     ./configure                               (optional if already run)
9     make
10
11 based-on: patch/master/fix-checksums
12 diff --git a/checksum.c b/checksum.c
13 --- a/checksum.c
14 +++ b/checksum.c
15 @@ -57,6 +57,15 @@ struct name_num_item valid_checksums_items[] = {
16  #endif
17         { CSUM_MD5, NNI_BUILTIN|NNI_EVP, "md5", NULL },
18         { CSUM_MD4, NNI_BUILTIN|NNI_EVP, "md4", NULL },
19 +#ifdef SHA_DIGEST_LENGTH
20 +       { CSUM_SHA1, NNI_EVP, "sha1", NULL },
21 +#endif
22 +#ifdef SHA256_DIGEST_LENGTH
23 +       { CSUM_SHA256, NNI_EVP, "sha256", NULL },
24 +#endif
25 +#ifdef SHA512_DIGEST_LENGTH
26 +       { CSUM_SHA512, NNI_EVP, "sha512", NULL },
27 +#endif
28         { CSUM_NONE, 0, "none", NULL },
29         { 0, 0, NULL, NULL }
30  };
31 @@ -66,6 +75,15 @@ struct name_num_obj valid_checksums = {
32  };
33  
34  struct name_num_item valid_auth_checksums_items[] = {
35 +#ifdef SHA512_DIGEST_LENGTH
36 +       { CSUM_SHA512, NNI_EVP, "sha512", NULL },
37 +#endif
38 +#ifdef SHA256_DIGEST_LENGTH
39 +       { CSUM_SHA256, NNI_EVP, "sha256", NULL },
40 +#endif
41 +#ifdef SHA_DIGEST_LENGTH
42 +       { CSUM_SHA1, NNI_EVP, "sha1", NULL },
43 +#endif
44         { CSUM_MD5, NNI_BUILTIN|NNI_EVP, "md5", NULL },
45         { CSUM_MD4, NNI_BUILTIN|NNI_EVP, "md4", NULL },
46         { 0, 0, NULL, NULL }
47 @@ -211,6 +229,18 @@ int csum_len_for_type(int cst, BOOL flist_csum)
48                 return MD4_DIGEST_LEN;
49           case CSUM_MD5:
50                 return MD5_DIGEST_LEN;
51 +#ifdef SHA_DIGEST_LENGTH
52 +         case CSUM_SHA1:
53 +               return SHA_DIGEST_LENGTH;
54 +#endif
55 +#ifdef SHA256_DIGEST_LENGTH
56 +         case CSUM_SHA256:
57 +               return SHA256_DIGEST_LENGTH;
58 +#endif
59 +#ifdef SHA512_DIGEST_LENGTH
60 +         case CSUM_SHA512:
61 +               return SHA512_DIGEST_LENGTH;
62 +#endif
63           case CSUM_XXH64:
64           case CSUM_XXH3_64:
65                 return 64/8;
66 @@ -236,6 +266,9 @@ int canonical_checksum(int csum_type)
67                 break;
68           case CSUM_MD4:
69           case CSUM_MD5:
70 +         case CSUM_SHA1:
71 +         case CSUM_SHA256:
72 +         case CSUM_SHA512:
73                 return -1;
74           case CSUM_XXH64:
75           case CSUM_XXH3_64:
76 diff --git a/lib/md-defines.h b/lib/md-defines.h
77 --- a/lib/md-defines.h
78 +++ b/lib/md-defines.h
79 @@ -1,8 +1,19 @@
80  /* Keep this simple so both C and ASM can use it */
81  
82 +/*#undef SHA512_DIGEST_LENGTH*/
83 +/*#undef SHA256_DIGEST_LENGTH*/
84 +
85  #define MD4_DIGEST_LEN 16
86  #define MD5_DIGEST_LEN 16
87 +#if defined SHA512_DIGEST_LENGTH
88 +#define MAX_DIGEST_LEN SHA512_DIGEST_LENGTH
89 +#elif defined SHA256_DIGEST_LENGTH
90 +#define MAX_DIGEST_LEN SHA256_DIGEST_LENGTH
91 +#elif defined SHA_DIGEST_LENGTH
92 +#define MAX_DIGEST_LEN SHA_DIGEST_LENGTH
93 +#else
94  #define MAX_DIGEST_LEN MD5_DIGEST_LEN
95 +#endif
96  
97  #define CSUM_CHUNK 64
98  
99 @@ -16,3 +27,6 @@
100  #define CSUM_XXH64 6
101  #define CSUM_XXH3_64 7
102  #define CSUM_XXH3_128 8
103 +#define CSUM_SHA1 9
104 +#define CSUM_SHA256 10
105 +#define CSUM_SHA512 11
106 diff --git a/lib/mdigest.h b/lib/mdigest.h
107 --- a/lib/mdigest.h
108 +++ b/lib/mdigest.h
109 @@ -1,6 +1,7 @@
110  /* The include file for both the MD4 and MD5 routines. */
111  
112  #ifdef USE_OPENSSL
113 +#include <openssl/sha.h>
114  #include <openssl/evp.h>
115  #endif
116  #include "md-defines.h"