From 3843a8d114fff316a52e63d18a4cb623547f2fae Mon Sep 17 00:00:00 2001 From: LDA Date: Fri, 16 Aug 2024 18:22:53 +0200 Subject: [PATCH] [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