From 6d1a11eefbf2ec69b2f8232d6674564c5669d607 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 29 Mar 2019 13:35:27 -0700 Subject: [PATCH] Clang static analysis found a potential issue when checking an ECC key when the curve cache is enabled. There was a chance it could dereference NULL. Added some error checks to fix it. --- wolfcrypt/src/ecc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 4534dbfec..8fa9f4f12 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -6278,17 +6278,22 @@ int wc_ecc_check_key(ecc_key* key) if (err == MP_OKAY) err = mp_read_radix(b, key->dp->Bf, MP_RADIX_HEX); #else - b = curve->Bf; + if (err == MP_OKAY) + b = curve->Bf; #endif /* SP 800-56Ar3, section 5.6.2.3.3, process step 2 */ /* Qx must be in the range [0, p-1] */ - if (mp_cmp(key->pubkey.x, curve->prime) != MP_LT) - err = ECC_OUT_OF_RANGE_E; + if (err == MP_OKAY) { + if (mp_cmp(key->pubkey.x, curve->prime) != MP_LT) + err = ECC_OUT_OF_RANGE_E; + } /* Qy must be in the range [0, p-1] */ - if (mp_cmp(key->pubkey.y, curve->prime) != MP_LT) - err = ECC_OUT_OF_RANGE_E; + if (err == MP_OKAY) { + if (mp_cmp(key->pubkey.y, curve->prime) != MP_LT) + err = ECC_OUT_OF_RANGE_E; + } /* SP 800-56Ar3, section 5.6.2.3.3, process steps 3 */ /* make sure point is actually on curve */