blob: a0424a7e3f4412c8f21095dd64844fb4161e9a8f [file] [log] [blame]
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <platform/nxp/common/factory_data/FactoryDataProvider.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/storage/flash_map.h>
namespace chip {
namespace DeviceLayer {
/**
* @brief This class provides Commissionable data and Device Attestation Credentials.
*
* This implementation is using the SDK fwk_factory_data_provider module.
*
* For more information on this module, the interface description available in
* FactoryDataProvider/fwk_factory_data_provider.h inside the SDK can be checked.
*/
class FactoryDataProviderImpl : public FactoryDataProvider
{
public:
static FactoryDataProviderImpl sInstance;
CHIP_ERROR Init(void);
CHIP_ERROR SearchForId(uint8_t searchedType, uint8_t * pBuf, size_t bufLength, uint16_t & length,
uint32_t * contentAddr = NULL);
CHIP_ERROR SignWithDacKey(const ByteSpan & digestToSign, MutableByteSpan & outSignBuffer);
CHIP_ERROR SetAes128Key(const uint8_t * keyAes128);
CHIP_ERROR SetEncryptionMode(EncryptionMode mode);
private:
struct Header
{
uint32_t hashId;
uint32_t size;
uint8_t hash[4];
};
struct FactoryData
{
struct Header header;
uint8_t factoryDataBuffer[FIXED_PARTITION_SIZE(factory_partition) - sizeof(struct Header)];
};
FactoryData mFactoryData;
const uint8_t * pAes128Key = nullptr;
EncryptionMode encryptMode = encrypt_ecb;
CHIP_ERROR ReadEncryptedData(uint8_t * dest, uint8_t * source);
CHIP_ERROR LoadKeypairFromRaw(ByteSpan privateKey, ByteSpan publicKey, Crypto::P256Keypair & keypair);
};
inline FactoryDataProvider & FactoryDataPrvd()
{
return FactoryDataProviderImpl::sInstance;
}
inline FactoryDataProviderImpl & FactoryDataPrvdImpl()
{
return FactoryDataProviderImpl::sInstance;
}
} // namespace DeviceLayer
} // namespace chip