#include <dirent.h>
#include <glib.h>
#include <storage-internal.h>
+#include <sys/random.h>
#include "app2sd_internals.h"
"!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
int i;
+ ssize_t s;
+ unsigned int rand_nums[PASSWD_LEN];
+
+ s = getrandom(rand_nums, sizeof(rand_nums), 0);
+ if (s < 0) {
+ _E("Failed to read random data errno : %d", errno);
+ return NULL;
+ }
/* include null byte */
passwd = (char *)malloc(sizeof(char) * (PASSWD_LEN + 1));
}
for (i = 0; i < PASSWD_LEN; i++)
- passwd[i] = charset[g_random_int() % ASCII_PASSWD_CHAR];
+ passwd[i] = charset[rand_nums[i] % ASCII_PASSWD_CHAR];
passwd[i] = '\0';
return passwd;