smp: Reject pairing if the public keys match

Bug: 174886838
Test: pair an LE device
Tag: #security
Change-Id: I0902fdf6bb5c1c7d443fc73fc480d51226fb836b
Merged-In: I0902fdf6bb5c1c7d443fc73fc480d51226fb836b
(cherry picked from commit b7e176df4b9d90dbf8f29678615e6547a6e6d038)
diff --git a/stack/smp/smp_act.cc b/stack/smp/smp_act.cc
index bfce7cb..fc5098d 100644
--- a/stack/smp/smp_act.cc
+++ b/stack/smp/smp_act.cc
@@ -689,6 +689,16 @@
   memcpy(pt.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN);
   memcpy(pt.y, p_cb->peer_publ_key.y, BT_OCTET32_LEN);
 
+  if (!memcmp(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, BT_OCTET32_LEN) &&
+      !memcmp(p_cb->peer_publ_key.y, p_cb->loc_publ_key.y, BT_OCTET32_LEN)) {
+    android_errorWriteLog(0x534e4554, "174886838");
+    LOG_WARN("Remote and local public keys can't match");
+    tSMP_INT_DATA smp;
+    smp.status = SMP_PAIR_AUTH_FAIL;
+    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp);
+    return;
+  }
+
   if (!ECC_ValidatePoint(pt)) {
     android_errorWriteLog(0x534e4554, "72377774");
     tSMP_INT_DATA smp;