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.
This commit is contained in:
Josef Söntgen 2014-08-18 15:28:46 +02:00 committed by Norman Feske
parent 2bf67136c6
commit 2f46930824
16 changed files with 277 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/arm_v6
SPECS += perf_counter
include $(REP_DIR)/lib/mk/jitterentropy.inc

View File

@ -0,0 +1,5 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/arm_v7
SPECS += perf_counter
include $(REP_DIR)/lib/mk/jitterentropy.inc

View File

@ -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

View File

@ -0,0 +1,3 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/x86_32
include $(REP_DIR)/lib/mk/jitterentropy.inc

View File

@ -0,0 +1,3 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/x86_64
include $(REP_DIR)/lib/mk/jitterentropy.inc

View File

@ -0,0 +1 @@
7dbc3c0143b0312290895d91ccfa97e6a6e2ae3f

View File

@ -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

View File

@ -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 */

View File

@ -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 */

View File

@ -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 <base/env.h>
/* local includes */
#include <jitterentropy-base-genode.h>
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);
}

View File

@ -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 <base/fixed_stdint.h>
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 <jitterentropy-base-genode-nstime.h>
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_ */

View File

@ -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 <jitterentropy-base-genode.h>
+#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 {

View File

@ -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 */

View File

@ -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 */

View File

@ -0,0 +1,5 @@
TARGET = test-jitterentropy
LIBS = libc jitterentropy
SRC_CC = main.cc
vpath main.cc $(PRG_DIR)/..