From: Andrey Rys Date: Wed, 10 Apr 2019 05:27:30 +0000 (+0700) Subject: tfprng: expose range formula in form of macros to build custom range generators. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=8f5731f876403829977834c82c7afbecc484a02d;p=tfcrypt.git tfprng: expose range formula in form of macros to build custom range generators. --- diff --git a/VERSION b/VERSION index 6f4247a..f64f5d8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -26 +27 diff --git a/tfprng.c b/tfprng.c index d4370f3..4db2418 100644 --- a/tfprng.c +++ b/tfprng.c @@ -85,7 +85,7 @@ TF_UNIT_TYPE tf_prng_range_r(void *sdata, TF_UNIT_TYPE s, TF_UNIT_TYPE d) { TF_UNIT_TYPE c = tf_prng_random_r(sdata); if (d <= s) return s; - return s + c / ((TF_UNIT_TYPE)~0 / (d - s + 1) + 1); + return TF_PRNG_RANGE(c, TF_UNIT_TYPE, s, d); } TF_UNIT_TYPE tf_prng_range(TF_UNIT_TYPE s, TF_UNIT_TYPE d) diff --git a/tfprng.h b/tfprng.h index 5fbab0a..3fab0a2 100644 --- a/tfprng.h +++ b/tfprng.h @@ -6,6 +6,7 @@ #define TF_PRNG_KEY_SIZE TF_KEY_SIZE #define TF_PRNG_SIZE_UNIT TF_SIZE_UNIT +#define TF_PRNG_RANGE(C, T, S, D) (S + C / ((T)~0 / (D - S + 1) + 1)) size_t tf_prng_datasize(void); void tf_prng_seedkey_r(void *sdata, const void *skey);