Update jitterentropy to version 3.4.1

Fixes #5112
This commit is contained in:
Christian Helmuth 2024-02-08 08:14:57 +01:00
parent fb2e0b50c8
commit a529fffb7b
22 changed files with 192 additions and 144 deletions

View File

@ -20,5 +20,3 @@ endif
INC_DIR += $(call select_from_repositories,src/lib/jitterentropy)
INC_DIR += $(call select_from_repositories,src/lib/jitterentropy/spec/$(TARGET_CPUARCH))
CC_OPT += -DJITTERENTROPY_GENODE

View File

@ -3,12 +3,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
SRC_C += jitterentropy-base.c
SRC_C += jitterentropy-gcd.c
SRC_C += jitterentropy-health.c
SRC_C += jitterentropy-noise.c
SRC_C += jitterentropy-sha3.c
SRC_CC += jitterentropy-base-genode.cc
override CC_OLEVEL := -O0
vpath %.c $(JENT_CONTRIB_DIR)/src/lib/jitterentropy
vpath %.c $(JENT_CONTRIB_DIR)/src/lib/jitterentropy/src
vpath %.cc $(REP_DIR)/src/lib/jitterentropy

View File

@ -1,5 +1,3 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/spec/arm_v6
include $(REP_DIR)/lib/mk/jitterentropy.inc
CC_CXX_WARN_STRICT =

View File

@ -1,5 +1,3 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/spec/arm_v7
include $(REP_DIR)/lib/mk/jitterentropy.inc
CC_CXX_WARN_STRICT =

View File

@ -1,5 +1,3 @@
INC_DIR += $(REP_DIR)/src/lib/jitterentropy/spec/arm_v8
include $(REP_DIR)/lib/mk/jitterentropy.inc
CC_CXX_WARN_STRICT =

View File

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

View File

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

View File

@ -1 +1 @@
5a9912059b31cef732fde73b1933e9bf0ed15adc
6bed43a43605b0006c7298cf4824a8214f36bb07

View File

@ -1,28 +1,13 @@
LICENSE := BSD
VERSION := 1.2.0
VERSION := 3.4.1
DOWNLOADS := jitterentropy.archive
URL(jitterentropy) := http://www.chronox.de/jent/releases/historic/jitterentropy-$(VERSION).tar.xz
SHA(jitterentropy) := c2cadcc413b9f5f40b6cc0e092933a32585f7db8f28269af2bee794fde8034b2
SIG(jitterentropy) := ${URL(jitterentropy)}.asc
KEY(jitterentropy) := 5F0D446594D2BF6977A9828AF02C639D843B5F11
DIR(jitterentropy) := src/lib/jitterentropy
NAME(jitterentropy) := jitterentropy-$(VERSION).tar.gz
URL(jitterentropy) := https://github.com/smuellerDD/jitterentropy-library/archive/refs/tags/v$(VERSION).tar.gz
SHA(jitterentropy) := 33352369092b5a0d1463c720f5a8a3e870dbd63502ea57692e7da84a65c0c5c3
DIR(jitterentropy) := src/lib/jitterentropy
PATCHES := src/lib/jitterentropy/jitterentropy.patch
DIRS := include/jitterentropy
DIR_CONTENT(include/jitterentropy) := $(addprefix src/lib/jitterentropy/,\
jitterentropy.h)
PATCHES := src/lib/jitterentropy/jitterentropy_h.patch \
src/lib/jitterentropy/jitterentropy_delta_compare.patch \
src/lib/jitterentropy/jitterentropy_memcpy.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
DIR_CONTENT(include/jitterentropy) := $(addprefix src/lib/jitterentropy/,jitterentropy.h)

View File

@ -5,7 +5,7 @@ MIRROR_FROM_REP_DIR := lib/mk/jitterentropy.inc \
src/lib/jitterentropy
PORT_DIR := $(call port_dir,$(REP_DIR)/ports/jitterentropy)
MIRROR_FROM_PORT_DIR := src/lib/jitterentropy/jitterentropy-base.c \
MIRROR_FROM_PORT_DIR := src/lib/jitterentropy/src \
include/jitterentropy/jitterentropy.h
content: $(MIRROR_FROM_REP_DIR) $(MIRROR_FROM_PORT_DIR) LICENSE

View File

