Skip to content

Commit 4118afa

Browse files
committed
[M487/NUC472] TRN_Get support 32 bytes unalignment
1 parent 863b3fd commit 4118afa

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

targets/TARGET_NUVOTON/TARGET_M480/trng_api.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ void trng_free(trng_t *obj)
7777
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
7878
{
7979
(void)obj;
80-
80+
unsigned char tmpBuff[32];
81+
8182
*output_length = 0;
8283
if (length < 32) {
83-
unsigned char tmpBuff[32];
8484
trng_get(tmpBuff);
8585
memcpy(output, &tmpBuff, length);
8686
*output_length = length;
@@ -89,6 +89,11 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
8989
trng_get(output);
9090
*output_length += 32;
9191
output += 32;
92+
}
93+
if( length > *output_length ) {
94+
trng_get(tmpBuff);
95+
memcpy(output, &tmpBuff, (length - *output_length));
96+
*output_length = length;
9297
}
9398
}
9499

targets/TARGET_NUVOTON/TARGET_NUC472/trng_api.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,23 @@ void trng_free(trng_t *obj)
8282
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
8383
{
8484
(void)obj;
85-
85+
unsigned char tmpBuff[32];
86+
8687
*output_length = 0;
8788
if (length < 32) {
88-
unsigned char tmpBuff[32];
8989
trng_get(tmpBuff);
9090
memcpy(output, &tmpBuff, length);
9191
*output_length = length;
9292
} else {
93-
for (int i = 0; i < (length/32); i++) {
93+
for (unsigned i = 0; i < (length/32); i++) {
9494
trng_get(output);
9595
*output_length += 32;
9696
output += 32;
97+
}
98+
if( length > *output_length ) {
99+
trng_get(tmpBuff);
100+
memcpy(output, &tmpBuff, (length - *output_length));
101+
*output_length = length;
97102
}
98103
}
99104

0 commit comments

Comments
 (0)