From aae04b2516903a1862afdc6c3a815111c6181556 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Thu, 26 Sep 2019 10:23:57 +0800 Subject: [PATCH] Nuvoton: Remove TRNG support These targets below just support PRNG, not real TRNG. They cannot annouce TRNG. - NUMAKER_PFM_NUC472 - NUMAKER_PFM_M487 - NUMAKER_IOT_M487 On targets without TRNG, to run mbedtls applications which require entropy source, there are two alternatives to TRNG: - Custom entropy source: Define MBEDTLS_ENTROPY_HARDWARE_ALT and provide custom mbedtls_hardware_poll(...) - NV seed: 1. Define MBEDTLS_ENTROPY_NV_SEED 2. Define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO/MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and provide custom mbedtls_nv_seed_read(...)/mbedtls_nv_seed_write(...). 3. Don't define MBEDTLS_PSA_INJECT_ENTROPY. Meet mbedtls_psa_inject_entropy(...) undefined and then provide custom one, which must be compatible with mbedtls_nv_seed_read(...)/mbedtls_nv_seed_write(...) above. 4. For development, simulating partial provision process, inject entropy seed via mbedtls_psa_inject_entropy(...) pre-main. --- targets/TARGET_NUVOTON/TARGET_M480/objects.h | 6 +- targets/TARGET_NUVOTON/TARGET_M480/trng_api.c | 88 ------------------ .../TARGET_NUVOTON/TARGET_NUC472/objects.h | 6 +- .../TARGET_NUVOTON/TARGET_NUC472/trng_api.c | 92 ------------------- targets/targets.json | 2 - 5 files changed, 2 insertions(+), 192 deletions(-) delete mode 100644 targets/TARGET_NUVOTON/TARGET_M480/trng_api.c delete mode 100644 targets/TARGET_NUVOTON/TARGET_NUC472/trng_api.c diff --git a/targets/TARGET_NUVOTON/TARGET_M480/objects.h b/targets/TARGET_NUVOTON/TARGET_M480/objects.h index e30b101410..6a64f5edd6 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/objects.h +++ b/targets/TARGET_NUVOTON/TARGET_M480/objects.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015-2016 Nuvoton + * Copyright (c) 2015-2019 Nuvoton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,10 +118,6 @@ struct pwmout_s { uint32_t pulsewidth_us; }; -struct trng_s { - uint8_t dummy; -}; - struct can_s { CANName can; PinName pin_rd; diff --git a/targets/TARGET_NUVOTON/TARGET_M480/trng_api.c b/targets/TARGET_NUVOTON/TARGET_M480/trng_api.c deleted file mode 100644 index 305be2bd21..0000000000 --- a/targets/TARGET_NUVOTON/TARGET_M480/trng_api.c +++ /dev/null @@ -1,88 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2015-2016 Nuvoton - * - * 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. - */ - -#if DEVICE_TRNG - -#include -#include -#include "cmsis.h" -#include "us_ticker_api.h" -#include "trng_api.h" -#include "crypto-misc.h" - -/* - * Get Random number generator. - */ - -#define PRNG_KEY_SIZE (0x20UL) - -static void trng_get(unsigned char *pConversionData) -{ - uint32_t *p32ConversionData; - - p32ConversionData = (uint32_t *)pConversionData; - - PRNG_Open(PRNG_KEY_SIZE_256, 1, us_ticker_read()); - crypto_prng_prestart(); - PRNG_Start(); - crypto_prng_wait(); - - PRNG_Read(p32ConversionData); -} - -void trng_init(trng_t *obj) -{ - (void)obj; - - /* Init crypto module */ - crypto_init(); - - PRNG_ENABLE_INT(); -} - -void trng_free(trng_t *obj) -{ - (void)obj; - - PRNG_DISABLE_INT(); - - /* Uninit crypto module */ - crypto_uninit(); -} - -int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) -{ - (void)obj; - unsigned char tmpBuff[PRNG_KEY_SIZE]; - size_t cur_length = 0; - - while (length >= sizeof(tmpBuff)) { - trng_get(output); - output += sizeof(tmpBuff); - cur_length += sizeof(tmpBuff); - length -= sizeof(tmpBuff); - } - if (length > 0) { - trng_get(tmpBuff); - memcpy(output, tmpBuff, length); - cur_length += length; - crypto_zeroize(tmpBuff, sizeof(tmpBuff)); - } - *output_length = cur_length; - return 0; -} - -#endif diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/objects.h b/targets/TARGET_NUVOTON/TARGET_NUC472/objects.h index fe9caf1c14..3536afb480 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/objects.h +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/objects.h @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015-2016 Nuvoton + * Copyright (c) 2015-2019 Nuvoton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,10 +114,6 @@ struct pwmout_s { uint32_t pulsewidth_us; }; -struct trng_s { - uint8_t dummy; -}; - struct can_s { CANName can; PinName pin_rd; diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/trng_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/trng_api.c deleted file mode 100644 index 153e1ef42c..0000000000 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/trng_api.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Hardware entropy collector for NUC472's RNGA - * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - * - */ - -#if DEVICE_TRNG - -#include -#include -#include "cmsis.h" -#include "us_ticker_api.h" -#include "trng_api.h" -#include "crypto-misc.h" - -/* - * Get Random number generator. - */ - -#define PRNG_KEY_SIZE (0x20UL) - -static void trng_get(unsigned char *pConversionData) -{ - uint32_t *p32ConversionData; - - p32ConversionData = (uint32_t *)pConversionData; - - PRNG_Open(PRNG_KEY_SIZE_256, 1, us_ticker_read()); - crypto_prng_prestart(); - PRNG_Start(); - crypto_prng_wait(); - - PRNG_Read(p32ConversionData); -} - -void trng_init(trng_t *obj) -{ - (void)obj; - - /* Init crypto module */ - crypto_init(); - - PRNG_ENABLE_INT(); -} - -void trng_free(trng_t *obj) -{ - (void)obj; - - PRNG_DISABLE_INT(); - - /* Uninit crypto module */ - crypto_uninit(); -} - -int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) -{ - (void)obj; - unsigned char tmpBuff[PRNG_KEY_SIZE]; - size_t cur_length = 0; - - while (length >= sizeof(tmpBuff)) { - trng_get(output); - output += sizeof(tmpBuff); - cur_length += sizeof(tmpBuff); - length -= sizeof(tmpBuff); - } - if (length > 0) { - trng_get(tmpBuff); - memcpy(output, tmpBuff, length); - cur_length += length; - crypto_zeroize(tmpBuff, sizeof(tmpBuff)); - } - *output_length = cur_length; - return 0; -} - -#endif diff --git a/targets/targets.json b/targets/targets.json index e7c1ab980d..afc134ba1e 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -7980,7 +7980,6 @@ "SPI", "SPISLAVE", "SPI_ASYNCH", - "TRNG", "CAN", "FLASH", "EMAC", @@ -8629,7 +8628,6 @@ "SPI", "SPISLAVE", "SPI_ASYNCH", - "TRNG", "FLASH", "CAN", "EMAC",