forked from wolfSSL/wolfssl
SHA1 implementation and test
This commit is contained in:
34
src/ssl.c
34
src/ssl.c
@@ -28708,16 +28708,38 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
|||||||
defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) \
|
defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) \
|
||||||
|| defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
|
|| defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
|
||||||
|
|
||||||
#ifndef NO_WOLFSSL_STUB
|
|
||||||
unsigned char *wolfSSL_SHA1(const unsigned char *d, size_t n, unsigned char *md)
|
unsigned char *wolfSSL_SHA1(const unsigned char *d, size_t n, unsigned char *md)
|
||||||
{
|
{
|
||||||
(void) *d; (void) n; (void) *md;
|
static byte dig[SHA_DIGEST_SIZE];
|
||||||
WOLFSSL_ENTER("wolfSSL_SHA1");
|
Sha sha;
|
||||||
WOLFSSL_STUB("SHA1");
|
|
||||||
|
|
||||||
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)
|
char wolfSSL_CTX_use_certificate(WOLFSSL_CTX *ctx, WOLFSSL_X509 *x)
|
||||||
{
|
{
|
||||||
|
22
tests/api.c
22
tests/api.c
@@ -16158,6 +16158,27 @@ static void test_wolfSSL_msg_callback(void)
|
|||||||
#endif
|
#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)
|
static void test_no_op_functions(void)
|
||||||
{
|
{
|
||||||
#if defined(OPENSSL_EXTRA)
|
#if defined(OPENSSL_EXTRA)
|
||||||
@@ -16982,6 +17003,7 @@ void ApiTest(void)
|
|||||||
test_wolfSSL_verify_depth();
|
test_wolfSSL_verify_depth();
|
||||||
test_wolfSSL_HMAC_CTX();
|
test_wolfSSL_HMAC_CTX();
|
||||||
test_wolfSSL_msg_callback();
|
test_wolfSSL_msg_callback();
|
||||||
|
test_wolfSSL_SHA();
|
||||||
|
|
||||||
/* test the no op functions for compatibility */
|
/* test the no op functions for compatibility */
|
||||||
test_no_op_functions();
|
test_no_op_functions();
|
||||||
|
Reference in New Issue
Block a user