mirror of https://github.com/ARMmbed/mbed-os.git
[M487/NUC472] TRN_Get support 32 bytes unalignment
parent
863b3fdcc1
commit
4118afa259
|
@ -77,10 +77,10 @@ void trng_free(trng_t *obj)
|
||||||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
|
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
unsigned char tmpBuff[32];
|
||||||
|
|
||||||
*output_length = 0;
|
*output_length = 0;
|
||||||
if (length < 32) {
|
if (length < 32) {
|
||||||
unsigned char tmpBuff[32];
|
|
||||||
trng_get(tmpBuff);
|
trng_get(tmpBuff);
|
||||||
memcpy(output, &tmpBuff, length);
|
memcpy(output, &tmpBuff, length);
|
||||||
*output_length = length;
|
*output_length = length;
|
||||||
|
@ -90,6 +90,11 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
|
||||||
*output_length += 32;
|
*output_length += 32;
|
||||||
output += 32;
|
output += 32;
|
||||||
}
|
}
|
||||||
|
if( length > *output_length ) {
|
||||||
|
trng_get(tmpBuff);
|
||||||
|
memcpy(output, &tmpBuff, (length - *output_length));
|
||||||
|
*output_length = length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -82,19 +82,24 @@ void trng_free(trng_t *obj)
|
||||||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
|
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
unsigned char tmpBuff[32];
|
||||||
|
|
||||||
*output_length = 0;
|
*output_length = 0;
|
||||||
if (length < 32) {
|
if (length < 32) {
|
||||||
unsigned char tmpBuff[32];
|
|
||||||
trng_get(tmpBuff);
|
trng_get(tmpBuff);
|
||||||
memcpy(output, &tmpBuff, length);
|
memcpy(output, &tmpBuff, length);
|
||||||
*output_length = length;
|
*output_length = length;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < (length/32); i++) {
|
for (unsigned i = 0; i < (length/32); i++) {
|
||||||
trng_get(output);
|
trng_get(output);
|
||||||
*output_length += 32;
|
*output_length += 32;
|
||||||
output += 32;
|
output += 32;
|
||||||
}
|
}
|
||||||
|
if( length > *output_length ) {
|
||||||
|
trng_get(tmpBuff);
|
||||||
|
memcpy(output, &tmpBuff, (length - *output_length));
|
||||||
|
*output_length = length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue