aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--matrix-e2e.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/matrix-e2e.c b/matrix-e2e.c
index dbd7dd1..2e3acd9 100644
--- a/matrix-e2e.c
+++ b/matrix-e2e.c
@@ -22,6 +22,7 @@
#include "matrix-api.h"
#include "matrix-e2e.h"
#include "matrix-json.h"
+#include "debug.h"
/* json-glib */
#include <json-glib/json-glib.h>
@@ -50,6 +51,25 @@ static void clear_mem(volatile char *data, size_t len)
#endif
}
+/* Returns a pointer to a freshly allocated buffer of 'n' bytes of random data.
+ * If it fails it returns NULL.
+ * TODO: There must be some portable function we can call to do this.
+ */
+static void *get_random(size_t n)
+{
+ FILE *urandom = fopen("/dev/urandom", "rb");
+ if (!urandom) {
+ return NULL;
+ }
+ void *buffer = g_malloc(n);
+ if (fread(buffer, 1, n, urandom) != n) {
+ g_free(buffer);
+ buffer = NULL;
+ }
+ fclose(urandom);
+ return buffer;
+}
+
/* Sign the JsonObject with olm_account_sign and add it to the object
* as a 'signatures' member of the top level object.
* 0 on success