summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos
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/esp32/components/eos
parentf2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (diff)
random numbers for fe310
Diffstat (limited to 'fw/esp32/components/eos')
-rw-r--r--fw/esp32/components/eos/include/rng.h1
-rw-r--r--fw/esp32/components/eos/rng.c31
2 files changed, 32 insertions, 0 deletions
diff --git a/fw/esp32/components/eos/include/rng.h b/fw/esp32/components/eos/include/rng.h
new file mode 100644
index 0000000..0690973
--- /dev/null
+++ b/fw/esp32/components/eos/include/rng.h
@@ -0,0 +1 @@
+void eos_rng_init(void);
diff --git a/fw/esp32/components/eos/rng.c b/fw/esp32/components/eos/rng.c
new file mode 100644
index 0000000..79eca21
--- /dev/null
+++ b/fw/esp32/components/eos/rng.c
@@ -0,0 +1,31 @@
+#include <esp_system.h>
+#include <esp_log.h>
+#include <esp_err.h>
+
+#include "net.h"
+#include "rng.h"
+
+static const char *TAG = "EOS RNG";
+
+static void rng_handler(unsigned char type, unsigned char *buffer, uint16_t buf_len) {
+ uint16_t rng_len = 0;
+
+ if (buf_len < sizeof(uint16_t)) goto rng_handler_fin;
+
+ rng_len = (uint16_t)buffer[0] << 8;
+ rng_len |= (uint16_t)buffer[1];
+ if (rng_len > EOS_NET_MTU) {
+ rng_len = 0;
+ goto rng_handler_fin;
+ }
+ esp_fill_random(buffer, rng_len);
+
+rng_handler_fin:
+ eos_net_reply(EOS_NET_MTYPE_RNG, buffer, rng_len);
+}
+
+void eos_rng_init(void) {
+ eos_net_set_handler(EOS_NET_MTYPE_RNG, rng_handler);
+ ESP_LOGI(TAG, "INIT");
+}
+