From 3008c888bf0537fc87c9a3d45db4abc43136ed6a Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 1 Feb 2017 13:08:17 -0800 Subject: [PATCH] Fix mp_cmp_d logic to handle a->used == 0. Revert mp_copy and mp_set 0 size workarounds. --- wolfcrypt/src/integer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index e4be0c7b1..5afc43693 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -317,7 +317,7 @@ int mp_copy (mp_int * a, mp_int * b) } /* grow dest */ - if (b->alloc < a->used || a->used == 0) { + if (b->alloc < a->used) { if ((res = mp_grow (b, a->used)) != MP_OKAY) { return res; } @@ -360,7 +360,7 @@ int mp_grow (mp_int * a, int size) mp_digit *tmp; /* if the alloc size is smaller alloc more ram */ - if (a->alloc < size || size == 0) { + if (a->alloc < size) { /* ensure there are always at least MP_PREC digits extra on top */ size += (MP_PREC * 2) - (size % MP_PREC); @@ -1283,8 +1283,12 @@ int mp_cmp (mp_int * a, mp_int * b) /* compare a digit */ int mp_cmp_d(mp_int * a, mp_digit b) { + /* special case for zero*/ + if (a->used == 0 && b == 0) + return MP_EQ; + /* compare based on sign */ - if (a->sign == MP_NEG) { + if ((b && a->used == 0) || a->sign == MP_NEG) { return MP_LT; }