From 28c7e7f6fabe8b921bcf2f8fc044e126236da38e Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 15 Dec 2011 19:49:30 +0000 Subject: [PATCH] - Added HAVEGE as a default entropy source --- include/polarssl/entropy.h | 8 ++++++++ library/entropy.c | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/polarssl/entropy.h b/include/polarssl/entropy.h index aeec8b25d..6dea79a71 100644 --- a/include/polarssl/entropy.h +++ b/include/polarssl/entropy.h @@ -29,7 +29,12 @@ #include +#include "config.h" + #include "sha4.h" +#if defined(POLARSSL_HAVEGE_C) +#include "havege.h" +#endif #define POLARSSL_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */ #define POLARSSL_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */ @@ -77,6 +82,9 @@ typedef struct sha4_context accumulator; int source_count; source_state source[ENTROPY_MAX_SOURCES]; +#if defined(POLARSSL_HAVEGE_C) + havege_state havege_data; +#endif } entropy_context; diff --git a/library/entropy.c b/library/entropy.c index bc0e141b2..ebace0881 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -30,6 +30,10 @@ #include "polarssl/entropy.h" #include "polarssl/entropy_poll.h" +#if defined(POLARSSL_HAVEGE_C) +#include "polarssl/havege.h" +#endif + #define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */ void entropy_init( entropy_context *ctx ) @@ -45,6 +49,11 @@ void entropy_init( entropy_context *ctx ) #if defined(POLARSSL_TIMING_C) entropy_add_source( ctx, hardclock_poll, NULL, ENTROPY_MIN_HARDCLOCK ); #endif +#if defined(POLARSSL_HAVEGE_C) + havege_init( &ctx->havege_data ); + entropy_add_source( ctx, havege_poll, &ctx->havege_data, + ENTROPY_MIN_HAVEGE ); +#endif } int entropy_add_source( entropy_context *ctx,