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

[Minios-devel] [UNIKRAFT PATCH v5 1/4] lib/ukswrand: Adapt the library to work with multiple algorithms


  • To: "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Wed, 27 Nov 2019 12:41:48 +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=ZNVgtG/GH+OqKaULsimfjmCnguOMCVYUOYrCaajUOT0=; b=OhN6tbm0BrbeeX86QvzVWGXRcgQrNEeA1VOFGD2IVMa6SizmEy93PTn0K5vpqVkKLApxVZqh7FIdlgt7F2wrpEtRXNupzYDNsL0FueGrcdpOpz9t4YFyRQDzo/L6kB/uQJM1TyIdzEN8XWTfueuaR6tt/SCik2HBZMxe2dI3PVCoeQURxCv/6idsGJZOIsTYtUrPotFOK8oejIuOs27ndkCHcNdToqox4cW6rKJwxqkw5FRQ5mcujx08ZLpL3xHdjcBLYKN+KaZAaW3CVeVBt11UQRUHp9/JDeeKh0Mgj7HHemdwl9vcIQEeBBjRleH9TEe11MsadO4iFYh7IFiKJg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CPfNscY6dic9jsARgHEfnqmoWQWRY+nd7iMp90JviyC0t9I3ddQoMaOprRSD30HvBt1r+jMiYZ/vOn3F4dd98ojgoMa+4n0fr4/tUGy2JB4ilquNfCA9Rk2AiStwGF4EhJzdaFT+E27PJLVuoWQjvdqIMEDpLK5SmONmfGswFJ8BURStpMIiDTfyDNIi8FSSLWUfsxJ+KQT4Ppe6F2rJPIMi1S+qvXhDwdZQ/mQuwHLNs6Bta0V/dQprEEh4IRVjji5WM6xPU4TIEKMu6Ty0hKGYU/K8brQoDsYUjFFtXyzgsFraarckAL3T/ZTQT4xd9TaFF92YVhd8wJ6h/cHYZw==
  • 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, 27 Nov 2019 12:41:58 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVpSAIKlGkLhEde0O84XOdB6Xn2A==
  • Thread-topic: [UNIKRAFT PATCH v5 1/4] lib/ukswrand: Adapt the library to work with multiple algorithms

From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

We move the common function, uk_swrand_fill_buffer, to swrand.c and move
the common definitions to include/uk/swrand.h.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 lib/ukswrand/Makefile.uk         |  1 +
 lib/ukswrand/include/uk/swrand.h |  8 +---
 lib/ukswrand/mwc.c               | 41 +++-----------------
 lib/ukswrand/swrand.c            | 66 ++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 42 deletions(-)
 create mode 100644 lib/ukswrand/swrand.c

diff --git a/lib/ukswrand/Makefile.uk b/lib/ukswrand/Makefile.uk
index 6cf1223e..da85d381 100644
--- a/lib/ukswrand/Makefile.uk
+++ b/lib/ukswrand/Makefile.uk
@@ -5,4 +5,5 @@ CXXINCLUDES-$(CONFIG_LIBUKSWRAND) += 
-I$(LIBUKSWRAND_BASE)/include
 
 LIBUKSWRAND_SRCS-$(CONFIG_LIBUKSWRAND_MWC) += $(LIBUKSWRAND_BASE)/mwc.c
 LIBUKSWRAND_SRCS-$(CONFIG_LIBUKSWRAND_DEVFS) += $(LIBUKSWRAND_BASE)/dev.c
+LIBUKSWRAND_SRCS-y += $(LIBUKSWRAND_BASE)/swrand.c
 LIBUKSWRAND_SRCS-y += $(LIBUKSWRAND_BASE)/getrandom.c
diff --git a/lib/ukswrand/include/uk/swrand.h b/lib/ukswrand/include/uk/swrand.h
index 8523e207..35f3e2fe 100644
--- a/lib/ukswrand/include/uk/swrand.h
+++ b/lib/ukswrand/include/uk/swrand.h
@@ -44,13 +44,7 @@
 extern "C" {
 #endif
 
-struct uk_swrand {
-#ifdef CONFIG_LIBUKSWRAND_MWC
-        __u32 Q[4096];
-        __u32 c;
-        __u32 i;
-#endif
-};
+struct uk_swrand;
 
 extern struct uk_swrand uk_swrand_def;
 
diff --git a/lib/ukswrand/mwc.c b/lib/ukswrand/mwc.c
index 85abf0c6..8b4cca30 100644
--- a/lib/ukswrand/mwc.c
+++ b/lib/ukswrand/mwc.c
@@ -35,20 +35,18 @@
 
 #include <string.h>
 #include <uk/swrand.h>
-#include <uk/print.h>
 #include <uk/assert.h>
-#include <uk/ctors.h>
 
 /* 
https://stackoverflow.com/questions/9492581/c-random-number-generation-pure-c-code-no-libraries-or-functions
 */
 #define PHI 0x9e3779b9
-#define UK_SWRAND_CTOR_PRIO    1
 
-struct uk_swrand uk_swrand_def;
+struct uk_swrand {
+       __u32 Q[4096];
+       __u32 c;
+       __u32 i;
+};
 
-/*
- * Declare the constructor function to initialize the swrand
- */
-static void _uk_swrand_ctor(void);
+struct uk_swrand uk_swrand_def;
 
 void uk_swrand_init_r(struct uk_swrand *r, __u32 seed)
 {
@@ -91,30 +89,3 @@ __u32 uk_swrand_randr_r(struct uk_swrand *r)
        return (r->Q[i] = y - x);
 }
 
-ssize_t uk_swrand_fill_buffer(void *buf, size_t buflen)
-{
-       size_t step, chunk_size, i;
-       __u32 rd;
-
-       step = sizeof(__u32);
-       chunk_size = buflen % step;
-
-       for (i = 0; i < buflen - chunk_size; i += step)
-               *((char *) buf + i) = uk_swrand_randr();
-
-       /* fill the remaining bytes of the buffer */
-       if (chunk_size > 0) {
-               rd = uk_swrand_randr();
-               memcpy(buf + i, &rd, chunk_size);
-       }
-
-       return buflen;
-}
-
-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_CTOR_FUNC(UK_SWRAND_CTOR_PRIO, _uk_swrand_ctor);
diff --git a/lib/ukswrand/swrand.c b/lib/ukswrand/swrand.c
new file mode 100644
index 00000000..d9497bf8
--- /dev/null
+++ b/lib/ukswrand/swrand.c
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2019, University Politehnica of Bucharest. All rights 
reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <string.h>
+#include <uk/swrand.h>
+#include <uk/ctors.h>
+#include <uk/config.h>
+#include <uk/print.h>
+
+#define UK_SWRAND_CTOR_PRIO    1
+
+ssize_t uk_swrand_fill_buffer(void *buf, size_t buflen)
+{
+       size_t step, chunk_size, i;
+       __u32 rd;
+
+       step = sizeof(__u32);
+       chunk_size = buflen % step;
+
+       for (i = 0; i < buflen - chunk_size; i += step)
+               *((char *) buf + i) = uk_swrand_randr();
+
+       /* fill the remaining bytes of the buffer */
+       if (chunk_size > 0) {
+               rd = uk_swrand_randr();
+               memcpy(buf + i, &rd, chunk_size);
+       }
+
+       return buflen;
+}
+
+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_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®.