Skip to content

Commit fda2062

Browse files
committed
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.
1 parent bd48bf3 commit fda2062

File tree

19 files changed

+52
-38
lines changed

19 files changed

+52
-38
lines changed

cmake/Modules/SelectHashes.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ IF(SHA1_BACKEND STREQUAL "CollisionDetection")
3030
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
3131
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
3232
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
33-
FILE(GLOB SRC_SHA1 hash/hash_collisiondetect.c hash/sha1dc/*)
33+
FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.c hash/sha1/sha1dc/*)
3434
ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
3535
# OPENSSL_FOUND should already be set, we're checking HTTPS_BACKEND
3636

@@ -40,13 +40,13 @@ ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
4040
ELSE()
4141
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
4242
ENDIF()
43-
FILE(GLOB SRC_SHA1 hash/hash_openssl.c)
43+
FILE(GLOB SRC_SHA1 hash/sha1/openssl.c)
4444
ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
4545
SET(GIT_SHA1_COMMON_CRYPTO 1)
46-
FILE(GLOB SRC_SHA1 hash/hash_common_crypto.c)
46+
FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.c)
4747
ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
4848
SET(GIT_SHA1_MBEDTLS 1)
49-
FILE(GLOB SRC_SHA1 hash/hash_mbedtls.c)
49+
FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.c)
5050
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
5151
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
5252
# mbedTLS has no pkgconfig file, hence we can't require it
@@ -55,9 +55,9 @@ ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
5555
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
5656
ELSEIF(SHA1_BACKEND STREQUAL "Win32")
5757
SET(GIT_SHA1_WIN32 1)
58-
FILE(GLOB SRC_SHA1 hash/hash_win32.c)
58+
FILE(GLOB SRC_SHA1 hash/sha1/win32.c)
5959
ELSEIF(SHA1_BACKEND STREQUAL "Generic")
60-
FILE(GLOB SRC_SHA1 hash/hash_generic.c)
60+
FILE(GLOB SRC_SHA1 hash/sha1/generic.c)
6161
# ELSEIF(NOT USE_SHA1)
6262
ELSE()
6363
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${SHA1_BACKEND}")

src/hash.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* This file is part of libgit2, distributed under the GNU GPL v2 with
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
7+
78
#ifndef INCLUDE_hash_h__
89
#define INCLUDE_hash_h__
910

@@ -18,19 +19,7 @@ typedef struct {
1819
size_t len;
1920
} git_buf_vec;
2021

21-
#if defined(GIT_SHA1_COLLISIONDETECT)
22-
# include "hash/hash_collisiondetect.h"
23-
#elif defined(GIT_SHA1_COMMON_CRYPTO)
24-
# include "hash/hash_common_crypto.h"
25-
#elif defined(GIT_SHA1_OPENSSL)
26-
# include "hash/hash_openssl.h"
27-
#elif defined(GIT_SHA1_WIN32)
28-
# include "hash/hash_win32.h"
29-
#elif defined(GIT_SHA1_MBEDTLS)
30-
# include "hash/hash_mbedtls.h"
31-
#else
32-
# include "hash/hash_generic.h"
33-
#endif
22+
#include "hash/sha1.h"
3423

3524
int git_hash_global_init(void);
3625

src/hash/sha1.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#ifndef INCLUDE_hash_sha1_h__
9+
#define INCLUDE_hash_sha1_h__
10+
11+
#include "common.h"
12+
13+
#if defined(GIT_SHA1_COLLISIONDETECT)
14+
# include "sha1/collisiondetect.h"
15+
#elif defined(GIT_SHA1_COMMON_CRYPTO)
16+
# include "sha1/common_crypto.h"
17+
#elif defined(GIT_SHA1_OPENSSL)
18+
# include "sha1/openssl.h"
19+
#elif defined(GIT_SHA1_WIN32)
20+
# include "sha1/win32.h"
21+
#elif defined(GIT_SHA1_MBEDTLS)
22+
# include "sha1/mbedtls.h"
23+
#else
24+
# include "sha1/generic.h"
25+
#endif
26+
27+
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#include "hash_collisiondetect.h"
8+
#include "collisiondetect.h"
99

1010
int git_hash_global_init(void)
1111
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#ifndef INCLUDE_hash_hash_collisiondetect_h__
9-
#define INCLUDE_hash_hash_collisiondetect_h__
8+
#ifndef INCLUDE_hash_sha1_collisiondetect_h__
9+
#define INCLUDE_hash_sha1_collisiondetect_h__
1010

1111
#include "hash.h"
1212

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#include "hash_common_crypto.h"
8+
#include "common_crypto.h"
99

1010
#define CC_LONG_MAX ((CC_LONG)-1)
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#ifndef INCLUDE_hash_hash_common_crypto_h__
9-
#define INCLUDE_hash_hash_common_crypto_h__
8+
#ifndef INCLUDE_hash_sha1_common_crypto_h__
9+
#define INCLUDE_hash_sha1_common_crypto_h__
1010

1111
#include "hash.h"
1212

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#include "hash_generic.h"
8+
#include "generic.h"
99

1010
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#ifndef INCLUDE_hash_hash_generic_h__
9-
#define INCLUDE_hash_hash_generic_h__
8+
#ifndef INCLUDE_hash_sha1_generic_h__
9+
#define INCLUDE_hash_sha1_generic_h__
1010

1111
#include "hash.h"
1212

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#include "common.h"
9-
#include "hash.h"
10-
#include "hash/hash_mbedtls.h"
8+
#include "mbedtls.h"
119

1210
int git_hash_global_init(void)
1311
{

0 commit comments

Comments
 (0)