Merge "Remove unused openssl-devel dependency" into tizen
[platform/upstream/iotivity.git] / resource / c_common / ocrandom / src / ocrandom.c
index 631906c..1c43edb 100644 (file)
@@ -191,9 +191,23 @@ void OCFillRandomMem(uint8_t * location, uint16_t len)
     {
         return;
     }
-    for (; len--;)
+    uint16_t i, rand_idx;
+    uint8_t *loc;
+    i = len;
+    loc = location;
+    for (; i--;)
     {
-        *location++ = OCGetRandomByte();
+        *loc++ = OCGetRandomByte();
+    }
+    uint8_t temp;
+    i = len;
+    while(i > 1)
+    {
+        rand_idx = lrand48() % i;
+        temp = location[i - 1];
+        location[i - 1] = location[rand_idx];
+        location[rand_idx] = temp;
+        i--;
     }
 }
 
@@ -213,6 +227,16 @@ uint8_t OCGetRandomByte(void)
 #endif
 }
 
+uint16_t OCGetRandomTwoByte(void)
+{
+#ifdef HAVE_SRANDOM
+    return random() & 0x00FFFF;
+#else
+    return rand() & 0x00FFFF;
+#endif
+}
+
+
 uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound)
 {
     uint32_t base;