@ -15,8 +15,7 @@
#include <base/allocator.h>
#include <util/string.h>
/* local includes */
#include <jitterentropy-base-genode.h>
#include <jitterentropy.h>
static Genode::Allocator *_alloc;
@ -40,7 +39,7 @@ void *jent_zalloc(size_t len)
}
void jent_zfree(void *ptr, unsigned int len)
void jent_zfree(void *ptr, unsigned int)
{
if (!_alloc) { return; }
_alloc->free(ptr, 0);
@ -51,3 +50,9 @@ void *jent_memcpy(void *dest, const void *src, size_t n)
{
return Genode::memcpy(dest, src, n);
}
void *jent_memset(void *dest, int c, size_t n)
{
return Genode::memset(dest, (uint8_t)c, n);
}

View File

@ -1,11 +1,15 @@
/*
* \brief Genode base for jitterentropy
* \author Josef Soentgen
* \author Christian Helmuth
* \date 2014-08-18
*
* Required to be included outside of extern "C" {...} at top of
* jitterentropy.h.
*/
/*
* Copyright (C) 2014-2017 Genode Labs GmbH
* Copyright (C) 2014-2024 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
@ -14,21 +18,6 @@
#ifndef _JITTERENTROPY_BASE_GENODE_H_
#define _JITTERENTROPY_BASE_GENODE_H_
/* needed type definitions */
#include <base/fixed_stdint.h>
typedef unsigned long size_t;
typedef signed long ssize_t;
typedef genode_uint32_t uint32_t;
typedef genode_uint64_t uint64_t;
typedef uint32_t __u32;
typedef uint64_t __u64;
typedef genode_int64_t __s64;
#ifndef __cplusplus
#define NULL (void*)0
#endif
#ifdef __cplusplus
#include <base/allocator.h>
@ -36,25 +25,6 @@ typedef genode_int64_t __s64;
/* Genode specific function to set the backend allocator */
void jitterentropy_init(Genode::Allocator &alloc);
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 *jent_memcpy(void *dest, const void *src, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* _JITTERENTROPY_BASE_GENODE_H_ */

View File

@ -0,0 +1,74 @@
/*
* \brief Genode base for jitterentropy
* \author Josef Soentgen
* \author Christian Helmuth
* \date 2014-08-18
*/
/*
* Copyright (C) 2014-2024 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _JITTERENTROPY_BASE_USER_H_
#define _JITTERENTROPY_BASE_USER_H_
/* needed type definitions */
#include <base/fixed_stdint.h>
typedef unsigned long size_t;
typedef signed long ssize_t;
typedef genode_uint8_t uint8_t;
typedef genode_uint32_t uint32_t;
typedef genode_uint64_t uint64_t;
typedef uint32_t __u32;
typedef uint64_t __u64;
typedef genode_int64_t __s64;
/* use gcc standard defines */
#define UINT32_MAX __UINT32_MAX__
#define UINT32_C __UINT32_C
#define UINT64_C __UINT64_C
#ifndef __cplusplus
#define NULL (void*)0
#define EAGAIN 35 /* jitterentropy-health.c */
#define EOPNOTSUPP 45 /* jitterentropy-timer.h */
#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 uint32_t jent_cache_size_roundup(void) { return 0; }
static inline __u64 rol64(__u64 word, unsigned int shift)
{
return (word << shift) | (word >> (64 - shift));
}
void *jent_memcpy(void *dest, void const *src, size_t n);
void *jent_memset(void *dest, int c, size_t n);
static inline void jent_memset_secure(void *s, size_t n)
{
jent_memset(s, 0, n);
asm volatile ("" : : "r" (s) : "memory");
}
#ifdef __cplusplus
}
#endif
#endif /* _JITTERENTROPY_BASE_USER_H_ */

View File

@ -0,0 +1,81 @@
diff -ur -x '*~' -x recording_userspace src.orig/lib/jitterentropy/jitterentropy.h src/lib/jitterentropy/jitterentropy.h
--- src.orig/lib/jitterentropy/jitterentropy.h
+++ src/lib/jitterentropy/jitterentropy.h
@@ -42,6 +42,8 @@
#ifndef _JITTERENTROPY_H
#define _JITTERENTROPY_H
+#include "jitterentropy-base-genode.h"
+
#ifdef __cplusplus
extern "C" {
#endif
diff -ur -x '*~' -x recording_userspace src.orig/lib/jitterentropy/src/jitterentropy-noise.c src/lib/jitterentropy/src/jitterentropy-noise.c
--- src.orig/lib/jitterentropy/src/jitterentropy-noise.c
+++ src/lib/jitterentropy/src/jitterentropy-noise.c
@@ -112,7 +112,7 @@
jent_loop_shuffle(ec, MAX_HASH_LOOP, MIN_HASH_LOOP);
/* Use the memset to shut up valgrind */
- memset(intermediary, 0, sizeof(intermediary));
+ jent_memset(intermediary, 0, sizeof(intermediary));
sha3_256_init(&ctx);
@@ -413,7 +413,7 @@
/* The final operation automatically re-initializes the ->hash_state */
sha3_final(ec->hash_state, jent_block);
if (dst_len)
- memcpy(dst, jent_block, dst_len);
+ jent_memcpy(dst, jent_block, dst_len);
/*
* Stir the new state with the data from the old state - the digest
diff -ur -x '*~' -x recording_userspace src.orig/lib/jitterentropy/src/jitterentropy-sha3.c src/lib/jitterentropy/src/jitterentropy-sha3.c
--- src.orig/lib/jitterentropy/src/jitterentropy-sha3.c
+++ src/lib/jitterentropy/src/jitterentropy-sha3.c
@@ -295,7 +295,7 @@
* buffer, copy it and leave it unprocessed.
*/
if (inlen < todo) {
- memcpy(ctx->partial + partial, in, inlen);
+ jent_memcpy(ctx->partial + partial, in, inlen);
return;
}
@@ -303,7 +303,7 @@
* The input data is large enough to fill the entire partial
* block buffer. Thus, we fill it and transform it.
*/
- memcpy(ctx->partial + partial, in, todo);
+ jent_memcpy(ctx->partial + partial, in, todo);
inlen -= todo;
in += todo;
@@ -318,7 +318,7 @@
}
/* If we have data left, copy it into the partial block buffer */
- memcpy(ctx->partial, in, inlen);
+ jent_memcpy(ctx->partial, in, inlen);
}
void sha3_final(struct sha_ctx *ctx, uint8_t *digest)
@@ -329,7 +329,7 @@
/* Final round in sponge absorbing phase */
/* Fill the unused part of the partial buffer with zeros */
- memset(ctx->partial + partial, 0, ctx->r - partial);
+ jent_memset(ctx->partial + partial, 0, ctx->r - partial);
/*
* Add the leading and trailing bit as well as the 01 bits for the
@@ -353,7 +353,7 @@
if (ctx->digestsize % 8)
le32_to_ptr(digest, (uint32_t)(ctx->state[i]));
- memset(ctx->partial, 0, ctx->r);
+ jent_memset(ctx->partial, 0, ctx->r);
sha3_init(ctx);
}

View File

@ -1,13 +0,0 @@
diff --git a/jitterentropy-base.c b/jitterentropy-base.c
index c71e1e7..28b1462 100644
--- a/jitterentropy-base.c
+++ b/jitterentropy-base.c
@@ -754,7 +754,7 @@ int jent_entropy_init(void)
* than 1 to ensure the entropy estimation
* implied with 1 is preserved
*/
- if (!(delta_sum) > 1)
+ if (!(delta_sum > 1))
return EMINVARVAR;
/*

View File

@ -1,31 +0,0 @@
--- a/jitterentropy.h.orig
+++ b/jitterentropy.h
@@ -42,11 +42,19 @@
#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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/* Statistical data from the entropy source */
struct entropy_stat {
@@ -171,4 +179,8 @@
/* -- END of statistical test function -- */
+#ifdef __cplusplus
+}
+#endif /* extern "C" */
+
#endif /* _JITTERENTROPY_H */

