diff mbox series

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

Message ID 20240313164425.690572-2-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/2] ecc: add l_ecc_scalar_clone | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

James Prestwood March 13, 2024, 4:44 p.m. UTC
---
 ell/ecdh.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

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);