# HG changeset patch # User Matt Johnston # Date 1603118959 -28800 # Node ID 34d9d3c022ce00425c4be6d7aa6ee1625e2fc8b3 # Parent ff51d5967e2dd579b9f5f2b8db96270c35c4ac5e Use Dropbear's random source rather than libtommath's platform diff -r ff51d5967e2d -r 34d9d3c022ce crypto_desc.c --- a/crypto_desc.c Mon Oct 19 21:38:20 2020 +0800 +++ b/crypto_desc.c Mon Oct 19 22:49:19 2020 +0800 @@ -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 @@ } #endif + mp_rand_source(dropbear_rand_source); + #if DROPBEAR_ECC ltc_mp = ltm_desc; dropbear_ecc_fill_dp(); diff -r ff51d5967e2d -r 34d9d3c022ce libtommath/bn_mp_rand.c --- a/libtommath/bn_mp_rand.c Mon Oct 19 21:38:20 2020 +0800 +++ b/libtommath/bn_mp_rand.c Mon Oct 19 22:49:19 2020 +0800 @@ -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 -r ff51d5967e2d -r 34d9d3c022ce libtommath/tommath_class.h --- a/libtommath/tommath_class.h Mon Oct 19 21:38:20 2020 +0800 +++ b/libtommath/tommath_class.h Mon Oct 19 22:49:19 2020 +0800 @@ -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