minor fixes to accommodate --disable-sha in combination with --enable-all-crypto.

This commit is contained in:
Daniel Pouzzner
2022-12-20 00:42:05 -06:00
parent 6f7d8d287d
commit 91869f6028
7 changed files with 144 additions and 37 deletions
+26 -4
View File
@@ -330,7 +330,7 @@ static unsigned long wolfSSL_CONF_VALUE_hash(const WOLFSSL_CONF_VALUE *val)
return 0;
}
/* Use SHA for hashing as OpenSSL uses a hash algorithm that is
/* Use SHA[256] for hashing as OpenSSL uses a hash algorithm that is
* "not as good as MD5, but still good" so using SHA should be more
* than good enough for this application. The produced hashes don't
* need to line up between OpenSSL and wolfSSL. The hashes are for
@@ -338,19 +338,22 @@ static unsigned long wolfSSL_CONF_VALUE_hash(const WOLFSSL_CONF_VALUE *val)
unsigned long wolfSSL_LH_strhash(const char *str)
{
unsigned long ret = 0;
#ifndef NO_SHA
#if !defined(NO_SHA)
wc_Sha sha;
int strLen;
byte digest[WC_SHA_DIGEST_SIZE];
#elif !defined(NO_SHA256)
wc_Sha256 sha;
int strLen;
byte digest[WC_SHA256_DIGEST_SIZE];
#endif
WOLFSSL_ENTER("wolfSSL_LH_strhash");
if (!str)
return 0;
#ifndef NO_SHA
strLen = (int)XSTRLEN(str);
#if !defined(NO_SHA)
if (wc_InitSha_ex(&sha, NULL, 0) != 0) {
WOLFSSL_MSG("SHA1 Init failed");
return 0;
@@ -366,6 +369,25 @@ unsigned long wolfSSL_LH_strhash(const char *str)
}
}
wc_ShaFree(&sha);
#elif !defined(NO_SHA256)
if (wc_InitSha256_ex(&sha, NULL, 0) != 0) {
WOLFSSL_MSG("SHA256 Init failed");
return 0;
}
ret = wc_Sha256Update(&sha, (const byte *)str, (word32)strLen);
if (ret != 0) {
WOLFSSL_MSG("SHA256 Update failed");
} else {
ret = wc_Sha256Final(&sha, digest);
if (ret != 0) {
WOLFSSL_MSG("SHA256 Final failed");
}
}
wc_Sha256Free(&sha);
#endif
#if !defined(NO_SHA) || !defined(NO_SHA256)
if (ret != 0)
return 0;