From daa157cf4992d0bbd31a189d984e1afe6b1fefa3 Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Wed, 15 Jan 2025 00:39:32 +1100 Subject: [PATCH] * minor fixes --- examples/simple_secure_chat/main.cpp | 4 ++-- src/Identity.cpp | 4 ++-- src/Identity.h | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/simple_secure_chat/main.cpp b/examples/simple_secure_chat/main.cpp index 411196bf..4a1c6c75 100644 --- a/examples/simple_secure_chat/main.cpp +++ b/examples/simple_secure_chat/main.cpp @@ -108,7 +108,7 @@ protected: void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, uint8_t* data, size_t len) override { if (type == PAYLOAD_TYPE_TXT_MSG && len > 5) { int i = matching_peer_indexes[sender_idx]; - if (i < 0 && i >= num_contacts) { + if (i < 0 || i >= num_contacts) { MESH_DEBUG_PRINTLN("onPeerDataRecv: Invalid sender idx: %d", i); return; } @@ -150,7 +150,7 @@ protected: void onPeerPathRecv(mesh::Packet* packet, int sender_idx, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override { int i = matching_peer_indexes[sender_idx]; - if (i < 0 && i >= num_contacts) { + if (i < 0 || i >= num_contacts) { MESH_DEBUG_PRINTLN("onPeerPathRecv: Invalid sender idx: %d", i); return; } diff --git a/src/Identity.cpp b/src/Identity.cpp index 05a90668..ea31cb36 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -63,8 +63,8 @@ void LocalIdentity::sign(uint8_t* sig, const uint8_t* message, int msg_len) cons ed25519_sign(sig, message, msg_len, pub_key, prv_key); } -void LocalIdentity::calcSharedSecret(uint8_t* secret, const Identity& other) { - ed25519_key_exchange(secret, other.pub_key, prv_key); +void LocalIdentity::calcSharedSecret(uint8_t* secret, const uint8_t* other_pub_key) { + ed25519_key_exchange(secret, other_pub_key, prv_key); } } \ No newline at end of file diff --git a/src/Identity.h b/src/Identity.h index cdd15019..766e2985 100644 --- a/src/Identity.h +++ b/src/Identity.h @@ -64,7 +64,14 @@ public: * \param secret OUT - the 'shared secret' (must be PUB_KEY_SIZE bytes) * \param other IN - the second party in the exchange. */ - void calcSharedSecret(uint8_t* secret, const Identity& other); + void calcSharedSecret(uint8_t* secret, const Identity& other) { calcSharedSecret(secret, other.pub_key); } + + /** + * \brief the ECDH key exhange, with Ed25519 public key transposed to Ex25519. + * \param secret OUT - the 'shared secret' (must be PUB_KEY_SIZE bytes) + * \param other_pub_key IN - the public key of second party in the exchange (must be PUB_KEY_SIZE bytes) + */ + void calcSharedSecret(uint8_t* secret, const uint8_t* other_pub_key); bool readFrom(Stream& s); bool writeTo(Stream& s) const;