Skip to content

Commit ea1041e

Browse files
committed
HAL - RNG rename to TRNG
1 parent da1b423 commit ea1041e

File tree

18 files changed

+76
-75
lines changed

18 files changed

+76
-75
lines changed

features/mbedtls/mbed_rng.c renamed to features/mbedtls/mbed_trng.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "hal/rng_api.h"
17+
#include "hal/trng_api.h"
1818

19-
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) && defined(DEVICE_RNG)
19+
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) && defined(DEVICE_TRNG)
2020

2121
int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen ) {
22-
rng_t rng_obj;
23-
rng_init(&rng_obj);
24-
int ret = rng_get_bytes(&rng_obj, output, len, olen);
25-
rng_free(&rng_obj);
22+
trng_t trng_obj;
23+
trng_init(&trng_obj);
24+
int ret = trng_get_bytes(&trng_obj, output, len, olen);
25+
trng_free(&trng_obj);
2626
return ret;
2727
}
2828

hal/hal/rng_api.h renamed to hal/hal/trng_api.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,55 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef MBED_RNG_API_H
17-
#define MBED_RNG_API_H
16+
#ifndef MBED_TRNG_API_H
17+
#define MBED_TRNG_API_H
1818

1919
#include <stddef.h>
2020
#include "device.h"
2121

22-
#if DEVICE_RNG
22+
#if DEVICE_TRNG
2323

24-
/** RNG HAL structure. rng_s is declared in the target's HAL
24+
/** TRNG HAL structure. trng_s is declared in the target's HAL
2525
*/
26-
typedef struct rng_s rng_t;
26+
typedef struct trng_s trng_t;
2727

2828
#ifdef __cplusplus
2929
extern "C" {
3030
#endif
3131

3232
/**
33-
* \defgroup hal_rng RNG hal functions
33+
* \defgroup hal_trng TRNG hal functions
3434
* @{
3535
*/
3636

37-
/** Initialize the RNG peripheral
37+
/** Initialize the TRNG peripheral
3838
*
39-
* @param obj The RNG object
39+
* @param obj The TRNG object
4040
*/
41-
void rng_init(rng_t *obj);
41+
void trng_init(trng_t *obj);
4242

43-
/** Deinitialize the RNG peripheral
43+
/** Deinitialize the TRNG peripheral
4444
*
45-
* @param obj The RNG object
45+
* @param obj The TRNG object
4646
*/
47-
void rng_free(rng_t *obj);
47+
void trng_free(trng_t *obj);
4848

49-
/** Get random data from RNG peripheral
49+
/** Get random data from TRNG peripheral
5050
*
51-
* @param obj The RNG object
51+
* @param obj The TRNG object
5252
* @param output The pointer to an output array
5353
* @param length The length of output data
5454
* @param output_length The length of generated data
5555
* @return 0 success, -1 fail
5656
*/
57-
int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_length);
57+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length);
5858

5959
/** Set an external entropy value
6060
*
61-
* @param obj The RNG object
61+
* @param obj The TRNG object
6262
* @param seed_value Entropy value to be set
6363
*/
64-
void rng_set_seed(rng_t *obj, uint32_t seed_value);
64+
void trng_set_seed(trng_t *obj, uint32_t seed_value);
6565

6666
/**@}*/
6767

