hash.hon commit commit-reach: move walk methods from commit.c (5227c38)
   1#ifndef HASH_H
   2#define HASH_H
   3
   4#include "git-compat-util.h"
   5
   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
  17
  18#ifndef platform_SHA_CTX
  19/*
  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.
  25 */
  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
  31
  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
  36
  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
  42
  43/*
  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.
  50 */
  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)
  57
  58/* A suitably aligned type for stack allocations of hash contexts. */
  59union git_hash_ctx {
  60        git_SHA_CTX sha1;
  61};
  62typedef union git_hash_ctx git_hash_ctx;
  63
  64typedef void (*git_hash_init_fn)(git_hash_ctx *ctx);
  65typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);
  66typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);
  67
  68struct git_hash_algo {
  69        /*
  70         * The name of the algorithm, as appears in the config file and in
  71         * messages.
  72         */
  73        const char *name;
  74
  75        /* A four-byte version identifier, used in pack indices. */
  76        uint32_t format_id;
  77
  78        /* The length of the hash in binary. */
  79        size_t rawsz;
  80
  81        /* The length of the hash in hex characters. */
  82        size_t hexsz;
  83
  84        /* The hash initialization function. */
  85        git_hash_init_fn init_fn;
  86
  87        /* The hash update function. */
  88        git_hash_update_fn update_fn;
  89
  90        /* The hash finalization function. */
  91        git_hash_final_fn final_fn;
  92
  93        /* The OID of the empty tree. */
  94        const struct object_id *empty_tree;
  95
  96        /* The OID of the empty blob. */
  97        const struct object_id *empty_blob;
  98};
  99extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
 100
 101#endif