4 #include "git-compat-util.h"
8 #elif defined(SHA1_APPLE)
9 #include <CommonCrypto/CommonDigest.h>
10 #elif defined(SHA1_OPENSSL)
11 #include <openssl/sha.h>
12 #elif defined(SHA1_DC)
13 #include "sha1dc_git.h"
15 #include "block-sha1/sha1.h"
18 #ifndef platform_SHA_CTX
20 * platform's underlying implementation of SHA-1; could be OpenSSL,
21 * blk_SHA, Apple CommonCrypto, etc... Note that including
22 * SHA1_HEADER may have already defined platform_SHA_CTX for our
23 * own implementations like block-sha1 and ppc-sha1, so we list
24 * the default for OpenSSL compatible SHA-1 implementations here.
26 #define platform_SHA_CTX SHA_CTX
27 #define platform_SHA1_Init SHA1_Init
28 #define platform_SHA1_Update SHA1_Update
29 #define platform_SHA1_Final SHA1_Final
32 #define git_SHA_CTX platform_SHA_CTX
33 #define git_SHA1_Init platform_SHA1_Init
34 #define git_SHA1_Update platform_SHA1_Update
35 #define git_SHA1_Final platform_SHA1_Final
37 #ifdef SHA1_MAX_BLOCK_SIZE
38 #include "compat/sha1-chunked.h"
39 #undef git_SHA1_Update
40 #define git_SHA1_Update git_SHA1_Update_Chunked
44 * Note that these constants are suitable for indexing the hash_algos array and
45 * comparing against each other, but are otherwise arbitrary, so they should not
46 * be exposed to the user or serialized to disk. To know whether a
47 * git_hash_algo struct points to some usable hash function, test the format_id
48 * field for being non-zero. Use the name field for user-visible situations and
49 * the format_id field for fixed-length fields on disk.
51 /* An unknown hash function. */
52 #define GIT_HASH_UNKNOWN 0
54 #define GIT_HASH_SHA1 1
55 /* Number of algorithms supported (including unknown). */
56 #define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)
58 typedef void (*git_hash_init_fn
)(void *ctx
);
59 typedef void (*git_hash_update_fn
)(void *ctx
, const void *in
, size_t len
);
60 typedef void (*git_hash_final_fn
)(unsigned char *hash
, void *ctx
);
62 struct git_hash_algo
{
64 * The name of the algorithm, as appears in the config file and in
69 /* A four-byte version identifier, used in pack indices. */
72 /* The size of a hash context (e.g. git_SHA_CTX). */
75 /* The length of the hash in binary. */
78 /* The length of the hash in hex characters. */
81 /* The hash initialization function. */
82 git_hash_init_fn init_fn
;
84 /* The hash update function. */
85 git_hash_update_fn update_fn
;
87 /* The hash finalization function. */
88 git_hash_final_fn final_fn
;
90 /* The OID of the empty tree. */
91 const struct object_id
*empty_tree
;
93 /* The OID of the empty blob. */
94 const struct object_id
*empty_blob
;
96 extern const struct git_hash_algo hash_algos
[GIT_HASH_NALGOS
];