On Thu, 16 Aug 2012, Samuel Pitoiset wrote:

Replace mpz_random by mpz_urandomb with a random state initialization in
order to improve the randomness.
---
libavformat/rtmpdh.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtmpdh.c b/libavformat/rtmpdh.c
index 92bce7a..38c2f3d 100644
--- a/libavformat/rtmpdh.c
+++ b/libavformat/rtmpdh.c
@@ -28,6 +28,7 @@

#include "config.h"
#include "rtmpdh.h"
+#include "libavutil/random_seed.h"

#define P1024                                          \
    "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
@@ -78,7 +79,14 @@
            ret = (mpz_set_str(bn, buf, 16) == 0);  \
    } while (0)
#define bn_modexp(bn, y, q, p)      mpz_powm(bn, y, q, p)
-#define bn_random(bn, num_bytes)    mpz_random(bn, num_bytes);
+#define bn_random(bn, num_bytes)                    \
+    do {                                            \
+        gmp_randstate_t rs;                         \
+        gmp_randinit_mt(rs);                        \
+        gmp_randseed_ui(rs, av_get_random_seed());  \
+        mpz_urandomb(bn, rs, num_bytes);            \
+        gmp_randclear(rs);                          \
+    } while (0)

Ok.

You could have used the LFG PRNG in libavutil/lfg.h also, but this is ok as well, no need to change it.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to