mirror of
https://github.com/espressif/openthread.git
synced 2026-10-03 22:37:36 +00:00
Enhance otPlatRandomGet API to provide random stream (#471)
* Enhance otPlatRandomGet API to provide random stream
This commit is contained in:
@@ -34,6 +34,9 @@
|
||||
* This implementation is not a true random number generator and does @em satisfy the Thread requirements.
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/random.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
@@ -66,3 +69,20 @@ uint32_t otPlatRandomGet(void)
|
||||
|
||||
return mlcg;
|
||||
}
|
||||
|
||||
ThreadError otPlatSecureRandomGet(uint16_t aInputLength, uint8_t *aOutput, uint16_t *aOutputLength)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
|
||||
|
||||
for (uint16_t length = 0; length < aInputLength; length++)
|
||||
{
|
||||
aOutput[length] = (uint8_t)otPlatRandomGet();
|
||||
}
|
||||
|
||||
*aOutputLength = aInputLength;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
* This implementation is not a true random number generator and does @em satisfy the Thread requirements.
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/random.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
@@ -65,3 +68,20 @@ uint32_t otPlatRandomGet(void)
|
||||
|
||||
return mlcg;
|
||||
}
|
||||
|
||||
ThreadError otPlatSecureRandomGet(uint16_t aInputLength, uint8_t *aOutput, uint16_t *aOutputLength)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
|
||||
|
||||
for (uint16_t length = 0; length < aInputLength; length++)
|
||||
{
|
||||
aOutput[length] = (uint8_t)otPlatRandomGet();
|
||||
}
|
||||
|
||||
*aOutputLength = aInputLength;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user