hal/targets.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@
565565
"inherits": ["Target"],
566566
"progen": {"target": "frdm-k64f"},
567567
"detect_code": ["0240"],
568-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "RNG"],
568+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "TRNG"],
569569
"features": ["IPV4", "STORAGE"],
570570
"release_versions": ["2", "5"]
571571
},
@@ -603,7 +603,7 @@
603603
"inherits": ["Target"],
604604
"progen": {"target": "frdm-k66f"},
605605
"detect_code": ["0311"],
606-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "RNG"],
606+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
607607
"release_versions": ["2", "5"]
608608
},
609609
"NUCLEO_F030R8": {
@@ -795,7 +795,7 @@
795795
"progen": {"target": "nucleo-f410rb"},
796796
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "TRANSACTION_QUEUE_SIZE_SPI=2"],
797797
"detect_code": ["0740"],
798-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "RNG"],
798+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
799799
"release_versions": ["2", "5"]
800800
},
801801
"NUCLEO_F411RE": {
@@ -833,7 +833,7 @@
833833
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
834834
"progen": {"target": "nucleo-f429zi"},
835835
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "DEVICE_RTC_LSI=1", "TRANSACTION_QUEUE_SIZE_SPI=2"],
836-
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
836+
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
837837
"detect_code": ["0796"],
838838
"features": ["IPV4"],
839839
"release_versions": ["2", "5"]
@@ -1077,7 +1077,7 @@
10771077
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","DEVICE_RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"],
10781078
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
10791079
"progen": {"target": "disco-f429zi"},
1080-
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "RNG"],
1080+
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
10811081
"release_versions": ["2", "5"]
10821082
},
10831083
"DISCO_F469NI": {
@@ -1090,7 +1090,7 @@
10901090
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","TRANSACTION_QUEUE_SIZE_SPI=2"],
10911091
"progen": {"target": "disco-f469ni"},
10921092
"detect_code": ["0788"],
1093-
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "RNG"],
1093+
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
10941094
"release_versions": ["2", "5"]
10951095
},
10961096
"DISCO_L053C8": {
@@ -2088,7 +2088,7 @@
20882088
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
20892089
"inherits": ["Target"],
20902090
"progen": {"target": "numaker-pfm-nuc472"},
2091-
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "RNG"],
2091+
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG"],
20922092
"features": ["IPV4"],
20932093
"release_versions": ["2", "5"]
20942094
},

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K66F/rng_api.c renamed to hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K66F/trng_api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
#include "cmsis.h"
2727
#include "fsl_common.h"
2828
#include "fsl_clock.h"
29-
#include "rng_api.h"
29+
#include "trng_api.h"
3030

31-
void rng_init(rng_t *obj)
31+
void trng_init(trng_t *obj)
3232
{
3333
(void)obj;
3434
CLOCK_EnableClock(kCLOCK_Rnga0);
3535
CLOCK_DisableClock(kCLOCK_Rnga0);
3636
CLOCK_EnableClock(kCLOCK_Rnga0);
3737
}
3838

39-
void rng_free(rng_t *obj)
39+
void trng_free(trng_t *obj)
4040
{
4141
(void)obj;
4242
CLOCK_DisableClock(kCLOCK_Rnga0);
@@ -46,7 +46,7 @@ void rng_free(rng_t *obj)
4646
* Get one byte of entropy from the RNG, assuming it is up and running.
4747
* As recommended (34.1.1), get only one bit of each output.
4848
*/
49-
static void rng_get_byte(unsigned char *byte)
49+
static void trng_get_byte(unsigned char *byte)
5050
{
5151
size_t bit;
5252

@@ -58,7 +58,7 @@ static void rng_get_byte(unsigned char *byte)
5858
}
5959
}
6060

