mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
hash: move SHA1 implementations into 'sha1/' folder
As we will include additional hash algorithms in the future due to upstream git discussing a move away from SHA1, we should accomodate for that and prepare for the move. As a first step, move all SHA1 implementations into a common subdirectory. Also, create a SHA1-specific header file that lives inside the hash folder. This header will contain the SHA1-specific header includes, function declarations and the SHA1 context structure.
This commit is contained in:
@@ -30,7 +30,7 @@ IF(SHA1_BACKEND STREQUAL "CollisionDetection")
|
||||
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
|
||||
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
|
||||
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
|
||||
FILE(GLOB SRC_SHA1 hash/hash_collisiondetect.c hash/sha1dc/*)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.c hash/sha1/sha1dc/*)
|
||||
ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
|
||||
# OPENSSL_FOUND should already be set, we're checking HTTPS_BACKEND
|
||||
|
||||
@@ -40,13 +40,13 @@ ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
|
||||
ELSE()
|
||||
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
|
||||
ENDIF()
|
||||
FILE(GLOB SRC_SHA1 hash/hash_openssl.c)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/openssl.c)
|
||||
ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
|
||||
SET(GIT_SHA1_COMMON_CRYPTO 1)
|
||||
FILE(GLOB SRC_SHA1 hash/hash_common_crypto.c)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.c)
|
||||
ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
|
||||
SET(GIT_SHA1_MBEDTLS 1)
|
||||
FILE(GLOB SRC_SHA1 hash/hash_mbedtls.c)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.c)
|
||||
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
|
||||
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
|
||||
# mbedTLS has no pkgconfig file, hence we can't require it
|
||||
@@ -55,9 +55,9 @@ ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
|
||||
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
|
||||
ELSEIF(SHA1_BACKEND STREQUAL "Win32")
|
||||
SET(GIT_SHA1_WIN32 1)
|
||||
FILE(GLOB SRC_SHA1 hash/hash_win32.c)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/win32.c)
|
||||
ELSEIF(SHA1_BACKEND STREQUAL "Generic")
|
||||
FILE(GLOB SRC_SHA1 hash/hash_generic.c)
|
||||
FILE(GLOB SRC_SHA1 hash/sha1/generic.c)
|
||||
# ELSEIF(NOT USE_SHA1)
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${SHA1_BACKEND}")
|
||||
|
||||
15
src/hash.h
15
src/hash.h
@@ -4,6 +4,7 @@
|
||||
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_h__
|
||||
#define INCLUDE_hash_h__
|
||||
|
||||
@@ -18,19 +19,7 @@ typedef struct {
|
||||
size_t len;
|
||||
} git_buf_vec;
|
||||
|
||||
#if defined(GIT_SHA1_COLLISIONDETECT)
|
||||
# include "hash/hash_collisiondetect.h"
|
||||
#elif defined(GIT_SHA1_COMMON_CRYPTO)
|
||||
# include "hash/hash_common_crypto.h"
|
||||
#elif defined(GIT_SHA1_OPENSSL)
|
||||
# include "hash/hash_openssl.h"
|
||||
#elif defined(GIT_SHA1_WIN32)
|
||||
# include "hash/hash_win32.h"
|
||||
#elif defined(GIT_SHA1_MBEDTLS)
|
||||
# include "hash/hash_mbedtls.h"
|
||||
#else
|
||||
# include "hash/hash_generic.h"
|
||||
#endif
|
||||
#include "hash/sha1.h"
|
||||
|
||||
int git_hash_global_init(void);
|
||||
|
||||
|
||||
27
src/hash/sha1.h
Normal file
27
src/hash/sha1.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) the libgit2 contributors. All rights reserved.
|
||||
*
|
||||
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_sha1_h__
|
||||
#define INCLUDE_hash_sha1_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(GIT_SHA1_COLLISIONDETECT)
|
||||
# include "sha1/collisiondetect.h"
|
||||
#elif defined(GIT_SHA1_COMMON_CRYPTO)
|
||||
# include "sha1/common_crypto.h"
|
||||
#elif defined(GIT_SHA1_OPENSSL)
|
||||
# include "sha1/openssl.h"
|
||||
#elif defined(GIT_SHA1_WIN32)
|
||||
# include "sha1/win32.h"
|
||||
#elif defined(GIT_SHA1_MBEDTLS)
|
||||
# include "sha1/mbedtls.h"
|
||||
#else
|
||||
# include "sha1/generic.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "hash_collisiondetect.h"
|
||||
#include "collisiondetect.h"
|
||||
|
||||
int git_hash_global_init(void)
|
||||
{
|
||||
@@ -5,8 +5,8 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_hash_collisiondetect_h__
|
||||
#define INCLUDE_hash_hash_collisiondetect_h__
|
||||
#ifndef INCLUDE_hash_sha1_collisiondetect_h__
|
||||
#define INCLUDE_hash_sha1_collisiondetect_h__
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "hash_common_crypto.h"
|
||||
#include "common_crypto.h"
|
||||
|
||||
#define CC_LONG_MAX ((CC_LONG)-1)
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_hash_common_crypto_h__
|
||||
#define INCLUDE_hash_hash_common_crypto_h__
|
||||
#ifndef INCLUDE_hash_sha1_common_crypto_h__
|
||||
#define INCLUDE_hash_sha1_common_crypto_h__
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "hash_generic.h"
|
||||
#include "generic.h"
|
||||
|
||||
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_hash_generic_h__
|
||||
#define INCLUDE_hash_hash_generic_h__
|
||||
#ifndef INCLUDE_hash_sha1_generic_h__
|
||||
#define INCLUDE_hash_sha1_generic_h__
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "hash.h"
|
||||
#include "hash/hash_mbedtls.h"
|
||||
#include "mbedtls.h"
|
||||
|
||||
int git_hash_global_init(void)
|
||||
{
|
||||
@@ -5,8 +5,8 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_mbedtld_h__
|
||||
#define INCLUDE_hash_mbedtld_h__
|
||||
#ifndef INCLUDE_hash_sha1_mbedtls_h__
|
||||
#define INCLUDE_hash_sha1_mbedtls_h__
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
@@ -16,4 +16,4 @@ struct git_hash_ctx {
|
||||
mbedtls_sha1_context c;
|
||||
};
|
||||
|
||||
#endif /* INCLUDE_hash_mbedtld_h__ */
|
||||
#endif /* INCLUDE_hash_sha1_mbedtls_h__ */
|
||||
@@ -5,7 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "hash_openssl.h"
|
||||
#include "openssl.h"
|
||||
|
||||
int git_hash_global_init(void)
|
||||
{
|
||||
@@ -5,8 +5,8 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_hash_hash_openssl_h__
|
||||
#define INCLUDE_hash_hash_openssl_h__
|
||||
#ifndef INCLUDE_hash_sha1_openssl_h__
|
||||
#define INCLUDE_hash_sha1_openssl_h__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
|
||||
#include "hash_win32.h"
|
||||
#include "win32.h"
|
||||
|
||||
#include "global.h"
|
||||
|
||||
Reference in New Issue
Block a user