[PATCH 2/2] ecdh: add unlikely() check for NULL parameters

James Prestwood <[email protected]> Wed, 13 Mar 2024 09:44:25 -0700
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
---
 ell/ecdh.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ell/ecdh.c b/ell/ecdh.c
index 568b599..e10a7d4 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);
-- 
2.34.1