aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-10-27 11:44:33 +0200
committerpedroGitt <pedro.contreiras@amdocs.com>2016-10-27 11:44:33 +0200
commit31f8fe23c5de0cf226f5061552c02a5bdc767b6a (patch)
tree229d49626c0cdeb0a3f7cb70f1e4348298d57336
parent6204fcd128279f876723eb2afefb6d278830465f (diff)
Fix random issue: increase random seed precision to micro secAndroidSdk_v0.1.0
- previously the random seed was seconds based, and it could originate identical identity keys for different OlmAccount
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
index 5910c42..239fc68 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
@@ -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;