[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 2/4] lib/ukswrand: Add seed generating function


  • To: "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Wed, 16 Oct 2019 15:41:39 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HxF6Xl2Jbd9GVxQJ0BjAf12fhkwnWqUDVKz0c3Uekw4=; b=F8wz0LhbZxJNLy08MtQjz/e7FP/4oDjYeJOQ4XigKaXOMNNv1T5LfWrTBz7I/4TjfWX5rumB1vHH8g8bh3QeFspG79wze22Hr5B/s5mmoiDgSY2veWRZUUJhFEEYwrcsrBdqj106tLoaKMZYEDnnPFz+UhQPBzK+BNcA+/TdJxrUDrTTAEu71w5ZcIO8MYzirg4REUynpKVCnUHvGeja37jZ4s+pD+1AIIW2oBIfifEGYJUCVsp9a13W7+lWsZqUa1IuQXHHgNkEoQgxqFTtIvUgRDIiN9RE8HmNcuS8qTlUg13XjDlp+Pvxi2Lp/UYB8X5SgEaHb3cqqxKbrF4L6g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KHCqsbcUk+9ldlKuNpLrMQJQauEfSGhR8N/8xD3pZZO1EZYJMlyrYR+spE03dZqFbn/OR6aSwXvsdk6CxSduknMkHByBICCSOt6adizro2KOY5AIqlkzOJuy8H4CftjkTRQG7WkqphvxRJIbtzu2mzNgdwMORDNxsZ61tTCsB80tLFDwDN4WiWVd506S8U7PiTIOSfl2jRb1gIcO5sBi5CfGTUNFZS8FCJsUEbmV16ocS1XtegJyzcNC7lxd+CuUsRDOcZmNwGvznZIDoo36ezQuCXUjcug+c+RvBRSWQJgceARYvs7reZ8Rpbq759cTnPyok5eamZ1sgmlCtIG3IA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Cc: "felipe.huici@xxxxxxxxx" <felipe.huici@xxxxxxxxx>, "simon.kuenzer@xxxxxxxxx" <simon.kuenzer@xxxxxxxxx>, Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 16 Oct 2019 15:41:54 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVhDgzYDFBzLohEUi0/gZvC0olzA==
  • Thread-topic: [UNIKRAFT PATCH v2 2/4] lib/ukswrand: Add seed generating function

This patch adds a new function, _get_random_seed32 for seed generaton. If the
pre-compiled config option is not selected, then rdrand is used on x86 and
ukplat_wall_clock on ARM.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 lib/ukswrand/Config.uk           |  7 +++++++
 lib/ukswrand/include/uk/swrand.h | 20 ++++++++++++++++++++
 lib/ukswrand/mwc.c               |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/ukswrand/Config.uk b/lib/ukswrand/Config.uk
index c58371bb..8db3af03 100644
--- a/lib/ukswrand/Config.uk
+++ b/lib/ukswrand/Config.uk
@@ -14,10 +14,17 @@ config LIBUKSWRAND_MWC
                Use multiply-with-carry algorithm
 endchoice
 
+config LIBUKSWRAND_USE_INITIALSEED
+       bool "Use a pre-compiled seed"
+       default y
+
+if LIBUKSWRAND_USE_INITIALSEED
 config LIBUKSWRAND_INITIALSEED
        int "Initial random seed"
        default 23
 
+endif
+
 config LIBUKSWRAND_DEVFS
        bool "Register random and urandom device to devfs"
        select LIBDEVFS
diff --git a/lib/ukswrand/include/uk/swrand.h b/lib/ukswrand/include/uk/swrand.h
index 77912182..a3a1e227 100644
--- a/lib/ukswrand/include/uk/swrand.h
+++ b/lib/ukswrand/include/uk/swrand.h
@@ -39,6 +39,7 @@
 #include <uk/arch/types.h>
 #include <uk/plat/lcpu.h>
 #include <uk/config.h>
+#include <uk/plat/time.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -53,6 +54,25 @@ extern struct uk_swrand uk_swrand_def;
 void uk_swrand_init_r(struct uk_swrand *r, __u32 seed);
 __u32 uk_swrand_randr_r(struct uk_swrand *r);
 
+static inline __u32 _get_random_seed32(void)
+{
+       __u32 val;
+
+#ifdef CONFIG_LIBUKSWRAND_USE_INITIALSEED
+       return CONFIG_LIBUKSWRAND_INITIALSEED;
+#endif
+
+#ifdef CONFIG_ARCH_X86_64
+       asm volatile ("rdrand %%eax;"
+               : "=a" (val));
+       return val;
+#endif
+
+       /* TODO: Generate the seed randomly on ARM */
+       val = (__u32)ukplat_wall_clock();
+       return val;
+}
+
 /* Uses the pre-initialized default generator  */
 /* TODO: Add assertion when we can test if we are in interrupt context */
 /* TODO: Revisit with multi-CPU support */
diff --git a/lib/ukswrand/mwc.c b/lib/ukswrand/mwc.c
index 820aa2a2..6d785c07 100644
--- a/lib/ukswrand/mwc.c
+++ b/lib/ukswrand/mwc.c
@@ -99,7 +99,7 @@ __u32 uk_swrand_randr_r(struct uk_swrand *r)
 static void _uk_swrand_ctor(void)
 {
        uk_pr_info("Initialize random number generator...\n");
-       uk_swrand_init_r(&uk_swrand_def, CONFIG_LIBUKSWRAND_INITIALSEED);
+       uk_swrand_init_r(&uk_swrand_def, _get_random_seed32());
 }
 
 UK_CTOR_FUNC(UK_SWRAND_CTOR_PRIO, _uk_swrand_ctor);
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.