aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Prestwood <prestwoj@gmail.com>2024-03-13 09:44:25 -0700
committerDenis Kenzior <denkenz@gmail.com>2024-03-18 09:31:19 -0500
commitf50fb9d1c21c6598497b7fe197f62e32a3314255 (patch)
treeb8104b713909c56bb9577be203c32a51b69b1267
parentf5e27f0085f9b51015d4cd5aa0891f2cfd37e426 (diff)
ecdh: add unlikely() check for NULL parameters
-rw-r--r--ell/ecdh.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ell/ecdh.c b/ell/ecdh.c
index 568b5992..e10a7d43 100644
--- a/ell/ecdh.c
+++ b/ell/ecdh.c
@@ -16,6 +16,7 @@
#include "ecc.h"
#include "ecdh.h"
#include "random.h"
+#include "useful.h"
/*
* Some sane maximum for calculating the public key.
@@ -41,6 +42,9 @@ LIB_EXPORT bool l_ecdh_generate_key_pair(const struct l_ecc_curve *curve,
int iter = 0;
uint64_t p2[L_ECC_MAX_DIGITS];
+ if (unlikely(!curve || !out_private || !out_public))
+ return false;
+
_ecc_calculate_p2(curve, p2);
*out_public = l_ecc_point_new(curve);
@@ -77,6 +81,9 @@ LIB_EXPORT bool l_ecdh_generate_shared_secret(
struct l_ecc_scalar *z;
struct l_ecc_point *product;
+ if (unlikely(!private_key || !other_public || !secret))
+ return false;
+
z = l_ecc_scalar_new_random(curve);
product = l_ecc_point_new(curve);