]>
Commit | Line | Data |
---|---|---|
f18f816c | 1 | #ifndef HASH_H |
2 | #define HASH_H | |
3 | ||
f50e766b | 4 | #include "git-compat-util.h" |
5 | ||
f18f816c | 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> | |
8325e43b | 12 | #elif defined(SHA1_DC) |
36f048c5 | 13 | #include "sha1dc_git.h" |
f18f816c | 14 | #else /* SHA1_BLK */ |
15 | #include "block-sha1/sha1.h" | |
16 | #endif | |
17 | ||
f50e766b | 18 | /* |
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. | |
25 | */ | |
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) | |
32 | ||
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); | |
36 | ||
37 | struct git_hash_algo { | |
38 | /* | |
39 | * The name of the algorithm, as appears in the config file and in | |
40 | * messages. | |
41 | */ | |
42 | const char *name; | |
43 | ||
44 | /* A four-byte version identifier, used in pack indices. */ | |
45 | uint32_t format_id; | |
46 | ||
47 | /* The size of a hash context (e.g. git_SHA_CTX). */ | |
48 | size_t ctxsz; | |
49 | ||
50 | /* The length of the hash in binary. */ | |
51 | size_t rawsz; | |
52 | ||
53 | /* The length of the hash in hex characters. */ | |
54 | size_t hexsz; | |
55 | ||
56 | /* The hash initialization function. */ | |
57 | git_hash_init_fn init_fn; | |
58 | ||
59 | /* The hash update function. */ | |
60 | git_hash_update_fn update_fn; | |
61 | ||
62 | /* The hash finalization function. */ | |
63 | git_hash_final_fn final_fn; | |
64 | ||
65 | /* The OID of the empty tree. */ | |
66 | const struct object_id *empty_tree; | |
67 | ||
68 | /* The OID of the empty blob. */ | |
69 | const struct object_id *empty_blob; | |
70 | }; | |
71 | extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; | |
72 | ||
f18f816c | 73 | #endif |