@@ -71,8 +71,7 @@ void MyMesh::pushPostToClient(ClientInfo *client, PostInfo &post) {
7171 mesh::Utils::sha256 ((uint8_t *)&client->extra .room .pending_ack , 4 , reply_data, len, client->id .pub_key , PUB_KEY_SIZE );
7272 client->extra .room .push_post_timestamp = post .post_timestamp ;
7373
74- bool use_chacha = client->supports_chacha ;
75- auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , client->id , client->shared_secret , reply_data, len, use_chacha);
74+ auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , client->id , client->shared_secret , reply_data, len, client->supports_ascon );
7675 if (reply) {
7776 if (client->out_path_len < 0 ) {
7877 sendFlood (reply);
@@ -280,7 +279,7 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
280279}
281280
282281void MyMesh::onAnonDataRecv (mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
283- uint8_t *data, size_t len, bool decrypted_with_chacha ) {
282+ uint8_t *data, size_t len, bool was_ascon ) {
284283 if (packet->getPayloadType () == PAYLOAD_TYPE_ANON_REQ ) { // received an initial request by a possible admin
285284 // client (unknown at this stage)
286285 uint32_t sender_timestamp, sender_sync_since;
@@ -350,17 +349,13 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
350349
351350 next_push = futureMillis (PUSH_NOTIFY_DELAY_MILLIS ); // delay next push, give RESPONSE packet time to arrive first
352351
353- // Mark peer as ChaCha-capable if we decoded their packet with ChaCha
354- if (decrypted_with_chacha) client->supports_chacha = true ;
355-
356- bool use_chacha = client->supports_chacha ;
357352 if (packet->isRouteFlood ()) {
358353 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
359354 mesh::Packet *path = createPathReturn (sender, client->shared_secret , packet->path , packet->path_len ,
360- PAYLOAD_TYPE_RESPONSE , reply_data, 13 , use_chacha );
355+ PAYLOAD_TYPE_RESPONSE , reply_data, 13 , client-> supports_ascon );
361356 if (path) sendFlood (path, SERVER_RESPONSE_DELAY );
362357 } else {
363- mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , sender, client->shared_secret , reply_data, 13 , use_chacha );
358+ mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , sender, client->shared_secret , reply_data, 13 , client-> supports_ascon );
364359 if (reply) {
365360 if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
366361 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY );
@@ -392,35 +387,13 @@ void MyMesh::getPeerSharedSecret(uint8_t *dest_secret, int peer_idx) {
392387 }
393388}
394389
395- bool MyMesh::peerSupportsCHACHA (const mesh::Identity& dest) {
396- // Look up client by public key
397- ClientInfo* client = acl.getClient (dest.pub_key , PUB_KEY_SIZE );
398- if (client) {
399- return client->supports_chacha ;
400- }
401- // Unknown peer - default to AES (safe fallback)
402- return false ;
403- }
404-
405- bool MyMesh::peerSupportsCHACHA (uint8_t src_hash, int peer_idx) {
406- // Use the peer index from searchPeersByHash() - no re-lookup needed
390+ void MyMesh::onPeerAsconCapabilityDetected (int peer_idx, bool supports_ascon) {
407391 int i = matching_peer_indexes[peer_idx];
408392 if (i >= 0 && i < acl.getNumClients ()) {
409- return acl.getClientByIdx (i)->supports_chacha ;
410- }
411- return false ;
412- }
413-
414- void MyMesh::setPeerSupportsCHACHA (const mesh::Identity* id, int peer_idx) {
415- if (peer_idx >= 0 ) {
416- int i = matching_peer_indexes[peer_idx];
417- if (i >= 0 && i < acl.getNumClients ()) {
418- acl.getClientByIdx (i)->supports_chacha = true ;
419- }
420- } else if (id != nullptr ) {
421- ClientInfo* client = acl.getClient (id->pub_key , PUB_KEY_SIZE );
422- if (client) {
423- client->supports_chacha = true ;
393+ auto client = acl.getClientByIdx (i);
394+ if (supports_ascon && !client->supports_ascon ) {
395+ client->supports_ascon = true ;
396+ MESH_DEBUG_PRINTLN (" Auto-detected Ascon capability for client %d" , i);
424397 }
425398 }
426399}
@@ -429,12 +402,12 @@ void MyMesh::onAdvertRecv(mesh::Packet *packet, const mesh::Identity &id, uint32
429402 const uint8_t *app_data, size_t app_data_len) {
430403 mesh::Mesh::onAdvertRecv (packet, id, timestamp, app_data, app_data_len); // chain to super impl
431404
432- // Update CHACHA capability for known clients
405+ // Update Ascon encryption capability for known clients
433406 AdvertDataParser parser (app_data, app_data_len);
434407 if (parser.isValid ()) {
435408 ClientInfo* client = acl.getClient (id.pub_key , PUB_KEY_SIZE );
436409 if (client) {
437- client->supports_chacha = (parser.getFeat1 () & ADV_FEAT1_CHACHA_CAPABLE ) != 0 ;
410+ client->supports_ascon = (parser.getFeat1 () & ADV_FEAT1_ASCON_CAPABLE ) != 0 ;
438411 }
439412 }
440413}
@@ -532,8 +505,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
532505 // mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 5 + text_len, self_id.pub_key,
533506 // PUB_KEY_SIZE);
534507
535- bool use_chacha = client->supports_chacha ;
536- auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , client->id , secret, temp, 5 + text_len, use_chacha);
508+ auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , client->id , secret, temp, 5 + text_len, client->supports_ascon );
537509 if (reply) {
538510 if (client->out_path_len < 0 ) {
539511 sendFlood (reply, delay_millis + SERVER_RESPONSE_DELAY );
@@ -587,14 +559,13 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
587559 } else {
588560 int reply_len = handleRequest (client, sender_timestamp, &data[4 ], len - 4 );
589561 if (reply_len > 0 ) { // valid command
590- bool use_chacha = client->supports_chacha ;
591562 if (packet->isRouteFlood ()) {
592563 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
593564 mesh::Packet *path = createPathReturn (client->id , secret, packet->path , packet->path_len ,
594- PAYLOAD_TYPE_RESPONSE , reply_data, reply_len, use_chacha );
565+ PAYLOAD_TYPE_RESPONSE , reply_data, reply_len, client-> supports_ascon );
595566 if (path) sendFlood (path, SERVER_RESPONSE_DELAY );
596567 } else {
597- mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , client->id , secret, reply_data, reply_len, use_chacha );
568+ mesh::Packet *reply = createDatagram (PAYLOAD_TYPE_RESPONSE , client->id , secret, reply_data, reply_len, client-> supports_ascon );
598569 if (reply) {
599570 if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
600571 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY );
0 commit comments