diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index ec6404727290ef..69d143898c10f3 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -608,6 +608,8 @@ void SessionManager::SecureGroupMessageDispatch(const PacketHeader & packetHeade return; // malformed packet } + GroupId groupId = packetHeader.GetDestinationGroupId().Value(); + if (msg.IsNull()) { ChipLogError(Inet, "Secure transport received Groupcast NULL packet, discarding"); @@ -630,6 +632,11 @@ void SessionManager::SecureGroupMessageDispatch(const PacketHeader & packetHeade bool decrypted = false; while (!decrypted && iter->Next(groupContext)) { + // Optimization to reduce number of decryption attempts + if (groupId != groupContext.group_id) + { + continue; + } msgCopy = msg.CloneData(); decrypted = (CHIP_NO_ERROR == SecureMessageCodec::Decrypt(CryptoContext(groupContext.key), payloadHeader, packetHeader, msgCopy));