[M487/NUC472] TRN_Get support 32 bytes unalignment

pull/5454/head
cyliangtw 2017-11-08 14:23:05 +08:00
parent 863b3fdcc1
commit 4118afa259
2 changed files with 15 additions and 5 deletions

View File

@ -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)
{
(void)obj;
unsigned char tmpBuff[32];
*output_length = 0;
if (length < 32) {
unsigned char tmpBuff[32];
trng_get(tmpBuff);
memcpy(output, &tmpBuff, length);
*output_length = length;
@ -89,6 +89,11 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
trng_get(output);
*output_length += 32;
output += 32;
}
if( length > *output_length ) {
trng_get(tmpBuff);
memcpy(output, &tmpBuff, (length - *output_length));
*output_length = length;
}
}

View File

@ -82,18 +82,23 @@ void trng_free(trng_t *obj)
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{
(void)obj;
unsigned char tmpBuff[32];
*output_length = 0;
if (length < 32) {
unsigned char tmpBuff[32];
trng_get(tmpBuff);
memcpy(output, &tmpBuff, length);
*output_length = length;
} else {
for (int i = 0; i < (length/32); i++) {
for (unsigned i = 0; i < (length/32); i++) {
trng_get(output);
*output_length += 32;
output += 32;
}
if( length > *output_length ) {
trng_get(tmpBuff);
memcpy(output, &tmpBuff, (length - *output_length));
*output_length = length;
}
}