Skip to content

Commit

Permalink
[msg] Initialize session counters with random per spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
turon committed Dec 2, 2021
1 parent e66e2a1 commit 0babc91
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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,12 @@ 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

/**
* Initialize a local message counter with random value between [0, 2^28-1].
*/
LocalSessionMessageCounter() { value = Crypto::GetRandU32() & 0x0FFFFFFF; }

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

0 comments on commit 0babc91

Please sign in to comment.