Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / qpg6100 / GroupKeyStoreImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 /**
19  *    @file
20  *          Provides an implementation of the chip Group Key Store interface
21  *          for Qorvo QPG6100 platforms.
22  */
23
24 #include <core/CHIPKeyIds.h>
25 #include <platform/internal/CHIPDeviceLayerInternal.h>
26 #include <platform/qpg6100/qpg6100Config.h>
27
28 namespace chip {
29 namespace DeviceLayer {
30 namespace Internal {
31
32 class ChipGroupKey
33 {
34 public:
35     enum
36     {
37         MaxKeySize = 36
38     };
39     uint32_t KeyId;          /**< The key ID. */
40     uint8_t KeyLen;          /**< The key length. */
41     uint8_t Key[MaxKeySize]; /**< The secret key material. */
42     union
43     {
44         uint32_t StartTime; /**< The epoch key start time. */
45         uint32_t GlobalId;  /**< The application group key global ID. */
46     };
47 };
48
49 /**
50  * An implementation of the chip GroupKeyStoreBase API for this platform.
51  */
52 class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private QPG6100Config
53 {
54     using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey;
55
56 public:
57     CHIP_ERROR Init();
58
59     CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey & key) override;
60     CHIP_ERROR StoreGroupKey(const ChipGroupKey & key) override;
61     CHIP_ERROR DeleteGroupKey(uint32_t keyId) override;
62     CHIP_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override;
63     CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) override;
64     CHIP_ERROR Clear(void) override;
65     CHIP_ERROR RetrieveLastUsedEpochKeyId(void) override;
66     CHIP_ERROR StoreLastUsedEpochKeyId(void) override;
67
68 private:
69     static constexpr size_t kFixedEncodedKeySize = 4U + // key id
70         4U +                                            // start time / global id
71         1U;                                             // key data length
72
73     static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize;
74
75     static constexpr uint16_t kGroupKeyFileId    = GetFileId(kConfigKey_GroupKey);
76     static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey);
77
78     static CHIP_ERROR EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen);
79     static CHIP_ERROR DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key);
80     static CHIP_ERROR DecodeGroupKeyId(const uint8_t * encodedKey, size_t encodedKeyLen, uint32_t & keyId);
81 };
82
83 } // namespace Internal
84 } // namespace DeviceLayer
85 } // namespace chip