Skip to content
Snippets Groups Projects
Commit 31f8fe23 authored by pedroGitt's avatar pedroGitt
Browse files

Fix random issue: increase random seed precision to micro sec

- previously the random seed was seconds based, and it could originate identical identity keys for different OlmAccount
parent 6204fcd1
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
#include "olm_jni_helper.h"
#include "olm/olm.h"
#include <sys/time.h>
using namespace AndroidOlmSdk;
......@@ -31,6 +32,8 @@ using namespace AndroidOlmSdk;
bool setRandomInBuffer(uint8_t **aBuffer2Ptr, size_t aRandomSize)
{
bool retCode = false;
struct timeval timeValue;
if(NULL == aBuffer2Ptr)
{
LOGE("## setRandomInBuffer(): failure - aBuffer=NULL");
......@@ -47,10 +50,14 @@ bool setRandomInBuffer(uint8_t **aBuffer2Ptr, size_t aRandomSize)
{
LOGD("## setRandomInBuffer(): randomSize=%lu",static_cast<long unsigned int>(aRandomSize));
srand(time(NULL)); // init seed
gettimeofday(&timeValue, NULL);
srand(timeValue.tv_usec); // init seed
for(size_t i=0;i<aRandomSize;i++)
{
(*aBuffer2Ptr)[i] = (uint8_t)(rand()%ACCOUNT_CREATION_RANDOM_MODULO);
// debug purpose
//LOGD("## setRandomInBuffer(): randomBuffPtr[%ld]=%d",i, (*aBuffer2Ptr)[i]);
}
retCode = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment