diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h index 33e4bc0..6d6f4f3 100644 --- a/src/headers/tomcrypt_custom.h +++ b/src/headers/tomcrypt_custom.h @@ -304,6 +304,9 @@ /* rng_make_prng() */ #define LTC_RNG_MAKE_PRNG +/* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */ +/* #define LTC_PRNG_ENABLE_LTC_RNG */ + #endif /* LTC_NO_PRNGS */ #ifdef LTC_YARROW diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h index 2bfe820..dc2cc7e 100644 --- a/src/headers/tomcrypt_prng.h +++ b/src/headers/tomcrypt_prng.h @@ -193,8 +193,10 @@ unsigned long rng_get_bytes(unsigned char *out, int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void)); +#ifdef LTC_PRNG_ENABLE_LTC_RNG extern unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); +#endif /* $Source$ */ diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index 7d03cfa..aef292f 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -371,6 +371,9 @@ const char *crypt_build_settings = #if defined(LTC_RNG_MAKE_PRNG) " LTC_RNG_MAKE_PRNG " #endif +#if defined(LTC_PRNG_ENABLE_LTC_RNG) + " LTC_PRNG_ENABLE_LTC_RNG " +#endif #if defined(LTC_HASH_HELPERS) " LTC_HASH_HELPERS " #endif diff --git a/src/misc/crypt/crypt_prng_rng_descriptor.c b/src/misc/crypt/crypt_prng_rng_descriptor.c index 14f36ff..bf31781 100644 --- a/src/misc/crypt/crypt_prng_rng_descriptor.c +++ b/src/misc/crypt/crypt_prng_rng_descriptor.c @@ -10,4 +10,6 @@ */ #include "tomcrypt.h" +#ifdef LTC_PRNG_ENABLE_LTC_RNG unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); +#endif diff --git a/src/prngs/rng_get_bytes.c b/src/prngs/rng_get_bytes.c index 7430feb..28e8585 100644 --- a/src/prngs/rng_get_bytes.c +++ b/src/prngs/rng_get_bytes.c @@ -135,12 +135,14 @@ unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, LTC_ARGCHK(out != NULL); +#ifdef LTC_PRNG_ENABLE_LTC_RNG if (ltc_rng) { x = ltc_rng(out, outlen, callback); if (x != 0) { return x; } } +#endif #if defined(_WIN32) || defined(_WIN32_WCE) x = rng_win32(out, outlen, callback); if (x != 0) { return x; } diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c index 4aee85c..2d4700f 100644 --- a/testprof/x86_prof.c +++ b/testprof/x86_prof.c @@ -302,6 +302,8 @@ static void _unregister_all(void) #endif } /* _cleanup() */ +#ifdef LTC_PRNG_ENABLE_LTC_RNG + static unsigned long my_test_rng_read; static unsigned long my_test_rng(unsigned char *buf, unsigned long len, @@ -316,6 +318,8 @@ static unsigned long my_test_rng(unsigned char *buf, unsigned long len, return n; } +#endif + void reg_algs(void) { unsigned long before; @@ -456,6 +460,7 @@ register_prng(&rc4_desc); register_prng(&sober128_desc); #endif +#ifdef LTC_PRNG_ENABLE_LTC_RNG ltc_rng = my_test_rng; before = my_test_rng_read; @@ -470,6 +475,7 @@ register_prng(&sober128_desc); } ltc_rng = NULL; +#endif if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err));