builtin/replace.c: mark more strings for translation
[git.git] / hash.h
blob7c8238bc2ebfded778351b58c16a3854617082c6
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
18 #ifndef platform_SHA_CTX
20 * platform's underlying implementation of SHA-1; could be OpenSSL,
21 * blk_SHA, Apple CommonCrypto, etc... Note that the relevant
22 * SHA-1 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
30 #endif
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
41 #endif
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
53 /* SHA-1 */
54 #define GIT_HASH_SHA1 1
55 /* Number of algorithms supported (including unknown). */
56 #define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)
58 /* A suitably aligned type for stack allocations of hash contexts. */
59 union git_hash_ctx {
60 git_SHA_CTX sha1;
62 typedef union git_hash_ctx git_hash_ctx;
64 typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
65 typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
66 typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
68 struct git_hash_algo {
70 * The name of the algorithm, as appears in the config file and in
71 * messages.
73 const char *name;
75 /* A four-byte version identifier, used in pack indices. */
76 uint32_t format_id;
78 /* The length of the hash in binary. */
79 size_t rawsz;
81 /* The length of the hash in hex characters. */
82 size_t hexsz;
84 /* The hash initialization function. */
85 git_hash_init_fn init_fn;
87 /* The hash update function. */
88 git_hash_update_fn update_fn;
90 /* The hash finalization function. */
91 git_hash_final_fn final_fn;
93 /* The OID of the empty tree. */
94 const struct object_id *empty_tree;
96 /* The OID of the empty blob. */
97 const struct object_id *empty_blob;
99 extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
101 #endif