Skip to content

Commit

Permalink
crypto: ecc - remove checks in crypto_ecdh_shared_secret() and ecc_ma…
Browse files Browse the repository at this point in the history
…ke_pub_key()

With the current state of the code, ecc_get_curve() cannot return
NULL in crypto_ecdh_shared_secret() and ecc_make_pub_key(). This is
conditioned by the fact that they are only called from ecdh_compute_value(),
which implements the kpp_alg::{generate_public_key,compute_shared_secret}()
methods. Also ecdh implements the kpp_alg::init() method, which is called
before the other methods and sets ecdh_ctx::curve_id to a valid value.

Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Roman Smirnov authored and Herbert Xu committed Apr 12, 2024
1 parent 4ad27a8 commit 233e750
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crypto/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits,
u64 priv[ECC_MAX_DIGITS];
const struct ecc_curve *curve = ecc_get_curve(curve_id);

if (!private_key || !curve || ndigits > ARRAY_SIZE(priv)) {
if (!private_key || ndigits > ARRAY_SIZE(priv)) {
ret = -EINVAL;
goto out;
}
Expand Down Expand Up @@ -1622,7 +1622,7 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,
unsigned int nbytes;
const struct ecc_curve *curve = ecc_get_curve(curve_id);

if (!private_key || !public_key || !curve ||
if (!private_key || !public_key ||
ndigits > ARRAY_SIZE(priv) || ndigits > ARRAY_SIZE(rand_z)) {
ret = -EINVAL;
goto out;
Expand Down

0 comments on commit 233e750

Please sign in to comment.