From a7e585b63dff0836d5623d273e4a8196212f3332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moise=CC=81s=20Guimara=CC=83es?= Date: Fri, 17 Oct 2014 16:31:09 -0300 Subject: [PATCH] internal.c: refactoring BuildMessage to reduce stack usage: --- variable hmac moved to the heap (up to 64 bytes saved) --- src/internal.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 4546c143d..4ccda921a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6928,11 +6928,26 @@ static int BuildMessage(CYASSL* ssl, byte* output, int outSz, if (ssl->specs.cipher_type != aead) { #ifdef HAVE_TRUNCATED_HMAC if (ssl->truncated_hmac && ssl->specs.hash_size > digestSz) { - byte hmac[MAX_DIGEST_SIZE]; + #ifdef CYASSL_SMALL_STACK + byte* hmac = NULL; + #else + byte hmac[MAX_DIGEST_SIZE]; + #endif + + #ifdef CYASSL_SMALL_STACK + hmac = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (hmac == NULL) + return MEMORY_E; + #endif ret = ssl->hmac(ssl, hmac, output + headerSz + ivSz, inSz, - type, 0); + type, 0); XMEMCPY(output + idx, hmac, digestSz); + + #ifdef CYASSL_SMALL_STACK + XFREE(hmac, NULL, DYNAMIC_TYPE_TMP_BUFFER); + #endif } else #endif ret = ssl->hmac(ssl, output+idx, output + headerSz + ivSz, inSz,