]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
tests: Define mpz_urandomm when building with mini-gmp.
authorNiels Möller <nisse@lysator.liu.se>
Wed, 17 Aug 2022 14:53:11 +0000 (16:53 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 17 Aug 2022 14:53:11 +0000 (16:53 +0200)
ChangeLog
testsuite/testutils.c
testsuite/testutils.h

index 083d443a17300d9ffa21287a0a17053a2e240453..7d68e21bae1ecd37cae61ff91e6872ecc08f4cef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-17  Niels Möller  <nisse@lysator.liu.se>
+
+       * testsuite/testutils.c (mpz_urandomm) [NETTLE_USE_MINI_GMP]: New
+       fallback definition when building with mini-gmp.
+
 2022-08-16  Niels Möller  <nisse@lysator.liu.se>
 
        * ecc-mod-arith.c (ecc_mod_sub): Ensure that if inputs are in the
index 0d91d8ef26963100b7a55183c3b4ac13c374d355..39c6bece8d3f00eb9cd755b22d74e1ea7e7da218 100644 (file)
@@ -1109,6 +1109,13 @@ mpz_urandomb (mpz_t r, struct knuth_lfib_ctx *ctx, mp_bitcnt_t bits)
   nettle_mpz_set_str_256_u (r, bytes, buf);
   free (buf);
 }
+void
+mpz_urandomm (mpz_t r, struct knuth_lfib_ctx *ctx, const mpz_t n)
+{
+  /* Add some extra bits, to make result almost unbiased. */
+  mpz_urandomb(r, ctx, mpz_sizeinbase(n, 2) + 30);
+  mpz_mod(r, r, n);
+}
 #else /* !NETTLE_USE_MINI_GMP */
 static void
 get_random_seed(mpz_t seed)
index 3e239787c677b3818c6641dca1f6d291387134e0..00555b3a60accaa59b44d7e14baf40c6547c15aa 100644 (file)
@@ -164,8 +164,10 @@ typedef struct knuth_lfib_ctx gmp_randstate_t[1];
 void gmp_randinit_default (struct knuth_lfib_ctx *ctx);
 #define gmp_randclear(state)
 void mpz_urandomb (mpz_t r, struct knuth_lfib_ctx *ctx, mp_bitcnt_t bits);
+void mpz_urandomm (mpz_t r, struct knuth_lfib_ctx *ctx, const mpz_t n);
 /* This is cheating */
 #define mpz_rrandomb mpz_urandomb
+#define mpz_rrandomm mpz_urandomm
 static inline int
 test_randomize (gmp_randstate_t rands UNUSED) { return 0; }
 #else /* !NETTLE_USE_MINI_GMP */