Skip to content

Commit 263973b

Browse files
committed
src/wolfio.c: fix stack allocations for cookie digests on NO_SHA builds;
configure.ac: fix dependencies for enable_dsa vs enable_sha in enable-all, enable-all-crypto, and ENABLED_DSA setup.
1 parent eaa66dc commit 263973b

2 files changed

Lines changed: 37 additions & 16 deletions

File tree

configure.ac

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ then
805805
# sp-math is incompatible with opensslextra, ECC custom curves, and DSA.
806806
if test "$ENABLED_SP_MATH" = "no"
807807
then
808-
test "$enable_dsa" = "" && enable_dsa=yes
808+
test "$enable_dsa" = "" && test "$enable_sha" != "no" && enable_dsa=yes
809809
test "$enable_ecccustcurves" = "" && enable_ecccustcurves=yes
810810
test "$enable_brainpool" = "" && enable_brainpool=yes
811811
test "$enable_srp" = "" && enable_srp=yes
@@ -974,7 +974,7 @@ then
974974

975975
if test "$ENABLED_SP_MATH" = "no"
976976
then
977-
test "$enable_dsa" = "" && enable_dsa=yes
977+
test "$enable_dsa" = "" && test "$enable_sha" != "no" && enable_dsa=yes
978978
test "$enable_ecccustcurves" = "" && enable_ecccustcurves=yes
979979
test "$enable_brainpool" = "" && enable_brainpool=yes
980980
test "$enable_srp" = "" && enable_srp=yes
@@ -3585,7 +3585,7 @@ AC_ARG_ENABLE([dsa],
35853585
[ ENABLED_DSA=no ]
35863586
)
35873587

3588-
if test "$enable_dsa" = ""
3588+
if test "$enable_dsa" = "" && test "$enable_sha" != "no"
35893589
then
35903590
if (test "$ENABLED_OPENSSH" = "yes" && test "x$ENABLED_FIPS" = "xno") || test "$ENABLED_OPENVPN" = "yes" || test "$ENABLED_NGINX" = "yes" || test "$ENABLED_WPAS" = "yes" || test "$ENABLED_QT" = "yes" || test "$ENABLED_BIND" = "yes" || test "$ENABLED_LIBSSH2" = "yes" || test "$ENABLED_NTP" = "yes"
35913591
then
@@ -9725,8 +9725,11 @@ echo " * Secure Renegotiation: $ENABLED_SECURE_RENEGOTIATION"
97259725
echo " * Fallback SCSV: $ENABLED_FALLBACK_SCSV"
97269726
echo " * Keying Material Exporter: $ENABLED_KEYING_MATERIAL"
97279727
echo " * All TLS Extensions: $ENABLED_TLSX"
9728-
echo " * PKCS#7: $ENABLED_PKCS7"
97299728
echo " * S/MIME: $ENABLED_SMIME"
9729+
echo " * PKCS#7: $ENABLED_PKCS7"
9730+
echo " * PKCS#8: $ENABLED_PKCS8"
9731+
echo " * PKCS#11: $ENABLED_PKCS11"
9732+
echo " * PKCS#12: $ENABLED_PKCS12"
97309733
echo " * wolfSSH: $ENABLED_WOLFSSH"
97319734
echo " * wolfEngine: $ENABLED_WOLFENGINE"
97329735
echo " * wolfTPM: $ENABLED_WOLFTPM"
@@ -9745,9 +9748,6 @@ echo " * User Crypto: $ENABLED_USER_CRYPTO"
97459748
echo " * Fast RSA: $ENABLED_FAST_RSA"
97469749
echo " * Asynchronous Crypto: $ENABLED_ASYNCCRYPT"
97479750
echo " * Asynchronous Crypto (sim): $ENABLED_ASYNCCRYPT_SW"
9748-
echo " * PKCS#8: $ENABLED_PKCS8"
9749-
echo " * PKCS#11: $ENABLED_PKCS11"
9750-
echo " * PKCS#12: $ENABLED_PKCS12"
97519751
echo " * Cavium Nitrox: $ENABLED_CAVIUM"
97529752
echo " * Cavium Octeon (Sync): $ENABLED_OCTEON_SYNC"
97539753
echo " * Intel Quick Assist: $ENABLED_INTEL_QA"

