From 3843a8d114fff316a52e63d18a4cb623547f2fae Mon Sep 17 00:00:00 2001 From: LDA Date: Fri, 16 Aug 2024 18:22:53 +0200 Subject: [PATCH 1/3] [MOD/WIP] Get SHA to use Open/LibreSSL if present I still haven't tested on LibreSSL (Debian doesn't seem to actually like it all that much), but manuals seems to state that they're the same in that regard. If anyone is up to verify, let me know so that I'm aware it's safe to merge it. --- src/Sha/Sha1.c | 21 +++++++++++++++++++++ src/Sha/Sha256.c | 25 ++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Sha/Sha1.c b/src/Sha/Sha1.c index 9e12d56..e565041 100644 --- a/src/Sha/Sha1.c +++ b/src/Sha/Sha1.c @@ -28,6 +28,26 @@ #include +#if (TLS_IMPL == TLS_OPENSSL) || (TLS_IMPL == TLS_LIBRESSL) + +#include + +unsigned char * +Sha1(char *str) +{ + unsigned char *digest; + if (!str) + { + return NULL; + } + + digest = Malloc(20 + 1); + SHA1((unsigned char *) str, strlen(str), digest); + digest[20] = '\0'; + return digest; +} +#else + #define LOAD32H(x, y) \ { \ x = ((uint32_t)((y)[0] & 255) << 24) | \ @@ -264,3 +284,4 @@ Sha1(char *str) return out; } +#endif diff --git a/src/Sha/Sha256.c b/src/Sha/Sha256.c index 2563246..e93600a 100644 --- a/src/Sha/Sha256.c +++ b/src/Sha/Sha256.c @@ -21,14 +21,36 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include #include +#include #include #include #include + +#if (TLS_IMPL == TLS_OPENSSL) || (TLS_IMPL == TLS_LIBRESSL) + +#include +#include + +unsigned char * +Sha256(char *str) +{ + unsigned char *digest; + if (!str) + { + return NULL; + } + + digest = Malloc(32 + 1); + SHA256((unsigned char *) str, strlen(str), digest); + digest[32] = '\0'; + return digest; +} +#else + #define GET_UINT32(x) \ (((uint32_t)(x)[0] << 24) | \ ((uint32_t)(x)[1] << 16) | \ @@ -230,3 +252,4 @@ Sha256(char *str) return out; } +#endif -- 2.45.2 From e8543bdb2a1965298d3b5a6590c85b3b58f2c4f0 Mon Sep 17 00:00:00 2001 From: LDA Date: Fri, 16 Aug 2024 18:26:19 +0200 Subject: [PATCH 2/3] [FIX/WIP] Don't include Log. --- src/Sha/Sha256.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Sha/Sha256.c b/src/Sha/Sha256.c index e93600a..cb56b6c 100644 --- a/src/Sha/Sha256.c +++ b/src/Sha/Sha256.c @@ -33,8 +33,7 @@ #if (TLS_IMPL == TLS_OPENSSL) || (TLS_IMPL == TLS_LIBRESSL) #include -#include - + unsigned char * Sha256(char *str) { -- 2.45.2 From 7752ea7b8612f52acf2abd04f1676354eff9438e Mon Sep 17 00:00:00 2001 From: LDA Date: Fri, 23 Aug 2024 22:45:24 +0200 Subject: [PATCH 3/3] [MOD] Drop LibreSSL "support" in SHA for now We'll test later... --- src/Sha/Sha1.c | 3 ++- src/Sha/Sha256.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Sha/Sha1.c b/src/Sha/Sha1.c index e565041..0b0d327 100644 --- a/src/Sha/Sha1.c +++ b/src/Sha/Sha1.c @@ -28,7 +28,8 @@ #include -#if (TLS_IMPL == TLS_OPENSSL) || (TLS_IMPL == TLS_LIBRESSL) +/* TODO: Verify LibreSSL support later */ +#if TLS_IMPL == TLS_OPENSSL #include diff --git a/src/Sha/Sha256.c b/src/Sha/Sha256.c index cb56b6c..5a1e08c 100644 --- a/src/Sha/Sha256.c +++ b/src/Sha/Sha256.c @@ -30,7 +30,8 @@ #include -#if (TLS_IMPL == TLS_OPENSSL) || (TLS_IMPL == TLS_LIBRESSL) +/* TODO: Verify LibreSSL support later */ +#if TLS_IMPL == TLS_OPENSSL #include -- 2.45.2