AP_HAL_SITL: add support for hw random number generation

This commit is contained in:
Siddharth Purohit 2021-06-24 22:20:23 +05:30 committed by Andrew Tridgell
parent f2e947589d
commit 1082046134
2 changed files with 20 additions and 0 deletions

View File

@ -162,3 +162,20 @@ void HALSITL::Util::commandline_arguments(uint8_t &argc, char * const *&argv)
argv = saved_argv;
}
/**
* This method will read random values with set size.
*/
bool HALSITL::Util::get_random_vals(uint8_t* data, size_t size)
{
int dev_random = open("/dev/urandom", O_RDONLY);
if (dev_random < 0) {
return false;
}
ssize_t result = read(dev_random, data, size);
if (result < 0) {
close(dev_random);
return false;
}
close(dev_random);
return true;
}

View File

@ -81,6 +81,9 @@ public:
saved_argv = argv;
}
// fills data with random values of requested size
bool get_random_vals(uint8_t* data, size_t size) override;
private:
SITL_State *sitlState;