Skip to content

Commit 7564308

Browse files
turonpull[bot]
authored andcommitted
[msg] Initialize session counters with random per spec. (#12517)
1 parent 2dd183d commit 7564308

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/transport/MessageCounter.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
#pragma once
2323

24+
#include <crypto/RandUtils.h>
2425
#include <lib/support/PersistedCounter.h>
2526

2627
namespace chip {
@@ -106,8 +107,14 @@ class GlobalEncryptedMessageCounter : public MessageCounter
106107
class LocalSessionMessageCounter : public MessageCounter
107108
{
108109
public:
109-
static constexpr uint32_t kInitialValue = 1;
110-
LocalSessionMessageCounter() : value(kInitialValue) {}
110+
static constexpr uint32_t kInitialValue = 1; ///< Used for initializing peer counter
111+
static constexpr uint32_t kMessageCounterRandomInitMask = 0x0FFFFFF; ///< 28-bit mask
112+
113+
/**
114+
* Initialize a local message counter with random value between [0, 2^28-1]. This increases the difficulty of traffic analysis
115+
* attacks by making it harder to determine how long a particular session has been open.
116+
*/
117+
LocalSessionMessageCounter() { value = Crypto::GetRandU32() & kMessageCounterRandomInitMask; }
111118

112119
Type GetType() override { return Session; }
113120
uint32_t Value() override { return value; }

0 commit comments

Comments
 (0)