git/hash.h

#ifndef HASH_H
#define HASH_H

#if defined(SHA1_APPLE)
#include <CommonCrypto/CommonDigest.h>
#elif defined(SHA1_OPENSSL)
#  include <openssl/sha.h>
#  if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
#define SHA1_NEEDS_CLONE_HELPER
#    include "sha1/openssl.h"
#  endif
#elif defined(SHA1_DC)
#include "sha1dc_git.h"
#else /* SHA1_BLK */
#include "block-sha1/sha1.h"
#endif

#if defined(SHA1_APPLE_UNSAFE)
#  include <CommonCrypto/CommonDigest.h>
#define platform_SHA_CTX_unsafe
#define platform_SHA1_Init_unsafe
#define platform_SHA1_Update_unsafe
#define platform_SHA1_Final_unsafe
#elif defined(SHA1_OPENSSL_UNSAFE)
#  include <openssl/sha.h>
#  if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
#define SHA1_NEEDS_CLONE_HELPER_UNSAFE
#    include "sha1/openssl.h"
#define platform_SHA_CTX_unsafe
#define platform_SHA1_Init_unsafe
#define platform_SHA1_Clone_unsafe
#define platform_SHA1_Update_unsafe
#define platform_SHA1_Final_unsafe
#  else
#define platform_SHA_CTX_unsafe
#define platform_SHA1_Init_unsafe
#define platform_SHA1_Update_unsafe
#define platform_SHA1_Final_unsafe
#  endif
#elif defined(SHA1_BLK_UNSAFE)
#  include "block-sha1/sha1.h"
#define platform_SHA_CTX_unsafe
#define platform_SHA1_Init_unsafe
#define platform_SHA1_Update_unsafe
#define platform_SHA1_Final_unsafe
#endif

#if defined(SHA256_NETTLE)
#include "sha256/nettle.h"
#elif defined(SHA256_GCRYPT)
#define SHA256_NEEDS_CLONE_HELPER
#include "sha256/gcrypt.h"
#elif defined(SHA256_OPENSSL)
#  include <openssl/sha.h>
#  if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
#define SHA256_NEEDS_CLONE_HELPER
#    include "sha256/openssl.h"
#  endif
#else
#include "sha256/block/sha256.h"
#endif

#ifndef platform_SHA_CTX
/*
 * platform's underlying implementation of SHA-1; could be OpenSSL,
 * blk_SHA, Apple CommonCrypto, etc...  Note that the relevant
 * SHA-1 header may have already defined platform_SHA_CTX for our
 * own implementations like block-sha1, so we list
 * the default for OpenSSL compatible SHA-1 implementations here.
 */
#define platform_SHA_CTX
#define platform_SHA1_Init
#define platform_SHA1_Update
#define platform_SHA1_Final
#endif

#ifndef platform_SHA_CTX_unsafe
#define platform_SHA_CTX_unsafe
#define platform_SHA1_Init_unsafe
#define platform_SHA1_Update_unsafe
#define platform_SHA1_Final_unsafe
#  ifdef platform_SHA1_Clone
#define platform_SHA1_Clone_unsafe
#  endif
#  ifdef SHA1_NEEDS_CLONE_HELPER
#define SHA1_NEEDS_CLONE_HELPER_UNSAFE
#  endif
#endif

#define git_SHA_CTX
#define git_SHA1_Init
#define git_SHA1_Update
#define git_SHA1_Final

#define git_SHA_CTX_unsafe
#define git_SHA1_Init_unsafe
#define git_SHA1_Update_unsafe
#define git_SHA1_Final_unsafe

#ifdef platform_SHA1_Clone
#define git_SHA1_Clone
#endif
#ifdef platform_SHA1_Clone_unsafe
#define git_SHA1_Clone_unsafe
#endif

#ifndef platform_SHA256_CTX
#define platform_SHA256_CTX
#define platform_SHA256_Init
#define platform_SHA256_Update
#define platform_SHA256_Final
#endif

#define git_SHA256_CTX
#define git_SHA256_Init
#define git_SHA256_Update
#define git_SHA256_Final

#ifdef platform_SHA256_Clone
#define git_SHA256_Clone
#endif

#ifdef SHA1_MAX_BLOCK_SIZE
#include "compat/sha1-chunked.h"
#undef git_SHA1_Update
#define git_SHA1_Update
#endif

#ifndef SHA1_NEEDS_CLONE_HELPER
static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
{}
#endif
#ifndef SHA1_NEEDS_CLONE_HELPER_UNSAFE
static inline void git_SHA1_Clone_unsafe(git_SHA_CTX_unsafe *dst,
				       const git_SHA_CTX_unsafe *src)
{}
#endif

