Skip to content

Commit c1deffa

Browse files
committed
mode-aware max path calculation (AEAD-4 vs ECB)
1 parent 9568d4d commit c1deffa

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/Mesh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ Packet* Mesh::createAdvert(const LocalIdentity& id, const uint8_t* app_data, siz
502502
return packet;
503503
}
504504

505-
#define MAX_COMBINED_PATH (MAX_PACKET_PAYLOAD - 2 - CIPHER_BLOCK_SIZE)
506-
507505
Packet* Mesh::createPathReturn(const Identity& dest, const uint8_t* secret, const uint8_t* path, uint8_t path_len, uint8_t extra_type, const uint8_t*extra, size_t extra_len, uint16_t aead_nonce) {
508506
uint8_t dest_hash[PATH_HASH_SIZE];
509507
dest.copyHashTo(dest_hash);
@@ -514,7 +512,9 @@ Packet* Mesh::createPathReturn(const uint8_t* dest_hash, const uint8_t* secret,
514512
uint8_t path_hash_size = (path_len >> 6) + 1;
515513
uint8_t path_hash_count = path_len & 63;
516514

517-
if (path_hash_count*path_hash_size + extra_len + 5 > MAX_COMBINED_PATH) return NULL; // too long!!
515+
size_t max_overhead = aead_nonce ? (AEAD_NONCE_SIZE + AEAD_TAG_SIZE) : (CIPHER_MAC_SIZE + CIPHER_BLOCK_SIZE-1);
516+
size_t max_combined_path = MAX_PACKET_PAYLOAD - PATH_HASH_SIZE * 2 - max_overhead;
517+
if (path_hash_count*path_hash_size + extra_len + 5 > max_combined_path) return NULL; // too long!!
518518

519519
Packet* packet = obtainNewPacket();
520520
if (packet == NULL) {

0 commit comments

Comments
 (0)