star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit 72abbde1f852b0d0862d95460ae211c61f33eed3
parent 561a75c771f3ac33385f1a0069608c4b99e4585d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed,  5 Jul 2017 14:34:01 +0200

Fix an alignment bug.

RNG states where allocated with default alignment, which proved insufficient
for aes-based RNGs.
Public RNG type now includes a field to specify the required alignment.

Fixed a Linux warning from Random123/aes.h too.

Diffstat:
Msrc/ssp.h | 1+
Msrc/ssp_rng.c | 22+++++++++++++++-------
Msrc/ssp_rng_proxy.c | 3++-
3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/ssp.h b/src/ssp.h @@ -79,6 +79,7 @@ struct ssp_rng_type { uint64_t min; uint64_t max; size_t sizeof_state; + size_t alignof_state; }; static FINLINE char diff --git a/src/ssp_rng.c b/src/ssp_rng.c @@ -39,6 +39,7 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" /* unsafe conversion */ #pragma GCC diagnostic ignored "-Wshadow" + #pragma GCC diagnostic ignored "-Wunused-parameter" /* in Random123/aes.h */ #elif defined(COMPILER_CL) #pragma warning(push) #pragma warning(disable:4100) /* unreferenced formal parameter */ @@ -184,7 +185,8 @@ const struct ssp_rng_type ssp_rng_kiss = { rng_kiss_entropy, 0, UINT32_MAX, - sizeof(struct rng_kiss) + sizeof(struct rng_kiss), + 16 }; /******************************************************************************* @@ -331,7 +333,8 @@ const struct ssp_rng_type ssp_rng_mt19937_64 = { rng_cxx_entropy<RAN_NAMESPACE::mt19937_64>, RAN_NAMESPACE::mt19937_64::min(), RAN_NAMESPACE::mt19937_64::max(), - sizeof(RAN_NAMESPACE::mt19937_64) + sizeof(RAN_NAMESPACE::mt19937_64), + 16 }; /* 48-bits RANLUX PRNG */ @@ -346,7 +349,8 @@ const struct ssp_rng_type ssp_rng_ranlux48 = { rng_cxx_entropy<RAN_NAMESPACE::ranlux48>, RAN_NAMESPACE::ranlux48::min(), RAN_NAMESPACE::ranlux48::max(), - sizeof(RAN_NAMESPACE::ranlux48) + sizeof(RAN_NAMESPACE::ranlux48), + 16 }; /* random_device generator */ @@ -361,7 +365,8 @@ const struct ssp_rng_type ssp_rng_random_device = { rng_cxx_entropy<RAN_NAMESPACE::random_device>, RAN_NAMESPACE::random_device::min(), RAN_NAMESPACE::random_device::max(), - sizeof(RAN_NAMESPACE::random_device) + sizeof(RAN_NAMESPACE::random_device), + 16 }; /******************************************************************************* @@ -400,7 +405,8 @@ const struct ssp_rng_type ssp_rng_threefry = { rng_cxx_entropy<threefry_T>, std::numeric_limits<threefry_T::result_type>::min(), std::numeric_limits<threefry_T::result_type>::max(), - sizeof(threefry_T) + sizeof(threefry_T), + 16 }; #ifdef WITH_R123_AES @@ -416,7 +422,8 @@ const struct ssp_rng_type ssp_rng_aes = { rng_cxx_entropy<aes_T>, std::numeric_limits<aes_T::result_type>::min(), std::numeric_limits<aes_T::result_type>::max(), - sizeof(aes_T) + sizeof(aes_T), + 16 }; #endif @@ -480,7 +487,8 @@ ssp_rng_create rng->allocator = allocator; ref_init(&rng->ref); - rng->state = MEM_CALLOC(rng->allocator, 1, type->sizeof_state); + rng->state = + MEM_ALLOC_ALIGNED(rng->allocator, type->sizeof_state, type->alignof_state); if(!rng->state) { res = RES_MEM_ERR; goto error; diff --git a/src/ssp_rng_proxy.c b/src/ssp_rng_proxy.c @@ -278,7 +278,8 @@ static const struct ssp_rng_type RNG_BUCKET_NULL = { rng_bucket_entropy, INT_MAX, /* Min dummy value */ 0, /* Max dummy value */ - sizeof(struct rng_bucket) + sizeof(struct rng_bucket), + 16 }; /*******************************************************************************