Merge branch 'jt/fsck-code-cleanup' into maint
[git/raj.git] / hash.h
blob7d7a864f5dd43bb53ee6b31d391df3e15cbdbb08
1 #ifndef HASH_H
2 #define HASH_H
4 #include "git-compat-util.h"
6 #if defined(SHA1_PPC)
7 #include "ppc/sha1.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"
14 #else /* SHA1_BLK */
15 #include "block-sha1/sha1.h"
16 #endif
19 * Note that these constants are suitable for indexing the hash_algos array and
20 * comparing against each other, but are otherwise arbitrary, so they should not
21 * be exposed to the user or serialized to disk. To know whether a
22 * git_hash_algo struct points to some usable hash function, test the format_id
23 * field for being non-zero. Use the name field for user-visible situations and
24 * the format_id field for fixed-length fields on disk.
26 /* An unknown hash function. */
27 #define GIT_HASH_UNKNOWN 0
28 /* SHA-1 */
29 #define GIT_HASH_SHA1 1
30 /* Number of algorithms supported (including unknown). */
31 #define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)
33 typedef void (*git_hash_init_fn)(void *ctx);
34 typedef void (*git_hash_update_fn)(void *ctx, const void *in, size_t len);
35 typedef void (*git_hash_final_fn)(unsigned char *hash, void *ctx);
37 struct git_hash_algo {
39 * The name of the algorithm, as appears in the config file and in
40 * messages.
42 const char *name;
44 /* A four-byte version identifier, used in pack indices. */
45 uint32_t format_id;
47 /* The size of a hash context (e.g. git_SHA_CTX). */
48 size_t ctxsz;
50 /* The length of the hash in binary. */
51 size_t rawsz;
53 /* The length of the hash in hex characters. */
54 size_t hexsz;
56 /* The hash initialization function. */
57 git_hash_init_fn init_fn;
59 /* The hash update function. */
60 git_hash_update_fn update_fn;
62 /* The hash finalization function. */
63 git_hash_final_fn final_fn;
65 /* The OID of the empty tree. */
66 const struct object_id *empty_tree;
68 /* The OID of the empty blob. */
69 const struct object_id *empty_blob;
71 extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
73 #endif