From 9b48a5cf75356bb6beb4af04706ef19ede10d228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Wed, 17 Aug 2022 16:53:11 +0200 Subject: tests: Define mpz_urandomm when building with mini-gmp. --- ChangeLog | 5 +++++ testsuite/testutils.c | 7 +++++++ testsuite/testutils.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 083d443a..7d68e21b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-08-17 Niels Möller + + * testsuite/testutils.c (mpz_urandomm) [NETTLE_USE_MINI_GMP]: New + fallback definition when building with mini-gmp. + 2022-08-16 Niels Möller * ecc-mod-arith.c (ecc_mod_sub): Ensure that if inputs are in the diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 0d91d8ef..39c6bece 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -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) diff --git a/testsuite/testutils.h b/testsuite/testutils.h index 3e239787..00555b3a 100644 --- a/testsuite/testutils.h +++ b/testsuite/testutils.h @@ -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 */ -- cgit v1.2.1