#ifndef SHA256_NEEDS_CLONE_HELPER
static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
{}
#endif

/*
 * Note that these constants are suitable for indexing the hash_algos array and
 * comparing against each other, but are otherwise arbitrary, so they should not
 * be exposed to the user or serialized to disk.  To know whether a
 * git_hash_algo struct points to some usable hash function, test the format_id
 * field for being non-zero.  Use the name field for user-visible situations and
 * the format_id field for fixed-length fields on disk.
 */
/* An unknown hash function. */
#define GIT_HASH_UNKNOWN
/* SHA-1 */
#define GIT_HASH_SHA1
/* SHA-256  */
#define GIT_HASH_SHA256
/* Number of algorithms supported (including unknown). */
#define GIT_HASH_NALGOS

/* "sha1", big-endian */
#define GIT_SHA1_FORMAT_ID

/* The length in bytes and in hex digits of an object name (SHA-1 value). */
#define GIT_SHA1_RAWSZ
#define GIT_SHA1_HEXSZ
/* The block size of SHA-1. */
#define GIT_SHA1_BLKSZ

/* "s256", big-endian */
#define GIT_SHA256_FORMAT_ID

/* The length in bytes and in hex digits of an object name (SHA-256 value). */
#define GIT_SHA256_RAWSZ
#define GIT_SHA256_HEXSZ
/* The block size of SHA-256. */
#define GIT_SHA256_BLKSZ

/* The length in byte and in hex digits of the largest possible hash value. */
#define GIT_MAX_RAWSZ
#define GIT_MAX_HEXSZ
/* The largest possible block size for any supported hash. */
#define GIT_MAX_BLKSZ

struct object_id {};

#define GET_OID_QUIETLY
#define GET_OID_COMMIT
#define GET_OID_COMMITTISH
#define GET_OID_TREE
#define GET_OID_TREEISH
#define GET_OID_BLOB
#define GET_OID_FOLLOW_SYMLINKS
#define GET_OID_RECORD_PATH
#define GET_OID_ONLY_TO_DIE
#define GET_OID_REQUIRE_PATH
#define GET_OID_HASH_ANY

#define GET_OID_DISAMBIGUATORS

enum get_oid_result {};

#ifdef USE_THE_REPOSITORY_VARIABLE
# include "repository.h"
#define the_hash_algo
#endif

/* A suitably aligned type for stack allocations of hash contexts. */
git_hash_ctx;
git_hash_ctx;

git_hash_init_fn;
git_hash_clone_fn;
git_hash_update_fn;
git_hash_final_fn;
git_hash_final_oid_fn;

struct git_hash_algo {};
extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];

/*
 * Return a GIT_HASH_* constant based on the name.  Returns GIT_HASH_UNKNOWN if
 * the name doesn't match a known algorithm.
 */
int hash_algo_by_name(const char *name);
/* Identical, except based on the format ID. */
int hash_algo_by_id(uint32_t format_id);
/* Identical, except based on the length. */
int hash_algo_by_length(int len);
/* Identical, except for a pointer to struct git_hash_algo. */
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
{}

const struct object_id *null_oid(void);

static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{}

static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
{}

static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src,
			   const struct git_hash_algo *algop)
{}

static inline void hashclr(unsigned char *hash, const struct git_hash_algo *algop)
{}

static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
{}

static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
{}

static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{}

static inline void oidread(struct object_id *oid, const unsigned char *hash,
			   const struct git_hash_algo *algop)
{}

static inline void oidclr(struct object_id *oid,
			  const struct git_hash_algo *algop)
{}

static inline struct object_id *oiddup(const struct object_id *src)
{}

static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop)
{}

/*
 * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
 * for use in hash tables. Cryptographic hashes are supposed to have
 * uniform distribution, so in contrast to `memhash()`, this just copies
 * the first `sizeof(int)` bytes without shuffling any bits. Note that
 * the results will be different on big-endian and little-endian
 * platforms, so they should not be stored or transferred over the net.
 */
static inline unsigned int oidhash(const struct object_id *oid)
{}

static inline int is_null_oid(const struct object_id *oid)
{}

const char *empty_tree_oid_hex(const struct git_hash_algo *algop);

static inline int is_empty_blob_oid(const struct object_id *oid,
				    const struct git_hash_algo *algop)
{}

static inline int is_empty_tree_oid(const struct object_id *oid,
				    const struct git_hash_algo *algop)
{}

#endif