|
15 | 15 | #include "block-sha1/sha1.h"
|
16 | 16 | #endif
|
17 | 17 |
|
| 18 | +#if defined(SHA1_APPLE_UNSAFE) |
| 19 | +# include <CommonCrypto/CommonDigest.h> |
| 20 | +# define platform_SHA_CTX_unsafe CC_SHA1_CTX |
| 21 | +# define platform_SHA1_Init_unsafe CC_SHA1_Init |
| 22 | +# define platform_SHA1_Update_unsafe CC_SHA1_Update |
| 23 | +# define platform_SHA1_Final_unsafe CC_SHA1_Final |
| 24 | +#elif defined(SHA1_OPENSSL_UNSAFE) |
| 25 | +# include <openssl/sha.h> |
| 26 | +# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3 |
| 27 | +# define SHA1_NEEDS_CLONE_HELPER_UNSAFE |
| 28 | +# include "sha1/openssl.h" |
| 29 | +# define platform_SHA_CTX_unsafe openssl_SHA1_CTX |
| 30 | +# define platform_SHA1_Init_unsafe openssl_SHA1_Init |
| 31 | +# define platform_SHA1_Clone_unsafe openssl_SHA1_Clone |
| 32 | +# define platform_SHA1_Update_unsafe openssl_SHA1_Update |
| 33 | +# define platform_SHA1_Final_unsafe openssl_SHA1_Final |
| 34 | +# else |
| 35 | +# define platform_SHA_CTX_unsafe SHA_CTX |
| 36 | +# define platform_SHA1_Init_unsafe SHA1_Init |
| 37 | +# define platform_SHA1_Update_unsafe SHA1_Update |
| 38 | +# define platform_SHA1_Final_unsafe SHA1_Final |
| 39 | +# endif |
| 40 | +#elif defined(SHA1_BLK_UNSAFE) |
| 41 | +# include "block-sha1/sha1.h" |
| 42 | +# define platform_SHA_CTX_unsafe blk_SHA_CTX |
| 43 | +# define platform_SHA1_Init_unsafe blk_SHA1_Init |
| 44 | +# define platform_SHA1_Update_unsafe blk_SHA1_Update |
| 45 | +# define platform_SHA1_Final_unsafe blk_SHA1_Final |
| 46 | +#endif |
| 47 | + |
18 | 48 | #if defined(SHA256_NETTLE)
|
19 | 49 | #include "sha256/nettle.h"
|
20 | 50 | #elif defined(SHA256_GCRYPT)
|
|
44 | 74 | #define platform_SHA1_Final SHA1_Final
|
45 | 75 | #endif
|
46 | 76 |
|
| 77 | +#ifndef platform_SHA_CTX_unsafe |
| 78 | +# define platform_SHA_CTX_unsafe platform_SHA_CTX |
| 79 | +# define platform_SHA1_Init_unsafe platform_SHA1_Init |
| 80 | +# define platform_SHA1_Update_unsafe platform_SHA1_Update |
| 81 | +# define platform_SHA1_Final_unsafe platform_SHA1_Final |
| 82 | +# ifdef platform_SHA1_Clone |
| 83 | +# define platform_SHA1_Clone_unsafe platform_SHA1_Clone |
| 84 | +# endif |
| 85 | +#endif |
| 86 | + |
47 | 87 | #define git_SHA_CTX platform_SHA_CTX
|
48 | 88 | #define git_SHA1_Init platform_SHA1_Init
|
49 | 89 | #define git_SHA1_Update platform_SHA1_Update
|
50 | 90 | #define git_SHA1_Final platform_SHA1_Final
|
51 | 91 |
|
| 92 | +#define git_SHA_CTX_unsafe platform_SHA_CTX_unsafe |
| 93 | +#define git_SHA1_Init_unsafe platform_SHA1_Init_unsafe |
| 94 | +#define git_SHA1_Update_unsafe platform_SHA1_Update_unsafe |
| 95 | +#define git_SHA1_Final_unsafe platform_SHA1_Final_unsafe |
| 96 | + |
52 | 97 | #ifdef platform_SHA1_Clone
|
53 | 98 | #define git_SHA1_Clone platform_SHA1_Clone
|
54 | 99 | #endif
|
| 100 | +#ifdef platform_SHA1_Clone_unsafe |
| 101 | +# define git_SHA1_Clone_unsafe platform_SHA1_Clone_unsafe |
| 102 | +#endif |
55 | 103 |
|
56 | 104 | #ifndef platform_SHA256_CTX
|
57 | 105 | #define platform_SHA256_CTX SHA256_CTX
|
@@ -81,6 +129,13 @@ static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
|
81 | 129 | memcpy(dst, src, sizeof(*dst));
|
82 | 130 | }
|
83 | 131 | #endif
|
| 132 | +#ifndef SHA1_NEEDS_CLONE_HELPER_UNSAFE |
| 133 | +static inline void git_SHA1_Clone_unsafe(git_SHA_CTX_unsafe *dst, |
| 134 | + const git_SHA_CTX_unsafe *src) |
| 135 | +{ |
| 136 | + memcpy(dst, src, sizeof(*dst)); |
| 137 | +} |
| 138 | +#endif |
84 | 139 |
|
85 | 140 | #ifndef SHA256_NEEDS_CLONE_HELPER
|
86 | 141 | static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
|
@@ -178,6 +233,8 @@ enum get_oid_result {
|
178 | 233 | /* A suitably aligned type for stack allocations of hash contexts. */
|
179 | 234 | union git_hash_ctx {
|
180 | 235 | git_SHA_CTX sha1;
|
| 236 | + git_SHA_CTX_unsafe sha1_unsafe; |
| 237 | + |
181 | 238 | git_SHA256_CTX sha256;
|
182 | 239 | };
|
183 | 240 | typedef union git_hash_ctx git_hash_ctx;
|
@@ -222,6 +279,21 @@ struct git_hash_algo {
|
222 | 279 | /* The hash finalization function for object IDs. */
|
223 | 280 | git_hash_final_oid_fn final_oid_fn;
|
224 | 281 |
|
| 282 | + /* The non-cryptographic hash initialization function. */ |
| 283 | + git_hash_init_fn unsafe_init_fn; |
| 284 | + |
| 285 | + /* The non-cryptographic hash context cloning function. */ |
| 286 | + git_hash_clone_fn unsafe_clone_fn; |
| 287 | + |
| 288 | + /* The non-cryptographic hash update function. */ |
| 289 | + git_hash_update_fn unsafe_update_fn; |
| 290 | + |
| 291 | + /* The non-cryptographic hash finalization function. */ |
| 292 | + git_hash_final_fn unsafe_final_fn; |
| 293 | + |
| 294 | + /* The non-cryptographic hash finalization function. */ |
| 295 | + git_hash_final_oid_fn unsafe_final_oid_fn; |
| 296 | + |
225 | 297 | /* The OID of the empty tree. */
|
226 | 298 | const struct object_id *empty_tree;
|
227 | 299 |
|
|
0 commit comments