Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New functionality that supports a more straight-forward and technically justifiable entropy bound argument #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CC ?= gcc
#Hardening
ENABLE_STACK_PROTECTOR ?= 1
CFLAGS ?= -fwrapv --param ssp-buffer-size=4 -fvisibility=hidden -fPIE -Wcast-align -Wmissing-field-initializers -Wshadow -Wswitch-enum
CFLAGS +=-Wextra -Wall -pedantic -fPIC -O0 -fwrapv -Wconversion
CFLAGS +=-Wextra -Wall -pedantic -fPIC -O0 -fwrapv -Wconversion -Wno-type-limits
LDFLAGS +=-Wl,-z,relro,-z,now -lpthread

# Enable internal timer support
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ Direct CPU instructions
If the function in jent_get_nstime is not available, you can replace the
jitterentropy-base-user.h with examples from the arch/ directory.

Testing
=======

There are numerous tests around the Jitter RNG. Yet, they are too big to be
loaded into the official repository. Email me, if you want them.

Version Numbers
===============
The version numbers for this library have the following schema:
Expand Down
11 changes: 0 additions & 11 deletions doc/jitterentropy.3
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@ The
.IR flags
value is either zero or one or more of the following flags.
.TP
.B JENT_DISABLE_MEMORY_ACCESS
If the system is constrained with memory, this flag
disables the allocation of that memory and therefore memory accesses. But
that also implies that the entropy collection process only relies on the
complexity of the CPU. Note, if somebody knows all details of that CPU
complexity, that person may potentially reduce the entropy delivered by the CPU
complexity. If that person can push the generated entropy below a threshold,
the CPU Jitter random number generator starts overestimating entropy from the
noise source. Thus, disabling memory accesses and relying only on the CPU
complexity should only be done if you really know what you are doing.
.TP
.B JENT_FORCE_INTERNAL_TIMER
This flag can be used to force the Jitter RNG to use the internal
high-resolution timer instead of using the hardware time stamp. Commonly,
Expand Down
49 changes: 12 additions & 37 deletions jitterentropy-base-user.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,20 @@
#endif

#if (__x86_64__) || (__i386__)
/* Support rdtsc read on 64-bit and 32-bit x86 architectures */

#ifdef __x86_64__
/* specify 64 bit type since long is 32 bits in LLP64 x86_64 systems */
# define DECLARE_ARGS(val, low, high) uint64_t low, high
# define EAX_EDX_VAL(val, low, high) ((low) | (high) << 32)
# define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high)
#elif __i386__
# define DECLARE_ARGS(val, low, high) unsigned long val
# define EAX_EDX_VAL(val, low, high) val
# define EAX_EDX_RET(val, low, high) "=A" (val)
#endif
/* Support rdtsc read on 64-bit and 32-bit x86 architectures */
#include <x86intrin.h>

static inline void jent_get_nstime(uint64_t *out)
static inline void jent_get_nstime(volatile uint64_t *out)
{
DECLARE_ARGS(val, low, high);
asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
*out = EAX_EDX_VAL(val, low, high);
unsigned int dummy;
*out = __rdtscp(&dummy);
_mm_lfence();
}

#elif defined(__aarch64__)

static inline void jent_get_nstime(uint64_t *out)
static inline void jent_get_nstime(volatile uint64_t *out)
{
uint64_t ctr_val;
/*
Expand All @@ -127,7 +118,7 @@ static inline void jent_get_nstime(uint64_t *out)

#elif defined(__s390x__)

static inline void jent_get_nstime(uint64_t *out)
static inline void jent_get_nstime(volatile uint64_t *out)
{
uint64_t clk;

Expand All @@ -142,7 +133,7 @@ static inline void jent_get_nstime(uint64_t *out)

/* taken from http://www.ecrypt.eu.org/ebats/cpucycles.html */

static inline void jent_get_nstime(uint64_t *out)
static inline void jent_get_nstime(volatile uint64_t *out)
{
unsigned long high;
unsigned long low;
Expand All @@ -160,7 +151,7 @@ static inline void jent_get_nstime(uint64_t *out)

#else /* (__x86_64__) || (__i386__) || (__aarch64__) || (__s390x__) || (__powerpc) */

static inline void jent_get_nstime(uint64_t *out)
static inline void jent_get_nstime(volatile uint64_t *out)
{
/* OSX does not have clock_gettime -- taken from
* http://developer.apple.com/library/mac/qa/qa1398/_index.html */
Expand Down Expand Up @@ -379,7 +370,7 @@ static inline void jent_get_cachesize(long *l1, long *l2, long *l3)

# endif

static inline uint32_t jent_cache_size_roundup(void)
static inline uint32_t jent_cache_size(void)
{
static int checked = 0;
static uint32_t cache_size = 0;
Expand All @@ -398,32 +389,16 @@ static inline uint32_t jent_cache_size_roundup(void)
if (l3 > 0)
cache_size += (uint32_t)l3;

/*
* Force the output_size to be of the form
* (bounding_power_of_2 - 1).
*/
cache_size |= (cache_size >> 1);
cache_size |= (cache_size >> 2);
cache_size |= (cache_size >> 4);
cache_size |= (cache_size >> 8);
cache_size |= (cache_size >> 16);

if (cache_size == 0)
return 0;

/*
* Make the output_size the smallest power of 2 strictly
* greater than cache_size.
*/
cache_size++;
}

return cache_size;
}

#else /* __linux__ */

static inline uint32_t jent_cache_size_roundup(void)
static inline uint32_t jent_cache_size(void)
{
return 0;
}
Expand Down
Loading