Skip to content

Commit

Permalink
[msg] Initialize session counters with random per spec. (#12517)
Browse files Browse the repository at this point in the history
  • Loading branch information
turon authored and pull[bot] committed Jan 11, 2024
1 parent 68c1896 commit 3e31017
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/transport/MessageCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#pragma once

#include <crypto/RandUtils.h>
#include <lib/support/PersistedCounter.h>

namespace chip {
Expand Down Expand Up @@ -106,8 +107,14 @@ class GlobalEncryptedMessageCounter : public MessageCounter
class LocalSessionMessageCounter : public MessageCounter
{
public:
static constexpr uint32_t kInitialValue = 1;
LocalSessionMessageCounter() : value(kInitialValue) {}
static constexpr uint32_t kInitialValue = 1; ///< Used for initializing peer counter
static constexpr uint32_t kMessageCounterRandomInitMask = 0x0FFFFFF; ///< 28-bit mask

/**
* Initialize a local message counter with random value between [0, 2^28-1]. This increases the difficulty of traffic analysis
* attacks by making it harder to determine how long a particular session has been open.
*/
LocalSessionMessageCounter() { value = Crypto::GetRandU32() & kMessageCounterRandomInitMask; }

Type GetType() override { return Session; }
uint32_t Value() override { return value; }
Expand Down

0 comments on commit 3e31017

Please sign in to comment.