Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / EFR32 / GroupKeyStoreImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2019 Nest Labs, Inc.
5  *
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  *    @file
21  *          Provides an implementation of the Chip Group Key Store interface
22  *          for platforms based on the Silicon Labs SDK.
23  */
24
25 #include <Core/CHIPKeyIds.h>
26 #include <platform/EFR32/EFR32Config.h>
27 #include <platform/Profiles/security/ChipApplicationKeys.h>
28 #include <platform/internal/CHIPDeviceLayerInternal.h>
29
30 namespace chip {
31 namespace DeviceLayer {
32 namespace Internal {
33
34 /**
35  * An implementation of the Chip GroupKeyStoreBase API for platforms based
36  * on the Silicon Labs SDK.
37  */
38 class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private EFR32Config
39 {
40     using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey;
41
42 public:
43     CHIP_ERROR Init();
44
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;
53
54 private:
55     static constexpr size_t kFixedEncodedKeySize = 4U + // key id
56         4U +                                            // start time / global id
57         1U;                                             // key data length
58
59     static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize;
60
61     /* Not used
62     static constexpr uint16_t kGroupKeyFileId =     GetFileId(kConfigKey_GroupKey);
63     static constexpr uint16_t kGroupKeyRecordKey =  GetRecordKey(kConfigKey_GroupKey);
64     */
65
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);
69 };
70
71 } // namespace Internal
72 } // namespace DeviceLayer
73 } // namespace chip