Skip to content

Commit

Permalink
Add Random first value group counter
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs committed May 16, 2023
1 parent 5f1a60b commit fb7bfe7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/transport/GroupPeerMessageCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <lib/support/DefaultStorageKeyAllocator.h>
#include <transport/GroupPeerMessageCounter.h>

#include <crypto/RandUtils.h>

namespace chip {
namespace Transport {

Expand Down Expand Up @@ -268,7 +270,6 @@ CHIP_ERROR GroupOutgoingCounters::Init(chip::PersistentStorageDelegate * storage
return CHIP_ERROR_INVALID_ARGUMENT;
}

// TODO Implement Logic for first time use / factory reset to be random
// Spec 4.5.1.3
mStorage = storage_delegate;
uint16_t size = static_cast<uint16_t>(sizeof(uint32_t));
Expand All @@ -277,9 +278,8 @@ CHIP_ERROR GroupOutgoingCounters::Init(chip::PersistentStorageDelegate * storage
err = mStorage->SyncGetKeyValue(DefaultStorageKeyAllocator::GroupControlCounter().KeyName(), &temp, size);
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
// might be the first time we retrieve the value
// TODO handle this case
mGroupControlCounter = 0; // TODO should be random
// First time retrieving the counter
mGroupControlCounter = chip::Crypto::GetRandU32();
}
else if (err != CHIP_NO_ERROR)
{
Expand All @@ -293,9 +293,8 @@ CHIP_ERROR GroupOutgoingCounters::Init(chip::PersistentStorageDelegate * storage
err = mStorage->SyncGetKeyValue(DefaultStorageKeyAllocator::GroupDataCounter().KeyName(), &temp, size);
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
// might be the first time we retrieve the value
// TODO handle this case
mGroupDataCounter = 0; // TODO should be random
// First time retrieving the counter
mGroupDataCounter = chip::Crypto::GetRandU32();
}
else if (err != CHIP_NO_ERROR)
{
Expand Down

0 comments on commit fb7bfe7

Please sign in to comment.