# HG changeset patch # User Matt Johnston # Date 1518261900 -28800 # Node ID b0c3b46372dce41477bdff8eadacdd219ef6176d # Parent cf43bbb6b8ff94f57cad1f363bb3967bceb35a27 simplify error handling, check mp_copy return value diff -r cf43bbb6b8ff -r b0c3b46372dc ecc.c --- a/ecc.c Sat Feb 10 19:06:30 2018 +0800 +++ b/ecc.c Sat Feb 10 19:25:00 2018 +0800 @@ -221,46 +221,41 @@ /* type valid? */ if (private_key->type != PK_PRIVATE) { - goto done; + goto out; } if (private_key->dp != public_key->dp) { - goto done; + goto out; } /* make new point */ result = ltc_ecc_new_point(); if (result == NULL) { - goto done; + goto out; } prime = m_malloc(sizeof(*prime)); m_mp_init(prime); if (mp_read_radix(prime, (char *)private_key->dp->prime, 16) != CRYPT_OK) { - goto done; + goto out; } if (ltc_mp.ecc_ptmul(private_key->k, &public_key->pubkey, result, prime, 1) != CRYPT_OK) { - goto done; + goto out; } + shared_secret = m_malloc(sizeof(*shared_secret)); + m_mp_init(shared_secret); + if (mp_copy(result->x, shared_secret) != CRYPT_OK) { + goto out; + } + + mp_clear(prime); + m_free(prime); + ltc_ecc_del_point(result); + err = DROPBEAR_SUCCESS; - done: - if (err == DROPBEAR_SUCCESS) { - shared_secret = m_malloc(sizeof(*shared_secret)); - m_mp_init(shared_secret); - mp_copy(result->x, shared_secret); - } - - if (prime) { - mp_clear(prime); - m_free(prime); - } - if (result) - { - ltc_ecc_del_point(result); - } - + out: if (err == DROPBEAR_FAILURE) { dropbear_exit("ECC error"); }