Skip to content

Commit 7569cfd

Browse files
committed
src/internal.c,src/wolfio.c: fallback to SHA256 when NO_SHA, in LoadCertByIssuer(), MicriumGenerateCookie(), uIPGenerateCookie(), and GNRC_GenerateCookie();
tests/api.c: when NO_SHA, omit test_wolfSSL_CertManagerCheckOCSPResponse() and test_wolfSSL_CheckOCSPResponse() (both use static artifacts with SHA1 name and key hashes).
1 parent 6a3451c commit 7569cfd

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/internal.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13219,9 +13219,11 @@ int LoadCertByIssuer(WOLFSSL_X509_STORE* store, X509_NAME* issuer, int type)
1321913219

1322013220
len = wolfSSL_i2d_X509_NAME_canon(issuer, &pbuf);
1322113221
if (len > 0) {
13222-
#ifndef NO_SHA
13222+
#if defined(NO_SHA) && !defined(NO_SHA256)
13223+
retHash = wc_Sha256Hash((const byte*)pbuf, len, dgt);
13224+
#elif !defined(NO_SHA)
1322313225
retHash = wc_ShaHash((const byte*)pbuf, len, dgt);
13224-
#endif
13226+
#endif
1322513227
if (retHash == 0) {
1322613228
/* 4 bytes in little endian as unsigned long */
1322713229
hash = (((unsigned long)dgt[3] << 24) |

src/wolfio.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,11 @@ int MicriumGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
25052505
return GEN_COOKIE_E;
25062506
}
25072507

2508+
#if defined(NO_SHA) && !defined(NO_SHA256)
2509+
ret = wc_Sha256Hash((byte*)&peer, peerSz, digest);
2510+
#else
25082511
ret = wc_ShaHash((byte*)&peer, peerSz, digest);
2512+
#endif
25092513
if (ret != 0)
25102514
return ret;
25112515

@@ -2813,7 +2817,11 @@ int uIPGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
28132817
XMEMSET(token, 0, sizeof(token));
28142818
XMEMCPY(token, &ctx->peer_addr, sizeof(uip_ipaddr_t));
28152819
XMEMCPY(token + sizeof(uip_ipaddr_t), &ctx->peer_port, sizeof(word16));
2820+
#if defined(NO_SHA) && !defined(NO_SHA256)
2821+
ret = wc_Sha256Hash(token, sizeof(uip_ipaddr_t) + sizeof(word16), digest);
2822+
#else
28162823
ret = wc_ShaHash(token, sizeof(uip_ipaddr_t) + sizeof(word16), digest);
2824+
#endif
28172825
if (ret != 0)
28182826
return ret;
28192827
if (sz > WC_SHA_DIGEST_SIZE)
@@ -2895,7 +2903,11 @@ int GNRC_GenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
28952903
token_size = GNRC_MAX_TOKEN_SIZE;
28962904
XMEMSET(token, 0, GNRC_MAX_TOKEN_SIZE);
28972905
XMEMCPY(token, &ctx->peer_addr, token_size);
2906+
#if defined(NO_SHA) && !defined(NO_SHA256)
2907+
ret = wc_Sha256Hash(token, token_size, digest);
2908+
#else
28982909
ret = wc_ShaHash(token, token_size, digest);
2910+
#endif
28992911
if (ret != 0)
29002912
return ret;
29012913
if (sz > WC_SHA_DIGEST_SIZE)

tests/api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,7 +3196,7 @@ static int test_wolfSSL_CertManagerCRL(void)
31963196
static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
31973197
{
31983198
EXPECT_DECLS;
3199-
#if defined(HAVE_OCSP) && !defined(NO_RSA)
3199+
#if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
32003200
/* Need one of these for wolfSSL_OCSP_REQUEST_new. */
32013201
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
32023202
defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
@@ -3516,7 +3516,8 @@ static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
35163516
static int test_wolfSSL_CheckOCSPResponse(void)
35173517
{
35183518
EXPECT_DECLS;
3519-
#if defined(HAVE_OCSP) && !defined(NO_RSA) && defined(OPENSSL_ALL)
3519+
#if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA) && \
3520+
defined(OPENSSL_ALL)
35203521
const char* responseFile = "./certs/ocsp/test-response.der";
35213522
const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
35223523
const char* responseNoInternFile =

0 commit comments

Comments
 (0)