3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * Provides an implementation of the Chip Group Key Store interface
22 * for platforms based on the Silicon Labs SDK.
25 #include <Core/CHIPKeyIds.h>
26 #include <platform/EFR32/EFR32Config.h>
27 #include <platform/Profiles/security/ChipApplicationKeys.h>
28 #include <platform/internal/CHIPDeviceLayerInternal.h>
31 namespace DeviceLayer {
35 * An implementation of the Chip GroupKeyStoreBase API for platforms based
36 * on the Silicon Labs SDK.
38 class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private EFR32Config
40 using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey;
45 CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey & key) override;
46 CHIP_ERROR StoreGroupKey(const ChipGroupKey & key) override;
47 CHIP_ERROR DeleteGroupKey(uint32_t keyId) override;
48 CHIP_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override;
49 CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) override;
50 CHIP_ERROR Clear(void) override;
51 CHIP_ERROR RetrieveLastUsedEpochKeyId(void) override;
52 CHIP_ERROR StoreLastUsedEpochKeyId(void) override;
55 static constexpr size_t kFixedEncodedKeySize = 4U + // key id
56 4U + // start time / global id
57 1U; // key data length
59 static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize;
62 static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey);
63 static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey);
66 static CHIP_ERROR EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen);
67 static CHIP_ERROR DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key);
68 static CHIP_ERROR DecodeGroupKeyId(const uint8_t * encodedKey, size_t encodedKeyLen, uint32_t & keyId);
71 } // namespace Internal
72 } // namespace DeviceLayer