3 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Provides an implementation of the chip Group Key Store interface
21 * for Qorvo QPG6100 platforms.
24 #include <core/CHIPKeyIds.h>
25 #include <platform/internal/CHIPDeviceLayerInternal.h>
26 #include <platform/qpg6100/qpg6100Config.h>
29 namespace DeviceLayer {
39 uint32_t KeyId; /**< The key ID. */
40 uint8_t KeyLen; /**< The key length. */
41 uint8_t Key[MaxKeySize]; /**< The secret key material. */
44 uint32_t StartTime; /**< The epoch key start time. */
45 uint32_t GlobalId; /**< The application group key global ID. */
50 * An implementation of the chip GroupKeyStoreBase API for this platform.
52 class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private QPG6100Config
54 using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey;
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;
69 static constexpr size_t kFixedEncodedKeySize = 4U + // key id
70 4U + // start time / global id
71 1U; // key data length
73 static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize;
75 static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey);
76 static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey);
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);
83 } // namespace Internal
84 } // namespace DeviceLayer