From b82bc9418c885fb7eae6bd85ae06f00ad5ed7678 Mon Sep 17 00:00:00 2001 From: svost Date: Sun, 30 Jan 2022 21:10:34 +0300 Subject: [PATCH] EC_KEY_regenerate_key: add missed checks --- src/key.cpp | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/key.cpp b/src/key.cpp index b7a205a..9038342 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -13,27 +13,29 @@ // Generate a private key from just the secret parameter int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key) { - int ok = 0; - BN_CTX *ctx = NULL; - EC_POINT *pub_key = NULL; - if (!eckey) return 0; + int ok = 0; + BN_CTX *ctx = nullptr; + EC_POINT *pub_key = nullptr; + const EC_GROUP *group = EC_KEY_get0_group(eckey); - if ((ctx = BN_CTX_new()) == NULL) + if ((ctx = BN_CTX_new()) == nullptr) goto err; pub_key = EC_POINT_new(group); - if (pub_key == NULL) + if (pub_key == nullptr) goto err; - if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) + if (!EC_POINT_mul(group, pub_key, priv_key, nullptr, nullptr, ctx)) goto err; - EC_KEY_set_private_key(eckey,priv_key); - EC_KEY_set_public_key(eckey,pub_key); + if (!EC_KEY_set_private_key(eckey,priv_key)) + goto err; + if (!EC_KEY_set_public_key(eckey,pub_key)) + goto err; ok = 1; @@ -41,7 +43,7 @@ err: if (pub_key) EC_POINT_free(pub_key); - if (ctx != NULL) + if (ctx != nullptr) BN_CTX_free(ctx); return(ok); -- 1.7.1