summaryrefslogtreecommitdiff
path: root/code/init.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-05-03 21:10:08 +0200
committerUros Majstorovic <majstor@majstor.org>2017-05-03 21:10:08 +0200
commit25de5e761daab8b897a4f09ff8503e6f43c299f9 (patch)
treea9a1c185c7f89d67f9250e42b2aa53eefc9a6770 /code/init.c
initial commit
Diffstat (limited to 'code/init.c')
-rw-r--r--code/init.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/code/init.c b/code/init.c
new file mode 100644
index 0000000..ba792f0
--- /dev/null
+++ b/code/init.c
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "core.h"
+
+static int v_rng(void *buf, size_t bufsize) {
+ int fd;
+
+ if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1;
+ size_t nb = read(fd, buf, bufsize);
+ close(fd);
+ if (nb != bufsize) return -1;
+ return 0;
+}
+
+static ECPConnection *conn_alloc(void) {
+ return malloc(sizeof(ECPConnection));
+}
+
+static void conn_free(ECPConnection *conn) {
+ free(conn);
+}
+
+int ecp_init(ECPContext *ctx) {
+ int rv;
+
+ rv = ecp_ctx_create(ctx);
+ if (rv) return rv;
+
+ ctx->rng = v_rng;
+ ctx->conn_alloc = conn_alloc;
+ ctx->conn_free = conn_free;
+
+ return ECP_OK;
+} \ No newline at end of file