61-
int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_length)
61+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
6262
{
6363
(void)obj;
6464
size_t i;
@@ -69,7 +69,7 @@ int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_len
6969
RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK;
7070

7171
for (i = 0; i < length; i++) {
72-
rng_get_byte(output + i);
72+
trng_get_byte(output + i);
7373
}
7474

7575
/* Just be extra sure that we didn't do it wrong */

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_MCU_K64F/rng_api.c renamed to hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_MCU_K64F/trng_api.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
#include "cmsis.h"
2727
#include "fsl_common.h"
2828
#include "fsl_clock.h"
29-
#include "rng_api.h"
29+
#include "trng_api.h"
3030

31-
void rng_init(rng_t *obj)
31+
void trng_init(trng_t *obj)
3232
{
3333
(void)obj;
3434
CLOCK_EnableClock(kCLOCK_Rnga0);
3535
CLOCK_DisableClock(kCLOCK_Rnga0);
3636
CLOCK_EnableClock(kCLOCK_Rnga0);
3737
}
3838

39-
void rng_free(rng_t *obj)
39+
void trng_free(trng_t *obj)
4040
{
4141
(void)obj;
4242
CLOCK_DisableClock(kCLOCK_Rnga0);
@@ -46,19 +46,19 @@ void rng_free(rng_t *obj)
4646
* Get one byte of entropy from the RNG, assuming it is up and running.
4747
* As recommended (34.1.1), get only one bit of each output.
4848
*/
49-
static void rng_get_byte(unsigned char *byte)
49+
static void trng_get_byte(unsigned char *byte)
5050
{
5151
size_t bit;
5252

5353
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
5454
for( bit = 0; bit < 8; bit++ )
5555
{
56-
while( ( RNG->SR & RNG_SR_OREG_LVL_MASK ) == 0 );
57-
*byte |= ( RNG->OR & 1 ) << bit;
56+
while((RNG->SR & RNG_SR_OREG_LVL_MASK) == 0 );
57+
*byte |= (RNG->OR & 1) << bit;
5858
}
5959
}
6060

61-
int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_length)
61+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
6262
{
6363
(void)obj;
6464
size_t i;
@@ -69,7 +69,7 @@ int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_len
6969
RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK;
7070

7171
for (i = 0; i < length; i++) {
72-
rng_get_byte(output + i);
72+
trng_get_byte(output + i);
7373
}
7474

7575
/* Just be extra sure that we didn't do it wrong */

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct dac_s {
6161
DACName dac;
6262
};
6363

64-
struct rng_s {
64+
struct trng_s {
6565

6666
};
6767

hal/targets/hal/TARGET_NUVOTON/TARGET_NUC472/TARGET_NUMAKER_PFM_NUC472/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct sleep_s {
124124
int powerdown;
125125
};
126126

127-
struct rng_s {
127+
struct trng_s {
128128

129129
};
130130

hal/targets/hal/TARGET_NUVOTON/TARGET_NUC472/rng_api.c renamed to hal/targets/hal/TARGET_NUVOTON/TARGET_NUC472/trng_api.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "cmsis.h"
2525
#include "NUC472_442.h"
2626
#include "us_ticker_api.h"
27-
#include "rng_api.h"
27+
#include "trng_api.h"
2828

2929
/*
3030
* Get Random number generator.
@@ -39,7 +39,7 @@ void CRYPTO_IRQHandler()
3939
}
4040
}
4141

42-
static void rng_get(unsigned char *pConversionData)
42+
static void trng_get(unsigned char *pConversionData)
4343
{
4444
uint32_t *p32ConversionData;
4545

@@ -52,7 +52,7 @@ static void rng_get(unsigned char *pConversionData)
5252
PRNG_Read(p32ConversionData);
5353
}
5454

55-
void rng_init(rng_t *obj)
55+
void trng_init(trng_t *obj)
5656
{
5757
(void)obj;
5858
/* Unlock protected registers */
@@ -67,26 +67,26 @@ void rng_init(rng_t *obj)
6767
PRNG_ENABLE_INT();
6868
}
6969

70-
void rng_free(rng_t *obj)
70+
void trng_free(trng_t *obj)
7171
{
7272
(void)obj;
7373
PRNG_DISABLE_INT();
7474
NVIC_DisableIRQ(CRPT_IRQn);
7575
}
7676

77-
int rng_get_bytes(rng_t *obj, uint8_t *output, size_t length, size_t *output_length)
77+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
7878
{
7979
(void)obj;
8080

8181
*output_length = 0;
8282
if (length < 32) {
8383
unsigned char tmpBuff[32];
84-
rng_get(tmpBuff);
84+
trng_get(tmpBuff);
8585
memcpy(output, &tmpBuff, length);
8686
*output_length = length;
8787
} else {
8888
for (int i = 0; i < (length/32); i++) {
89-
rng_get(output);
89+
trng_get(output);
9090
*output_length += 32;
9191
output += 32;
9292
}

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct can_s {
7070
int index;
7171
};
7272

73-
struct rng_s {
73+
struct trng_s {
7474
RNG_HandleTypeDef handle;
7575
};
7676

hal/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct can_s {
7070
int index;
7171
};
7272

73-
struct rng_s {
73+
struct trng_s {
7474
RNG_HandleTypeDef handle;
7575
};
7676

0 commit comments

Comments
 (0)