diff options
-rw-r--r-- | crypto_desc.c | 9 | ||||
-rw-r--r-- | libtommath/bn_mp_rand.c | 6 | ||||
-rw-r--r-- | libtommath/tommath_class.h | 2 |
3 files changed, 15 insertions, 2 deletions
diff --git a/crypto_desc.c b/crypto_desc.c index 0f946fc..50b63dc 100644 --- a/crypto_desc.c +++ b/crypto_desc.c @@ -3,11 +3,18 @@ #include "crypto_desc.h" #include "ltc_prng.h" #include "ecc.h" +#include "dbrandom.h" #if DROPBEAR_LTC_PRNG int dropbear_ltc_prng = -1; #endif +/* Wrapper for libtommath */ +static mp_err dropbear_rand_source(void* out, size_t size) { + genrandom((unsigned char*)out, (unsigned int)size); + return MP_OKAY; +} + /* Register the compiled in ciphers. * This should be run before using any of the ciphers/hashes */ @@ -67,6 +74,8 @@ void crypto_init() { } #endif + mp_rand_source(dropbear_rand_source); + #if DROPBEAR_ECC ltc_mp = ltm_desc; dropbear_ecc_fill_dp(); diff --git a/libtommath/bn_mp_rand.c b/libtommath/bn_mp_rand.c index 7e9052c..110efe3 100644 --- a/libtommath/bn_mp_rand.c +++ b/libtommath/bn_mp_rand.c @@ -3,11 +3,13 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -mp_err(*s_mp_rand_source)(void *out, size_t size) = s_mp_rand_platform; +/* Dropbear sets this separately, avoid platform code */ +mp_err(*s_mp_rand_source)(void *out, size_t size) = NULL; void mp_rand_source(mp_err(*source)(void *out, size_t size)) { - s_mp_rand_source = (source == NULL) ? s_mp_rand_platform : source; + /* Dropbear, don't reset to platform if source==NULL */ + s_mp_rand_source = source; } mp_err mp_rand(mp_int *a, int digits) diff --git a/libtommath/tommath_class.h b/libtommath/tommath_class.h index 19bef02..7e02515 100644 --- a/libtommath/tommath_class.h +++ b/libtommath/tommath_class.h @@ -1316,6 +1316,8 @@ #undef BN_S_MP_KARATSUBA_SQR_C #undef BN_S_MP_TOOM_MUL_C #undef BN_S_MP_TOOM_SQR_C +/* Dropbear uses its own random source */ +#undef BN_S_MP_RAND_PLATFORM_C #include "dbmalloc.h" #define MP_MALLOC m_malloc |