2017-02-28 19:24:43 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Linaro Limited.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <device.h>
|
2017-10-14 07:30:55 +08:00
|
|
|
#include <entropy.h>
|
2017-10-14 06:45:02 +08:00
|
|
|
#include <random/rand32.h>
|
2017-02-28 19:24:43 +08:00
|
|
|
#include <init.h>
|
|
|
|
|
|
|
|
#include "fsl_trng.h"
|
|
|
|
|
2017-10-14 07:30:55 +08:00
|
|
|
static int entropy_mcux_trng_get_entropy(struct device *dev, u8_t *buffer,
|
|
|
|
u16_t length)
|
2017-02-28 19:24:43 +08:00
|
|
|
{
|
|
|
|
status_t status;
|
|
|
|
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
status = TRNG_GetRandomData(TRNG0, buffer, length);
|
|
|
|
__ASSERT_NO_MSG(!status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-14 07:30:55 +08:00
|
|
|
static const struct entropy_driver_api entropy_mcux_trng_api_funcs = {
|
|
|
|
.get_entropy = entropy_mcux_trng_get_entropy
|
2017-02-28 19:24:43 +08:00
|
|
|
};
|
|
|
|
|
2017-10-14 07:30:55 +08:00
|
|
|
static int entropy_mcux_trng_init(struct device *);
|
2017-02-28 19:24:43 +08:00
|
|
|
|
2017-10-14 07:30:55 +08:00
|
|
|
DEVICE_AND_API_INIT(entropy_mcux_trng, CONFIG_ENTROPY_NAME,
|
|
|
|
entropy_mcux_trng_init, NULL, NULL,
|
2018-05-23 06:08:38 +08:00
|
|
|
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
2017-10-14 07:30:55 +08:00
|
|
|
&entropy_mcux_trng_api_funcs);
|
2017-02-28 19:24:43 +08:00
|
|
|
|
2017-10-14 07:30:55 +08:00
|
|
|
static int entropy_mcux_trng_init(struct device *dev)
|
2017-02-28 19:24:43 +08:00
|
|
|
{
|
|
|
|
trng_config_t conf;
|
|
|
|
status_t status;
|
|
|
|
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
status = TRNG_GetDefaultConfig(&conf);
|
|
|
|
__ASSERT_NO_MSG(!status);
|
|
|
|
|
|
|
|
status = TRNG_Init(TRNG0, &conf);
|
|
|
|
__ASSERT_NO_MSG(!status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|