Skip to content

Commit 606ff36

Browse files
committed
mode-aware max path calculation (AEAD-4 vs ECB)
1 parent 05a34d2 commit 606ff36

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
@@ -488,8 +488,6 @@ Packet* Mesh::createAdvert(const LocalIdentity& id, const uint8_t* app_data, siz
488488
return packet;
489489
}
490490

491-
#define MAX_COMBINED_PATH (MAX_PACKET_PAYLOAD - 2 - CIPHER_BLOCK_SIZE)
492-
493491
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) {
494492
uint8_t dest_hash[PATH_HASH_SIZE];
495493
dest.copyHashTo(dest_hash);
@@ -500,7 +498,9 @@ Packet* Mesh::createPathReturn(const uint8_t* dest_hash, const uint8_t* secret,
500498
uint8_t path_hash_size = (path_len >> 6) + 1;
501499
uint8_t path_hash_count = path_len & 63;
502500

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

505505
Packet* packet = obtainNewPacket();
506506
if (packet == NULL) {

0 commit comments

Comments
 (0)