summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-03-31 13:17:48 +0200
committerUros Majstorovic <majstor@majstor.org>2022-03-31 13:17:48 +0200
commit4e2c7b2b070699b9f0a9cfe75de8316866cc5ed1 (patch)
treef63e7a1d58267bef3941c63341c71b11c18555a1 /fw/fe310
parentf2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (diff)
random numbers for fe310
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/eos/rng.c27
-rw-r--r--fw/fe310/eos/rng.h5
2 files changed, 32 insertions, 0 deletions
diff --git a/fw/fe310/eos/rng.c b/fw/fe310/eos/rng.c
new file mode 100644
index 0000000..317941d
--- /dev/null
+++ b/fw/fe310/eos/rng.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "net.h"
+
+int getentropy(unsigned char *b, size_t sz) {
+ unsigned char type;
+ unsigned char *buffer;
+ uint16_t len;
+ int rv;
+
+ buffer = eos_net_alloc();
+
+ type = EOS_NET_MTYPE_RNG;
+ len = sizeof(uint16_t);
+ buffer[0] = sz >> 8;
+ buffer[1] = sz;
+
+ rv = eos_net_xchg(&type, buffer, &len);
+ if (rv || (len != sz)) rv = -1;
+
+ if (!rv) memcpy(b, buffer, sz);
+ eos_net_free(buffer, 1);
+
+ return rv;
+}
diff --git a/fw/fe310/eos/rng.h b/fw/fe310/eos/rng.h
new file mode 100644
index 0000000..27bbf74
--- /dev/null
+++ b/fw/fe310/eos/rng.h
@@ -0,0 +1,5 @@
+#include <stdlib.h>
+
+int getentropy(unsigned char *b, size_t sz);
+int arc4random_alloc(void **rsp, size_t rsp_size, void **rsxp, size_t rsxp_size);
+void arc4random_close(void **rsp, void **rsxp); \ No newline at end of file