mirror of https://github.com/ARMmbed/mbed-os.git
Add entropy functions for STM32F4 and STM32F7 family
parent
2e4d9847e4
commit
31a410bfad
|
@ -773,6 +773,7 @@
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"inherits": ["Target"],
|
"inherits": ["Target"],
|
||||||
"progen": {"target": "nucleo-f410rb"},
|
"progen": {"target": "nucleo-f410rb"},
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"detect_code": ["0740"],
|
"detect_code": ["0740"],
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
"release_versions": ["2", "5"]
|
"release_versions": ["2", "5"]
|
||||||
|
@ -809,7 +810,8 @@
|
||||||
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI"],
|
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"progen": {"target": "nucleo-f429zi"},
|
"progen": {"target": "nucleo-f429zi"},
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
|
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
"detect_code": ["0796"],
|
"detect_code": ["0796"],
|
||||||
"features": ["IPV4"],
|
"features": ["IPV4"],
|
||||||
"release_versions": ["2", "5"]
|
"release_versions": ["2", "5"]
|
||||||
|
@ -856,6 +858,7 @@
|
||||||
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746ZG"],
|
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746ZG"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"default_toolchain": "ARM",
|
"default_toolchain": "ARM",
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"progen": {
|
"progen": {
|
||||||
"target": "nucleo-f746zg",
|
"target": "nucleo-f746zg",
|
||||||
"iar": {
|
"iar": {
|
||||||
|
@ -874,6 +877,7 @@
|
||||||
"extra_labels": ["STM", "STM32F7", "STM32F767", "STM32F767ZI"],
|
"extra_labels": ["STM", "STM32F7", "STM32F767", "STM32F767ZI"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"default_toolchain": "ARM",
|
"default_toolchain": "ARM",
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"progen": {"target": "nucleo-f767zi"},
|
"progen": {"target": "nucleo-f767zi"},
|
||||||
"detect_code": ["0818"],
|
"detect_code": ["0818"],
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
|
@ -1040,6 +1044,7 @@
|
||||||
"core": "Cortex-M4F",
|
"core": "Cortex-M4F",
|
||||||
"default_toolchain": "ARM",
|
"default_toolchain": "ARM",
|
||||||
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI"],
|
"extra_labels": ["STM", "STM32F4", "STM32F429", "STM32F429ZI"],
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"progen": {"target": "disco-f429zi"},
|
"progen": {"target": "disco-f429zi"},
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
|
@ -1052,6 +1057,7 @@
|
||||||
"extra_labels": ["STM", "STM32F4", "STM32F469", "STM32F469NI"],
|
"extra_labels": ["STM", "STM32F4", "STM32F469", "STM32F469NI"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
||||||
"inherits": ["Target"],
|
"inherits": ["Target"],
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"progen": {"target": "disco-f469ni"},
|
"progen": {"target": "disco-f469ni"},
|
||||||
"detect_code": ["0788"],
|
"detect_code": ["0788"],
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
|
@ -1073,6 +1079,7 @@
|
||||||
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746NG"],
|
"extra_labels": ["STM", "STM32F7", "STM32F746", "STM32F746NG"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"default_toolchain": "ARM",
|
"default_toolchain": "ARM",
|
||||||
|
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT"],
|
||||||
"progen": {"target": "disco-f746ng"},
|
"progen": {"target": "disco-f746ng"},
|
||||||
"detect_code": ["0815"],
|
"detect_code": ["0815"],
|
||||||
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Hardware entropy collector for the STM32F4 family
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016, 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 defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
|
||||||
|
defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
|
||||||
|
defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F469xx) ||\
|
||||||
|
defined(STM32F479xx)
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
/* RNG handler declaration */
|
||||||
|
RNG_HandleTypeDef RngHandle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get one byte of entropy from the RNG, assuming it is up and running.
|
||||||
|
*/
|
||||||
|
static void rng_get_byte( unsigned char *byte )
|
||||||
|
{
|
||||||
|
*byte = (unsigned char)HAL_RNG_GetRandomNumber(&RngHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get len bytes of entropy from the hardware RNG.
|
||||||
|
*/
|
||||||
|
int mbedtls_hardware_poll( void *data,
|
||||||
|
unsigned char *output, size_t len, size_t *olen )
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int ret;
|
||||||
|
((void) data);
|
||||||
|
|
||||||
|
/* RNG Peripheral clock enable */
|
||||||
|
__HAL_RCC_RNG_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Initialize RNG instance */
|
||||||
|
RngHandle.Instance = RNG;
|
||||||
|
HAL_RNG_Init(&RngHandle);
|
||||||
|
|
||||||
|
/* Get Random byte */
|
||||||
|
for( i = 0; i < len; i++ ){
|
||||||
|
rng_get_byte( output + i );
|
||||||
|
printf("output %i: %i\n",i,(int)*(output+i));
|
||||||
|
|
||||||
|
}
|
||||||
|
/* Just be extra sure that we didn't do it wrong */
|
||||||
|
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 )
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
*olen = len;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
/*Disable the RNG peripheral */
|
||||||
|
HAL_RNG_DeInit(&RngHandle);
|
||||||
|
/* RNG Peripheral clock disable - assume we're the only users of RNG */
|
||||||
|
__HAL_RCC_RNG_CLK_DISABLE();
|
||||||
|
|
||||||
|
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
|
||||||
|
STM32F429xx || STM32F439xx || STM32F410xx || STM32F469xx || STM32F479xx */
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Hardware entropy collector for the STM32F7 family
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
/* RNG handler declaration */
|
||||||
|
RNG_HandleTypeDef RngHandle;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get one byte of entropy from the RNG, assuming it is up and running.
|
||||||
|
*/
|
||||||
|
static void rng_get_byte( unsigned char *byte )
|
||||||
|
{
|
||||||
|
*byte = (unsigned char)HAL_RNG_GetRandomNumber(&RngHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get len bytes of entropy from the hardware RNG.
|
||||||
|
*/
|
||||||
|
int mbedtls_hardware_poll( void *data,
|
||||||
|
unsigned char *output, size_t len, size_t *olen )
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int ret;
|
||||||
|
((void) data);
|
||||||
|
|
||||||
|
/* RNG Peripheral clock enable */
|
||||||
|
__HAL_RCC_RNG_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Initialize RNG instance */
|
||||||
|
RngHandle.Instance = RNG;
|
||||||
|
HAL_RNG_Init(&RngHandle);
|
||||||
|
|
||||||
|
|
||||||
|
/* Get Random byte */
|
||||||
|
for( i = 0; i < len; i++ )
|
||||||
|
rng_get_byte( output + i );
|
||||||
|
|
||||||
|
/* Just be extra sure that we didn't do it wrong */
|
||||||
|
if( ( __HAL_RNG_GET_FLAG(&RngHandle, (RNG_FLAG_CECS|RNG_FLAG_SECS)) ) != 0 )
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
*olen = len;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
/*Disable the RNG peripheral */
|
||||||
|
HAL_RNG_DeInit(&RngHandle);
|
||||||
|
/* RNG Peripheral clock disable - assume we're the only users of RNG */
|
||||||
|
__HAL_RCC_RNG_CLK_DISABLE();
|
||||||
|
|
||||||
|
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue