diff --git a/src/ssl.c b/src/ssl.c index 17a780c0d..fe0889d2b 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -28708,16 +28708,38 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl) defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) \ || defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) -#ifndef NO_WOLFSSL_STUB unsigned char *wolfSSL_SHA1(const unsigned char *d, size_t n, unsigned char *md) { - (void) *d; (void) n; (void) *md; - WOLFSSL_ENTER("wolfSSL_SHA1"); - WOLFSSL_STUB("SHA1"); + static byte dig[SHA_DIGEST_SIZE]; + Sha sha; - return NULL; + WOLFSSL_ENTER("wolfSSL_SHA1"); + + if (wc_InitSha_ex(&sha, NULL, 0) != 0) { + WOLFSSL_MSG("SHA1 Init failed"); + return NULL; + } + + if (wc_ShaUpdate(&sha, (const byte*)d, (word32)n) != 0) { + WOLFSSL_MSG("SHA1 Update failed"); + return NULL; + } + + if (wc_ShaFinal(&sha, dig) != 0) { + WOLFSSL_MSG("SHA1 Final failed"); + return NULL; + } + + wc_ShaFree(&sha); + + if (md != NULL) { + XMEMCPY(md, dig, SHA_DIGEST_SIZE); + return md; + } + else { + return (unsigned char*)dig; + } } -#endif char wolfSSL_CTX_use_certificate(WOLFSSL_CTX *ctx, WOLFSSL_X509 *x) { diff --git a/tests/api.c b/tests/api.c index 56338b590..305ff7061 100644 --- a/tests/api.c +++ b/tests/api.c @@ -16158,6 +16158,27 @@ static void test_wolfSSL_msg_callback(void) #endif } +static void test_wolfSSL_SHA(void) +{ +#if defined(OPENSSL_EXTRA) + printf(testingFmt, "wolfSSL_SHA()"); + + #if !defined(NO_SHA) + { + const unsigned char in[] = "abc"; + unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E" + "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D"; + unsigned char out[SHA_DIGEST_SIZE]; + + XMEMSET(out, 0, SHA_DIGEST_SIZE); + AssertNotNull(SHA1(in, XSTRLEN((char*)in), out)); + AssertIntEQ(XMEMCMP(out, expected, SHA_DIGEST_SIZE), 0); + } + #endif + printf(resultFmt, passed); +#endif +} + static void test_no_op_functions(void) { #if defined(OPENSSL_EXTRA) @@ -16982,6 +17003,7 @@ void ApiTest(void) test_wolfSSL_verify_depth(); test_wolfSSL_HMAC_CTX(); test_wolfSSL_msg_callback(); + test_wolfSSL_SHA(); /* test the no op functions for compatibility */ test_no_op_functions();