src/wolfio.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,11 +2489,18 @@ int MicriumSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
24892489
/* Micrium DTLS Generate Cookie callback
24902490
* return : number of bytes copied into buf, or error
24912491
*/
2492+
#if defined(NO_SHA) && !defined(NO_SHA256)
2493+
#define MICRIUM_COOKIE_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
2494+
#elif !defined(NO_SHA)
2495+
#define MICRIUM_COOKIE_DIGEST_SIZE WC_SHA_DIGEST_SIZE
2496+
#else
2497+
#error Must enable either SHA-1 or SHA256 (or both) for Micrium.
2498+
#endif
24922499
int MicriumGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
24932500
{
24942501
NET_SOCK_ADDR peer;
24952502
NET_SOCK_ADDR_LEN peerSz = sizeof(peer);
2496-
byte digest[WC_SHA_DIGEST_SIZE];
2503+
byte digest[MICRIUM_COOKIE_DIGEST_SIZE];
24972504
int ret = 0;
24982505

24992506
(void)ctx;
@@ -2513,8 +2520,8 @@ int MicriumGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
25132520
if (ret != 0)
25142521
return ret;
25152522

2516-
if (sz > WC_SHA_DIGEST_SIZE)
2517-
sz = WC_SHA_DIGEST_SIZE;
2523+
if (sz > MICRIUM_COOKIE_DIGEST_SIZE)
2524+
sz = MICRIUM_COOKIE_DIGEST_SIZE;
25182525
XMEMCPY(buf, digest, sz);
25192526

25202527
return sz;
@@ -2808,11 +2815,18 @@ int uIPReceive(WOLFSSL *ssl, char *buf, int sz, void *_ctx)
28082815
/* uIP DTLS Generate Cookie callback
28092816
* return : number of bytes copied into buf, or error
28102817
*/
2818+
#if defined(NO_SHA) && !defined(NO_SHA256)
2819+
#define UIP_COOKIE_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
2820+
#elif !defined(NO_SHA)
2821+
#define UIP_COOKIE_DIGEST_SIZE WC_SHA_DIGEST_SIZE
2822+
#else
2823+
#error Must enable either SHA-1 or SHA256 (or both) for uIP.
2824+
#endif
28112825
int uIPGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
28122826
{
28132827
uip_wolfssl_ctx *ctx = (uip_wolfssl_ctx *)_ctx;
28142828
byte token[32];
2815-
byte digest[WC_SHA_DIGEST_SIZE];
2829+
byte digest[UIP_COOKIE_DIGEST_SIZE];
28162830
int ret = 0;
28172831
XMEMSET(token, 0, sizeof(token));
28182832
XMEMCPY(token, &ctx->peer_addr, sizeof(uip_ipaddr_t));
@@ -2824,8 +2838,8 @@ int uIPGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
28242838
#endif
28252839
if (ret != 0)
28262840
return ret;
2827-
if (sz > WC_SHA_DIGEST_SIZE)
2828-
sz = WC_SHA_DIGEST_SIZE;
2841+
if (sz > UIP_COOKIE_DIGEST_SIZE)
2842+
sz = UIP_COOKIE_DIGEST_SIZE;
28292843
XMEMCPY(buf, digest, sz);
28302844
return sz;
28312845
}
@@ -2889,13 +2903,20 @@ int GNRC_ReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *_ctx)
28892903
* return : number of bytes copied into buf, or error
28902904
*/
28912905
#define GNRC_MAX_TOKEN_SIZE (32)
2906+
#if defined(NO_SHA) && !defined(NO_SHA256)
2907+
#define GNRC_COOKIE_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
2908+
#elif !defined(NO_SHA)
2909+
#define GNRC_COOKIE_DIGEST_SIZE WC_SHA_DIGEST_SIZE
2910+
#else
2911+
#error Must enable either SHA-1 or SHA256 (or both) for GNRC.
2912+
#endif
28922913
int GNRC_GenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
28932914
{
28942915
sock_tls_t *ctx = (sock_tls_t *)_ctx;
28952916
if (!ctx)
28962917
return WOLFSSL_CBIO_ERR_GENERAL;
28972918
byte token[GNRC_MAX_TOKEN_SIZE];
2898-
byte digest[WC_SHA_DIGEST_SIZE];
2919+
byte digest[GNRC_COOKIE_DIGEST_SIZE];
28992920
int ret = 0;
29002921
size_t token_size = sizeof(sock_udp_ep_t);
29012922
(void)ssl;
@@ -2910,8 +2931,8 @@ int GNRC_GenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *_ctx)
29102931
#endif
29112932
if (ret != 0)
29122933
return ret;
2913-
if (sz > WC_SHA_DIGEST_SIZE)
2914-
sz = WC_SHA_DIGEST_SIZE;
2934+
if (sz > GNRC_COOKIE_DIGEST_SIZE)
2935+
sz = GNRC_COOKIE_DIGEST_SIZE;
29152936
XMEMCPY(buf, digest, sz);
29162937
return sz;
29172938
}

0 commit comments

Comments
 (0)