@@ -146,8 +146,7 @@ int BaseChatMesh::searchPeersByHash(const uint8_t* hash) {
146146void BaseChatMesh::getPeerSharedSecret (uint8_t * dest_secret, int peer_idx) {
147147 int i = matching_peer_indexes[peer_idx];
148148 if (i >= 0 && i < num_contacts) {
149- ensureSharedSecretIsValid (contacts[i]);
150- memcpy (dest_secret, contacts[i].shared_secret , PUB_KEY_SIZE);
149+ memcpy (dest_secret, contacts[i].getSharedSecret (self_id), PUB_KEY_SIZE);
151150 } else {
152151 MESH_DEBUG_PRINTLN (" getPeerSharedSecret: Invalid peer idx: %d" , i);
153152 }
@@ -292,8 +291,7 @@ void BaseChatMesh::onAckRecv(mesh::Packet* packet, uint32_t ack_crc) {
292291void BaseChatMesh::handleReturnPathRetry (const ContactInfo& contact, const uint8_t * path, uint8_t path_len) {
293292 // NOTE: simplest impl is just to re-send a reciprocal return path to sender (DIRECTLY)
294293 // override this method in various firmwares, if there's a better strategy
295- ensureSharedSecretIsValid (contact);
296- mesh::Packet* rpath = createPathReturn (contact.id , contact.shared_secret , path, path_len, 0 , NULL , 0 );
294+ mesh::Packet* rpath = createPathReturn (contact.id , contact.getSharedSecret (self_id), path, path_len, 0 , NULL , 0 );
297295 if (rpath) sendDirect (rpath, contact.out_path , contact.out_path_len , 3000 ); // 3 second delay
298296}
299297
@@ -342,8 +340,7 @@ mesh::Packet* BaseChatMesh::composeMsgPacket(const ContactInfo& recipient, uint3
342340 temp[len++] = attempt; // hide attempt number at tail end of payload
343341 }
344342
345- ensureSharedSecretIsValid (recipient);
346- return createDatagram (PAYLOAD_TYPE_TXT_MSG, recipient.id , recipient.shared_secret , temp, len);
343+ return createDatagram (PAYLOAD_TYPE_TXT_MSG, recipient.id , recipient.getSharedSecret (self_id), temp, len);
347344}
348345
349346int BaseChatMesh::sendMessage (const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char * text, uint32_t & expected_ack, uint32_t & est_timeout) {
@@ -374,8 +371,7 @@ int BaseChatMesh::sendCommandData(const ContactInfo& recipient, uint32_t timest
374371 temp[4 ] = (attempt & 3 ) | (TXT_TYPE_CLI_DATA << 2 );
375372 memcpy (&temp[5 ], text, text_len + 1 );
376373
377- ensureSharedSecretIsValid (recipient);
378- auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG, recipient.id , recipient.shared_secret , temp, 5 + text_len);
374+ auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG, recipient.id , recipient.getSharedSecret (self_id), temp, 5 + text_len);
379375 if (pkt == NULL ) return MSG_SEND_FAILED;
380376
381377 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -464,8 +460,7 @@ int BaseChatMesh::sendLogin(const ContactInfo& recipient, const char* password,
464460 tlen = 4 + len;
465461 }
466462
467- ensureSharedSecretIsValid (recipient);
468- pkt = createAnonDatagram (PAYLOAD_TYPE_ANON_REQ, self_id, recipient.id , recipient.shared_secret , temp, tlen);
463+ pkt = createAnonDatagram (PAYLOAD_TYPE_ANON_REQ, self_id, recipient.id , recipient.getSharedSecret (self_id), temp, tlen);
469464 }
470465 if (pkt) {
471466 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -492,8 +487,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, const uint8_t* req_
492487 memcpy (temp, &tag, 4 ); // mostly an extra blob to help make packet_hash unique
493488 memcpy (&temp[4 ], req_data, data_len);
494489
495- ensureSharedSecretIsValid (recipient);
496- pkt = createDatagram (PAYLOAD_TYPE_REQ, recipient.id , recipient.shared_secret , temp, 4 + data_len);
490+ pkt = createDatagram (PAYLOAD_TYPE_REQ, recipient.id , recipient.getSharedSecret (self_id), temp, 4 + data_len);
497491 }
498492 if (pkt) {
499493 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -520,8 +514,7 @@ int BaseChatMesh::sendRequest(const ContactInfo& recipient, uint8_t req_type, u
520514 memset (&temp[5 ], 0 , 4 ); // reserved (possibly for 'since' param)
521515 getRNG ()->random (&temp[9 ], 4 ); // random blob to help make packet-hash unique
522516
523- ensureSharedSecretIsValid (recipient);
524- pkt = createDatagram (PAYLOAD_TYPE_REQ, recipient.id , recipient.shared_secret , temp, sizeof (temp));
517+ pkt = createDatagram (PAYLOAD_TYPE_REQ, recipient.id , recipient.getSharedSecret (self_id), temp, sizeof (temp));
525518 }
526519 if (pkt) {
527520 uint32_t t = _radio->getEstAirtimeFor (pkt->getRawLength ());
@@ -644,8 +637,7 @@ void BaseChatMesh::checkConnections() {
644637 // calc expected ACK reply
645638 mesh::Utils::sha256 ((uint8_t *)&connections[i].expected_ack , 4 , data, 9 , self_id.pub_key , PUB_KEY_SIZE);
646639
647- ensureSharedSecretIsValid (*contact);
648- auto pkt = createDatagram (PAYLOAD_TYPE_REQ, contact->id , contact->shared_secret , data, 9 );
640+ auto pkt = createDatagram (PAYLOAD_TYPE_REQ, contact->id , contact->getSharedSecret (self_id), data, 9 );
649641 if (pkt) {
650642 sendDirect (pkt, contact->out_path , contact->out_path_len );
651643 }
@@ -715,14 +707,6 @@ bool BaseChatMesh::addContact(const ContactInfo& contact) {
715707 return false ;
716708}
717709
718- void BaseChatMesh::ensureSharedSecretIsValid (const ContactInfo& contact) {
719- if (contact.shared_secret_valid ) {
720- return ; // already calculated
721- }
722- self_id.calcSharedSecret (contact.shared_secret , contact.id );
723- contact.shared_secret_valid = true ;
724- }
725-
726710bool BaseChatMesh::removeContact (ContactInfo& contact) {
727711 int idx = 0 ;
728712 while (idx < num_contacts && !contacts[idx].id .matches (contact.id )) {
0 commit comments