3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2020 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * Provides an implementation of the Chip Group Key Store interface
23 * for platforms based on the NXP SDK.
26 #include <core/CHIPKeyIds.h>
27 #include <platform/K32W/K32WConfig.h>
28 #include <platform/internal/CHIPDeviceLayerInternal.h>
31 namespace DeviceLayer {
41 uint32_t KeyId; /**< The key ID. */
42 uint8_t KeyLen; /**< The key length. */
43 uint8_t Key[MaxKeySize]; /**< The secret key material. */
46 uint32_t StartTime; /**< The epoch key start time. */
47 uint32_t GlobalId; /**< The application group key global ID. */
52 * An implementation of the Chip GroupKeyStoreBase API for platforms based
55 class GroupKeyStoreImpl final : public ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase, private K32WConfig
57 using ChipGroupKey = ::chip::Profiles::Security::AppKeys::ChipGroupKey;
62 CHIP_ERROR RetrieveGroupKey(uint32_t keyId, ChipGroupKey & key) override;
63 CHIP_ERROR StoreGroupKey(const ChipGroupKey & key) override;
64 CHIP_ERROR DeleteGroupKey(uint32_t keyId) override;
65 CHIP_ERROR DeleteGroupKeysOfAType(uint32_t keyType) override;
66 CHIP_ERROR EnumerateGroupKeys(uint32_t keyType, uint32_t * keyIds, uint8_t keyIdsArraySize, uint8_t & keyCount) override;
67 CHIP_ERROR Clear(void) override;
68 CHIP_ERROR RetrieveLastUsedEpochKeyId(void) override;
69 CHIP_ERROR StoreLastUsedEpochKeyId(void) override;
72 static constexpr size_t kFixedEncodedKeySize = 4U + // key id
73 4U + // start time / global id
74 1U; // key data length
76 static constexpr size_t kMaxEncodedKeySize = kFixedEncodedKeySize + ChipGroupKey::MaxKeySize;
79 static constexpr uint16_t kGroupKeyFileId = GetFileId(kConfigKey_GroupKey);
80 static constexpr uint16_t kGroupKeyRecordKey = GetRecordKey(kConfigKey_GroupKey);
83 static CHIP_ERROR EncodeGroupKey(const ChipGroupKey & key, uint8_t * buf, size_t bufSize, size_t & encodedKeyLen);
84 static CHIP_ERROR DecodeGroupKey(const uint8_t * encodedKey, size_t encodedKeyLen, ChipGroupKey & key);
85 static CHIP_ERROR DecodeGroupKeyId(const uint8_t * encodedKey, size_t encodedKeyLen, uint32_t & keyId);
88 } // namespace Internal
89 } // namespace DeviceLayer