View File

@ -1,13 +0,0 @@
diff --git a/jitterentropy-base.c b/jitterentropy-base.c
index 28b1462..3ea4c90 100644
--- a/jitterentropy-base.c
+++ b/jitterentropy-base.c
@@ -553,7 +553,7 @@ ssize_t jent_read_entropy(struct rand_data *ec, char *data, size_t len)
tocopy = (DATA_SIZE_BITS / 8);
else
tocopy = len;
- memcpy(p, &ec->data, tocopy);
+ jent_memcpy(p, &ec->data, tocopy);
len -= tocopy;
p += tocopy;

View File

@ -17,7 +17,7 @@
static inline void jent_get_nstime(__u64 *out)
{
uint32_t t;
asm volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(t));
asm volatile ("mrc p15, 0, %0, c15, c12, 1" : "=r"(t));
*out = t;
}

View File

@ -17,7 +17,7 @@
static inline void jent_get_nstime(__u64 *out)
{
uint32_t t;
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(t));
asm volatile ("mrc p15, 0, %0, c9, c13, 0" : "=r"(t));
*out = t;
}

View File

@ -18,7 +18,7 @@ static inline void jent_get_nstime(__u64 *out)
{
uint64_t t;
/* cycle counter */
asm volatile("mrs %0, pmccntr_el0" : "=r" (t));
asm volatile ("mrs %0, pmccntr_el0" : "=r" (t));
*out = t;
}

View File

@ -16,9 +16,9 @@
static inline void jent_get_nstime(__u64 *out)
{
uint64_t t;
__asm__ __volatile__ ( "rdtsc" : "=A" (t));
*out = t;
uint64_t t;
asm volatile ( "rdtsc" : "=A" (t));
*out = t;
}
#endif /* _JITTERENTROPY_X86_32_BASE_GENODE_NSTIME_H */

View File

@ -17,7 +17,7 @@
static inline void jent_get_nstime(__u64 *out)
{
uint32_t lo, hi;
__asm__ __volatile__ ( "rdtsc" : "=a" (lo), "=d" (hi));
asm volatile ( "rdtsc" : "=a" (lo), "=d" (hi));
*out = (uint64_t)hi << 32 | lo;
}