Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
cd8fde82
Unverified
Commit
cd8fde82
authored
Apr 05, 2022
by
Edward Thomson
Committed by
GitHub
Apr 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6258 from libgit2/ethomson/sha256_openssl_dynamic
sha256: support dynamically loaded openssl
parents
d8015d28
3bd9bb8d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
3 deletions
+107
-3
cmake/SelectHashes.cmake
+8
-0
src/features.h.in
+2
-0
src/util/CMakeLists.txt
+2
-2
src/util/hash/openssl.c
+76
-0
src/util/hash/openssl.h
+19
-1
No files found.
cmake/SelectHashes.cmake
View file @
cd8fde82
...
...
@@ -26,6 +26,10 @@ if(USE_SHA1 STREQUAL "CollisionDetection")
set
(
GIT_SHA1_COLLISIONDETECT 1
)
elseif
(
USE_SHA1 STREQUAL
"OpenSSL"
)
set
(
GIT_SHA1_OPENSSL 1
)
elseif
(
USE_SHA1 STREQUAL
"OpenSSL-Dynamic"
)
set
(
GIT_SHA1_OPENSSL 1
)
set
(
GIT_SHA1_OPENSSL_DYNAMIC 1
)
list
(
APPEND LIBGIT2_SYSTEM_LIBS dl
)
elseif
(
USE_SHA1 STREQUAL
"CommonCrypto"
)
set
(
GIT_SHA1_COMMON_CRYPTO 1
)
elseif
(
USE_SHA1 STREQUAL
"mbedTLS"
)
...
...
@@ -58,6 +62,10 @@ if(USE_SHA256 STREQUAL "Builtin")
set
(
GIT_SHA256_BUILTIN 1
)
elseif
(
USE_SHA256 STREQUAL
"OpenSSL"
)
set
(
GIT_SHA256_OPENSSL 1
)
elseif
(
USE_SHA256 STREQUAL
"OpenSSL-Dynamic"
)
set
(
GIT_SHA256_OPENSSL 1
)
set
(
GIT_SHA256_OPENSSL_DYNAMIC 1
)
list
(
APPEND LIBGIT2_SYSTEM_LIBS dl
)
elseif
(
USE_SHA256 STREQUAL
"CommonCrypto"
)
set
(
GIT_SHA256_COMMON_CRYPTO 1
)
elseif
(
USE_SHA256 STREQUAL
"mbedTLS"
)
...
...
src/features.h.in
View file @
cd8fde82
...
...
@@ -46,12 +46,14 @@
#cmakedefine GIT_SHA1_WIN32 1
#cmakedefine GIT_SHA1_COMMON_CRYPTO 1
#cmakedefine GIT_SHA1_OPENSSL 1
#cmakedefine GIT_SHA1_OPENSSL_DYNAMIC 1
#cmakedefine GIT_SHA1_MBEDTLS 1
#cmakedefine GIT_SHA256_BUILTIN 1
#cmakedefine GIT_SHA256_WIN32 1
#cmakedefine GIT_SHA256_COMMON_CRYPTO 1
#cmakedefine GIT_SHA256_OPENSSL 1
#cmakedefine GIT_SHA256_OPENSSL_DYNAMIC 1
#cmakedefine GIT_SHA256_MBEDTLS 1
#cmakedefine GIT_RAND_GETENTROPY 1
...
...
src/util/CMakeLists.txt
View file @
cd8fde82
...
...
@@ -33,7 +33,7 @@ if(USE_SHA1 STREQUAL "CollisionDetection")
target_compile_definitions
(
util PRIVATE SHA1DC_NO_STANDARD_INCLUDES=1
)
target_compile_definitions
(
util PRIVATE SHA1DC_CUSTOM_INCLUDE_SHA1_C=\
"git2_util.h
\"
)
target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=
\"
git2_util.h
\"
)
elseif(USE_SHA1 STREQUAL "
OpenSSL
")
elseif(USE_SHA1 STREQUAL "
OpenSSL
"
OR USE_SHA1 STREQUAL "
OpenSSL-Dynamic
"
)
file(GLOB UTIL_SRC_SHA1 hash/openssl.*)
elseif(USE_SHA1 STREQUAL "
CommonCrypto
")
file(GLOB UTIL_SRC_SHA1 hash/common_crypto.*)
...
...
@@ -49,7 +49,7 @@ list(SORT UTIL_SRC_SHA1)
if(USE_SHA256 STREQUAL "
Builtin
")
file(GLOB UTIL_SRC_SHA256 hash/builtin.* hash/rfc6234/*)
elseif(USE_SHA256 STREQUAL "
OpenSSL
")
elseif(USE_SHA256 STREQUAL "
OpenSSL
"
OR USE_SHA256 STREQUAL "
OpenSSL-Dynamic
"
)
file(GLOB UTIL_SRC_SHA256 hash/openssl.*)
elseif(USE_SHA256 STREQUAL "
CommonCrypto
")
file(GLOB UTIL_SRC_SHA256 hash/common_crypto.*)
...
...
src/util/hash/openssl.c
View file @
cd8fde82
...
...
@@ -7,10 +7,67 @@
#include "openssl.h"
#ifdef GIT_OPENSSL_DYNAMIC
# include <dlfcn.h>
int
handle_count
;
void
*
openssl_handle
;
static
int
git_hash_openssl_global_shutdown
(
void
)
{
if
(
--
handle_count
==
0
)
{
dlclose
(
openssl_handle
);
openssl_handle
=
NULL
;
}
return
0
;
}
static
int
git_hash_openssl_global_init
(
void
)
{
if
(
!
handle_count
)
{
if
((
openssl_handle
=
dlopen
(
"libssl.so.1.1"
,
RTLD_NOW
))
==
NULL
&&
(
openssl_handle
=
dlopen
(
"libssl.1.1.dylib"
,
RTLD_NOW
))
==
NULL
&&
(
openssl_handle
=
dlopen
(
"libssl.so.1.0.0"
,
RTLD_NOW
))
==
NULL
&&
(
openssl_handle
=
dlopen
(
"libssl.1.0.0.dylib"
,
RTLD_NOW
))
==
NULL
&&
(
openssl_handle
=
dlopen
(
"libssl.so.10"
,
RTLD_NOW
))
==
NULL
)
{
git_error_set
(
GIT_ERROR_SSL
,
"could not load ssl libraries"
);
return
-
1
;
}
}
if
(
git_hash_openssl_global_shutdown
()
<
0
)
return
-
1
;
handle_count
++
;
return
0
;
}
#endif
#ifdef GIT_SHA1_OPENSSL
# ifdef GIT_OPENSSL_DYNAMIC
static
int
(
*
SHA1_Init
)(
SHA_CTX
*
c
);
static
int
(
*
SHA1_Update
)(
SHA_CTX
*
c
,
const
void
*
data
,
size_t
len
);
static
int
(
*
SHA1_Final
)(
unsigned
char
*
md
,
SHA_CTX
*
c
);
# endif
int
git_hash_sha1_global_init
(
void
)
{
#ifdef GIT_OPENSSL_DYNAMIC
if
(
git_hash_openssl_global_init
()
<
0
)
return
-
1
;
if
((
SHA1_Init
=
dlsym
(
openssl_handle
,
"SHA1_Init"
))
==
NULL
||
(
SHA1_Update
=
dlsym
(
openssl_handle
,
"SHA1_Update"
))
==
NULL
||
(
SHA1_Final
=
dlsym
(
openssl_handle
,
"SHA1_Final"
))
==
NULL
)
{
const
char
*
msg
=
dlerror
();
git_error_set
(
GIT_ERROR_SSL
,
"could not load hash function: %s"
,
msg
?
msg
:
"unknown error"
);
return
-
1
;
}
#endif
return
0
;
}
...
...
@@ -64,8 +121,27 @@ int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
#ifdef GIT_SHA256_OPENSSL
# ifdef GIT_OPENSSL_DYNAMIC
static
int
(
*
SHA256_Init
)(
SHA256_CTX
*
c
);
static
int
(
*
SHA256_Update
)(
SHA256_CTX
*
c
,
const
void
*
data
,
size_t
len
);
static
int
(
*
SHA256_Final
)(
unsigned
char
*
md
,
SHA256_CTX
*
c
);
#endif
int
git_hash_sha256_global_init
(
void
)
{
#ifdef GIT_OPENSSL_DYNAMIC
if
(
git_hash_openssl_global_init
()
<
0
)
return
-
1
;
if
((
SHA256_Init
=
dlsym
(
openssl_handle
,
"SHA256_Init"
))
==
NULL
||
(
SHA256_Update
=
dlsym
(
openssl_handle
,
"SHA256_Update"
))
==
NULL
||
(
SHA256_Final
=
dlsym
(
openssl_handle
,
"SHA256_Final"
))
==
NULL
)
{
const
char
*
msg
=
dlerror
();
git_error_set
(
GIT_ERROR_SSL
,
"could not load hash function: %s"
,
msg
?
msg
:
"unknown error"
);
return
-
1
;
}
#endif
return
0
;
}
...
...
src/util/hash/openssl.h
View file @
cd8fde82
...
...
@@ -10,7 +10,25 @@
#include "hash/sha.h"
#include <openssl/sha.h>
#ifndef GIT_OPENSSL_DYNAMIC
# include <openssl/sha.h>
#else
typedef
struct
{
unsigned
int
h0
,
h1
,
h2
,
h3
,
h4
;
unsigned
int
Nl
,
Nh
;
unsigned
int
data
[
16
];
unsigned
int
num
;
}
SHA_CTX
;
typedef
struct
{
unsigned
int
h
[
8
];
unsigned
int
Nl
,
Nh
;
unsigned
int
data
[
16
];
unsigned
int
num
,
md_len
;
}
SHA256_CTX
;
#endif
#ifdef GIT_SHA1_OPENSSL
struct
git_hash_sha1_ctx
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment