From 2f46930824a451d251e301d03e71983457c1d4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 18 Aug 2014 15:28:46 +0200 Subject: [PATCH] libports: add jitterentropy-20140411 This commit adds a port the jitterentropy library to Genode. As backend on x86_{32,64} 'rdtsc' is used and on ARMv{6,7} the performance-counter. Fixes #1239. --- .../lib/import/import-jitterentropy.mk | 15 ++++++ repos/libports/lib/mk/arm_v6/jitterentropy.mk | 5 ++ repos/libports/lib/mk/arm_v7/jitterentropy.mk | 5 ++ repos/libports/lib/mk/jitterentropy.inc | 14 +++++ repos/libports/lib/mk/x86_32/jitterentropy.mk | 3 ++ repos/libports/lib/mk/x86_64/jitterentropy.mk | 3 ++ repos/libports/ports/jitterentropy.hash | 1 + repos/libports/ports/jitterentropy.port | 24 +++++++++ .../arm_v6/jitterentropy-base-genode-nstime.h | 24 +++++++++ .../arm_v7/jitterentropy-base-genode-nstime.h | 24 +++++++++ .../jitterentropy-base-genode.cc | 36 +++++++++++++ .../jitterentropy/jitterentropy-base-genode.h | 52 +++++++++++++++++++ .../lib/jitterentropy/jitterentropy_h.patch | 18 +++++++ .../x86_32/jitterentropy-base-genode-nstime.h | 24 +++++++++ .../x86_64/jitterentropy-base-genode-nstime.h | 24 +++++++++ .../src/test/libports/jitterentropy/target.mk | 5 ++ 16 files changed, 277 insertions(+) create mode 100644 repos/libports/lib/import/import-jitterentropy.mk create mode 100644 repos/libports/lib/mk/arm_v6/jitterentropy.mk create mode 100644 repos/libports/lib/mk/arm_v7/jitterentropy.mk create mode 100644 repos/libports/lib/mk/jitterentropy.inc create mode 100644 repos/libports/lib/mk/x86_32/jitterentropy.mk create mode 100644 repos/libports/lib/mk/x86_64/jitterentropy.mk create mode 100644 repos/libports/ports/jitterentropy.hash create mode 100644 repos/libports/ports/jitterentropy.port create mode 100644 repos/libports/src/lib/jitterentropy/arm_v6/jitterentropy-base-genode-nstime.h create mode 100644 repos/libports/src/lib/jitterentropy/arm_v7/jitterentropy-base-genode-nstime.h create mode 100644 repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc create mode 100644 repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h create mode 100644 repos/libports/src/lib/jitterentropy/jitterentropy_h.patch create mode 100644 repos/libports/src/lib/jitterentropy/x86_32/jitterentropy-base-genode-nstime.h create mode 100644 repos/libports/src/lib/jitterentropy/x86_64/jitterentropy-base-genode-nstime.h create mode 100644 repos/libports/src/test/libports/jitterentropy/target.mk diff --git a/repos/libports/lib/import/import-jitterentropy.mk b/repos/libports/lib/import/import-jitterentropy.mk new file mode 100644 index 0000000000..ec214073aa --- /dev/null +++ b/repos/libports/lib/import/import-jitterentropy.mk @@ -0,0 +1,15 @@ +ifeq ($(filter-out $(SPECS),x86_32),) + TARGET_CPUARCH=x86_32 +else ifeq ($(filter-out $(SPECS),x86_64),) + TARGET_CPUARCH=x86_64 +else ifeq ($(filter-out $(SPECS),arm_v6),) + TARGET_CPUARCH=arm_v6 +else ifeq ($(filter-out $(SPECS),arm_v7),) + TARGET_CPUARCH=arm_v7 +endif + +INC_DIR += $(call select_from_ports,jitterentropy)/include/jitterentropy +INC_DIR += $(REP_DIR)/src/lib/jitterentropy \ + $(REP_DIR)/src/lib/jitterentropy/$(TARGET_CPUARCH) + +CC_OPT += -DJITTERENTROPY_GENODE diff --git a/repos/libports/lib/mk/arm_v6/jitterentropy.mk b/repos/libports/lib/mk/arm_v6/jitterentropy.mk new file mode 100644 index 0000000000..edfe702a0c --- /dev/null +++ b/repos/libports/lib/mk/arm_v6/jitterentropy.mk @@ -0,0 +1,5 @@ +INC_DIR += $(REP_DIR)/src/lib/jitterentropy/arm_v6 + +SPECS += perf_counter + +include $(REP_DIR)/lib/mk/jitterentropy.inc diff --git a/repos/libports/lib/mk/arm_v7/jitterentropy.mk b/repos/libports/lib/mk/arm_v7/jitterentropy.mk new file mode 100644 index 0000000000..fde8675734 --- /dev/null +++ b/repos/libports/lib/mk/arm_v7/jitterentropy.mk @@ -0,0 +1,5 @@ +INC_DIR += $(REP_DIR)/src/lib/jitterentropy/arm_v7 + +SPECS += perf_counter + +include $(REP_DIR)/lib/mk/jitterentropy.inc diff --git a/repos/libports/lib/mk/jitterentropy.inc b/repos/libports/lib/mk/jitterentropy.inc new file mode 100644 index 0000000000..f2efd4ead3 --- /dev/null +++ b/repos/libports/lib/mk/jitterentropy.inc @@ -0,0 +1,14 @@ +JENT_CONTRIB_DIR := $(call select_from_ports,jitterentropy) + +INC_DIR += $(JENT_CONTRIB_DIR)/include/jitterentropy \ + $(REP_DIR)/src/lib/jitterentropy + +SRC_C = jitterentropy-base.c +SRC_CC = jitterentropy-base-genode.cc + +CC_OPT += -DJITTERENTROPY_GENODE + +CC_OLEVEL := -O0 + +vpath %.c $(JENT_CONTRIB_DIR)/src/lib/jitterentropy +vpath %.cc $(REP_DIR)/src/lib/jitterentropy diff --git a/repos/libports/lib/mk/x86_32/jitterentropy.mk b/repos/libports/lib/mk/x86_32/jitterentropy.mk new file mode 100644 index 0000000000..69444a005b --- /dev/null +++ b/repos/libports/lib/mk/x86_32/jitterentropy.mk @@ -0,0 +1,3 @@ +INC_DIR += $(REP_DIR)/src/lib/jitterentropy/x86_32 + +include $(REP_DIR)/lib/mk/jitterentropy.inc diff --git a/repos/libports/lib/mk/x86_64/jitterentropy.mk b/repos/libports/lib/mk/x86_64/jitterentropy.mk new file mode 100644 index 0000000000..02c9d88aa7 --- /dev/null +++ b/repos/libports/lib/mk/x86_64/jitterentropy.mk @@ -0,0 +1,3 @@ +INC_DIR += $(REP_DIR)/src/lib/jitterentropy/x86_64 + +include $(REP_DIR)/lib/mk/jitterentropy.inc diff --git a/repos/libports/ports/jitterentropy.hash b/repos/libports/ports/jitterentropy.hash new file mode 100644 index 0000000000..a92744f43f --- /dev/null +++ b/repos/libports/ports/jitterentropy.hash @@ -0,0 +1 @@ +7dbc3c0143b0312290895d91ccfa97e6a6e2ae3f diff --git a/repos/libports/ports/jitterentropy.port b/repos/libports/ports/jitterentropy.port new file mode 100644 index 0000000000..19480903cb --- /dev/null +++ b/repos/libports/ports/jitterentropy.port @@ -0,0 +1,24 @@ +LICENSE := BSD +VERSION := 20140411 +DOWNLOADS := jitterentropy.archive + +URL(jitterentropy) := http://www.chronox.de/jent/jitterentropy-$(VERSION).tar.bz2 +SHA(jitterentropy) := a072ed4788b9de49bef5d339d61eaa8e88547cb3 +DIR(jitterentropy) := src/lib/jitterentropy + +DIRS := include/jitterentropy +DIR_CONTENT(include/jitterentropy) := $(addprefix src/lib/jitterentropy/,\ + jitterentropy.h) + +PATCHES := src/lib/jitterentropy/jitterentropy_h.patch +PATCH_OPT := -p1 -d src/lib/jitterentropy + +# +# Just to make sure that the compiler will use the right header files +# we delete the local copy from the source directory after the files +# were copied to the include directory. +# +default: rm_header +rm_header: _dirs + @$(MSG_PREFIX)"remove header files from source directory " + $(VERBOSE)rm src/lib/jitterentropy/jitterentropy.h diff --git a/repos/libports/src/lib/jitterentropy/arm_v6/jitterentropy-base-genode-nstime.h b/repos/libports/src/lib/jitterentropy/arm_v6/jitterentropy-base-genode-nstime.h new file mode 100644 index 0000000000..840cb25e09 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/arm_v6/jitterentropy-base-genode-nstime.h @@ -0,0 +1,24 @@ +/* + * \brief Time backend for jitterentropy library + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _JITTERENTROPY_ARM_V6_BASE_GENODE_NSTIME_H_ +#define _JITTERENTROPY_ARM_V6_BASE_GENODE_NSTIME_H_ + +static inline void jent_get_nstime(__u64 *out) +{ + uint32_t t; + asm volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(t)); + *out = t; +} + +#endif /* _JITTERENTROPY_ARM_V6_BASE_GENODE_NSTIME_H */ diff --git a/repos/libports/src/lib/jitterentropy/arm_v7/jitterentropy-base-genode-nstime.h b/repos/libports/src/lib/jitterentropy/arm_v7/jitterentropy-base-genode-nstime.h new file mode 100644 index 0000000000..c5972ef1d2 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/arm_v7/jitterentropy-base-genode-nstime.h @@ -0,0 +1,24 @@ +/* + * \brief Time backend for jitterentropy library + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _JITTERENTROPY_ARM_V7_BASE_GENODE_NSTIME_H_ +#define _JITTERENTROPY_ARM_V7_BASE_GENODE_NSTIME_H_ + +static inline void jent_get_nstime(__u64 *out) +{ + uint32_t t; + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(t)); + *out = t; +} + +#endif /* _JITTERENTROPY_ARM_V7_BASE_GENODE_NSTIME_H */ diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc new file mode 100644 index 0000000000..9c1300c5c8 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc @@ -0,0 +1,36 @@ +/* + * \brief Genode base for jitterentropy + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include + +/* local includes */ +#include + + +void *jent_zalloc(size_t len) +{ + return Genode::env()->heap()->alloc(len); +} + + +void jent_zfree(void *ptr, unsigned int len) +{ + Genode::env()->heap()->free(ptr, len); +} + + +void *memcpy(void *dest, const void *src, size_t n) +{ + return Genode::memcpy(dest, src, n); +} diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h new file mode 100644 index 0000000000..449541440a --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h @@ -0,0 +1,52 @@ +/* + * \brief Genode base for jitterentropy + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _JITTERENTROPY_BASE_GENODE_H_ +#define _JITTERENTROPY_BASE_GENODE_H_ + +/* needed type definitions */ +#include + +typedef __SIZE_TYPE__ size_t; +typedef genode_uint32_t uint32_t; +typedef genode_uint64_t uint64_t; +typedef uint32_t __u32; +typedef uint64_t __u64; + +#ifndef __cplusplus +#define NULL (void*)0 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void *jent_zalloc(size_t len); +void jent_zfree(void *ptr, unsigned int len); + +static inline int jent_fips_enabled(void) { return 0; } + +static inline __u64 rol64(__u64 word, unsigned int shift) +{ + return (word << shift) | (word >> (64 - shift)); +} + +void *memcpy(void *dest, const void *src, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _JITTERENTROPY_BASE_GENODE_H_ */ diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch b/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch new file mode 100644 index 0000000000..1d97dabe89 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch @@ -0,0 +1,18 @@ +--- a/jitterentropy.h 2014-04-07 21:07:13.000000000 +0200 ++++ b/jitterentropy.h 2014-08-18 14:42:32.609235231 +0200 +@@ -42,11 +42,15 @@ + #ifndef _JITTERENTROPY_H + #define _JITTERENTROPY_H + ++#ifdef JITTERENTROPY_GENODE ++#include ++#else + #ifdef __KERNEL__ + #include "jitterentropy-base-kernel.h" + #else + #include "jitterentropy-base-user.h" + #endif /* __KERNEL__ */ ++#endif + + /* Statistical data from the entropy source */ + struct entropy_stat { diff --git a/repos/libports/src/lib/jitterentropy/x86_32/jitterentropy-base-genode-nstime.h b/repos/libports/src/lib/jitterentropy/x86_32/jitterentropy-base-genode-nstime.h new file mode 100644 index 0000000000..c6291b7aa2 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/x86_32/jitterentropy-base-genode-nstime.h @@ -0,0 +1,24 @@ +/* + * \brief Time backend for jitterentropy library + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _JITTERENTROPY_X86_32_BASE_GENODE_NSTIME_H_ +#define _JITTERENTROPY_X86_32_BASE_GENODE_NSTIME_H_ + +static inline void jent_get_nstime(__u64 *out) +{ + uint64_t t; + __asm__ __volatile__ ( "rdtsc" : "=A" (t)); + *out = t; +} + +#endif /* _JITTERENTROPY_X86_32_BASE_GENODE_NSTIME_H */ diff --git a/repos/libports/src/lib/jitterentropy/x86_64/jitterentropy-base-genode-nstime.h b/repos/libports/src/lib/jitterentropy/x86_64/jitterentropy-base-genode-nstime.h new file mode 100644 index 0000000000..5c5912cf14 --- /dev/null +++ b/repos/libports/src/lib/jitterentropy/x86_64/jitterentropy-base-genode-nstime.h @@ -0,0 +1,24 @@ +/* + * \brief Time backend for jitterentropy library + * \author Josef Soentgen + * \date 2014-08-18 + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _JITTERENTROPY_X86_64_BASE_GENODE_NSTIME_H_ +#define _JITTERENTROPY_X86_64_BASE_GENODE_NSTIME_H_ + +static inline void jent_get_nstime(__u64 *out) +{ + uint32_t lo, hi; + __asm__ __volatile__ ( "rdtsc" : "=a" (lo), "=d" (hi)); + *out = (uint64_t)hi << 32 | lo; +} + +#endif /* _JITTERENTROPY_X86_64_BASE_GENODE_NSTIME_H */ diff --git a/repos/libports/src/test/libports/jitterentropy/target.mk b/repos/libports/src/test/libports/jitterentropy/target.mk new file mode 100644 index 0000000000..d9e97fb655 --- /dev/null +++ b/repos/libports/src/test/libports/jitterentropy/target.mk @@ -0,0 +1,5 @@ +TARGET = test-jitterentropy +LIBS = libc jitterentropy +SRC_CC = main.cc + +vpath main.cc $(PRG_DIR)/..