From 0bc0e0f562180d03edd862266dca8ff5e6b5d966 Mon Sep 17 00:00:00 2001 From: Eric Blankenhorn Date: Fri, 7 May 2021 09:12:22 -0500 Subject: [PATCH 1/2] Fix XMALLOC of sp_point_256 array --- wolfcrypt/src/sp_arm32.c | 2 +- wolfcrypt/src/sp_armthumb.c | 2 +- wolfcrypt/src/sp_cortexm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index feed015d3..13a441557 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -32596,7 +32596,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 16 + 1, + t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index 24276ebf1..fc979ec73 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -17891,7 +17891,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 16 + 1, + t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index c19f856ef..36a980ed6 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -18021,7 +18021,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 16 + 1, + t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; From 3807304243b983014f4507bb7ea150d3aae6da07 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 7 May 2021 09:43:17 -0700 Subject: [PATCH 2/2] Fixes in additional places for incorrect point heap allocation size in SP `ecc_mulmod` with small stack or SP no malloc. --- wolfcrypt/src/sp_arm32.c | 4 ++-- wolfcrypt/src/sp_armthumb.c | 4 ++-- wolfcrypt/src/sp_cortexm.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 13a441557..c14a231ad 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -41750,7 +41750,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 16 + 1, + t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -54451,7 +54451,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 16 + 1, + t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index fc979ec73..9f1a198c4 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -25530,7 +25530,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 16 + 1, + t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -36014,7 +36014,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 16 + 1, + t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 36a980ed6..7d08726d6 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -25154,7 +25154,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 16 + 1, + t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -33853,7 +33853,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)heap; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) - t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 16 + 1, + t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E;