summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/net/rng.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-05-13 12:45:53 +0200
committerUros Majstorovic <majstor@majstor.org>2022-05-13 12:45:53 +0200
commit412a8f99928beff605805807b0f07f6bf8d0a965 (patch)
tree366f1768ddfd32960c5d26ca3fba14e82c3b571e /fw/fe310/eos/net/rng.c
parent9ccb4db8d59ec9dab33ee8617d462f21a8bb4fa8 (diff)
code rename
Diffstat (limited to 'fw/fe310/eos/net/rng.c')
-rw-r--r--fw/fe310/eos/net/rng.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fw/fe310/eos/net/rng.c b/fw/fe310/eos/net/rng.c
new file mode 100644
index 0000000..317941d
--- /dev/null
+++ b/fw/fe310/eos/net/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;
+}