Skip to content

Commit cba28cc

Browse files
authored
Merge pull request #6221 from codeauroraforum/Add_RNG_LPC54XXX
LPC546XX: Add TRNG support
2 parents 7aa293b + 76c8a1b commit cba28cc

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/objects.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ struct spi_s {
5858
uint8_t bits;
5959
};
6060

61-
#if DEVICE_FLASH
61+
#if defined(DEVICE_FLASH)
6262
struct flash_s {
6363
uint8_t dummy;
6464
};
6565
#endif
6666

67+
#if defined(DEVICE_TRNG)
68+
struct trng_s {
69+
uint8_t dummy;
70+
};
71+
#endif
72+
6773
#include "gpio_object.h"
6874

6975
#ifdef __cplusplus
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "trng_api.h"
18+
19+
#if defined(DEVICE_TRNG)
20+
#include "fsl_rng.h"
21+
22+
void trng_init(trng_t *obj)
23+
{
24+
}
25+
26+
void trng_free(trng_t *obj)
27+
{
28+
}
29+
30+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
31+
{
32+
uint32_t skip;
33+
uint32_t data;
34+
size_t idx = 0;
35+
int i;
36+
37+
/* Get Random data */
38+
while (idx < length) {
39+
40+
data = RNG_GetRandomData();
41+
42+
for (i = 0; ((i < 4) && (idx < length)); i++) {
43+
output[idx++] = (data >> (i * 8)) & 0xFF;
44+
}
45+
46+
/* Skip next 32 random numbers for better entropy */
47+
for (skip = 0; skip < 32; skip++) {
48+
RNG_GetRandomData();
49+
}
50+
}
51+
52+
*output_length = idx;
53+
54+
/* Zeroize to avoid leakage of entropy on the stack. Also ensure this is not removed by compiler optimizations */
55+
*((volatile uint32_t*) &data) = 0;
56+
57+
return (idx == length ? 0 : -1);
58+
}
59+
#endif

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@
754754
"is_disk_virtual": true,
755755
"macros": ["CPU_LPC54628J512ET180", "FSL_RTOS_MBED"],
756756
"inherits": ["Target"],
757-
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
757+
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH", "TRNG"],
758758
"features": ["LWIP"],
759759
"device_name" : "LPC54628J512ET180"
760760
},

0 commit comments

Comments
 (0)