esp32: Add esp_fill_random() function
Convenience function to fill a buffer with random bytes. Add some unit tests (only sanity checks, really.)
This commit is contained in:
@@ -61,11 +61,7 @@ static struct blufi_security *blufi_sec;
|
||||
|
||||
static int myrand( void *rng_state, unsigned char *output, size_t len )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for( i = 0; i < len; ++i )
|
||||
output[i] = esp_random();
|
||||
|
||||
esp_fill_random(output, len);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,6 @@ int example_espnow_data_parse(uint8_t *data, uint16_t data_len, uint8_t *state,
|
||||
void example_espnow_data_prepare(example_espnow_send_param_t *send_param)
|
||||
{
|
||||
example_espnow_data_t *buf = (example_espnow_data_t *)send_param->buffer;
|
||||
int i = 0;
|
||||
|
||||
assert(send_param->len >= sizeof(example_espnow_data_t));
|
||||
|
||||
@@ -153,9 +152,8 @@ void example_espnow_data_prepare(example_espnow_send_param_t *send_param)
|
||||
buf->seq_num = s_example_espnow_seq[buf->type]++;
|
||||
buf->crc = 0;
|
||||
buf->magic = send_param->magic;
|
||||
for (i = 0; i < send_param->len - sizeof(example_espnow_data_t); i++) {
|
||||
buf->payload[i] = (uint8_t)esp_random();
|
||||
}
|
||||
/* Fill all remaining bytes after the data with random values */
|
||||
esp_fill_random(buf->payload, send_param->len - sizeof(example_espnow_data_t));
|
||||
buf->crc = crc16_le(UINT16_MAX, (uint8_t const *)buf, send_param->len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user