Validate peer's public key in ECDH
This protects against invalid curve attacks.
(It's also a tiny step in the direction of protecting against some fault
injection attacks.)
diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c
index 54b9a8a..853c50d 100644
--- a/tinycrypt/ecc_dh.c
+++ b/tinycrypt/ecc_dh.c
@@ -169,6 +169,12 @@
wordcount_t num_bytes = curve->num_bytes;
int r;
+ /* Protect against invalid curve attacks */
+ if (uECC_valid_public_key(public_key, curve) != 0) {
+ r = 0;
+ goto clear_and_out;
+ }
+
/* Converting buffers to correct bit order: */
uECC_vli_bytesToNative(_private,
private_key,