From fe7c4e39933443b423d22085d2dc23ec4d93c7ce Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 8 Sep 2015 21:13:17 +0200 Subject: [PATCH] add ltc_rng function pointer the idea is to be able to easily provide a plug-in rng for a specific platform without the need to touch the library. --- src/headers/tomcrypt_prng.h | 3 +++ src/misc/crypt/crypt_prng_rng_descriptor.c | 13 +++++++++++++ src/prngs/rng_get_bytes.c | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 src/misc/crypt/crypt_prng_rng_descriptor.c diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h index 4880b05..2bfe820 100644 --- a/src/headers/tomcrypt_prng.h +++ b/src/headers/tomcrypt_prng.h @@ -193,6 +193,9 @@ unsigned long rng_get_bytes(unsigned char *out, int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void)); +extern unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, + void (*callback)(void)); + /* $Source$ */ /* $Revision$ */ diff --git a/src/misc/crypt/crypt_prng_rng_descriptor.c b/src/misc/crypt/crypt_prng_rng_descriptor.c new file mode 100644 index 0000000..14f36ff --- /dev/null +++ b/src/misc/crypt/crypt_prng_rng_descriptor.c @@ -0,0 +1,13 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); diff --git a/src/prngs/rng_get_bytes.c b/src/prngs/rng_get_bytes.c index f0536f6..7430feb 100644 --- a/src/prngs/rng_get_bytes.c +++ b/src/prngs/rng_get_bytes.c @@ -135,6 +135,13 @@ unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, LTC_ARGCHK(out != NULL); + if (ltc_rng) { + x = ltc_rng(out, outlen, callback); + if (x != 0) { + return x; + } + } + #if defined(_WIN32) || defined(_WIN32_WCE) x = rng_win32(out, outlen, callback); if (x != 0) { return x; } #elif defined(LTC_DEVRANDOM)