+2014-10-03 Niels Möller <nisse@lysator.liu.se>
+
+ * testsuite/ecc-sqrt-test.c (mpz_ui_kronecker)
+ [NETTLE_USE_MINI_GMP]: New fallback definition when building with
+ mini-gmp.
+ * testsuite/testutils.c (gmp_randinit_default)
+ [NETTLE_USE_MINI_GMP]: Likewise.
+ (mpz_urandomb): Likewise.
+ * testsuite/testutils.h (gmp_randstate_t) [NETTLE_USE_MINI_GMP]:
+ Fallback typedef, using knuth_lfib_ctx.
+
2014-10-02 Niels Möller <nisse@lysator.liu.se>
* testsuite/eddsa-compress-test.c: New testcase.
#define COUNT 5000
+#if NETTLE_USE_MINI_GMP
+/* Implements Legendre symbol only, requiring that p is an odd prime */
+static int
+mpz_ui_kronecker (mp_limb_t ul, const mpz_t p)
+{
+ mpz_t t, u;
+ int r;
+
+ mpz_init_set_ui (u, ul);
+ mpz_init_set (t, p);
+ mpz_sub_ui (t, t, 1);
+ mpz_tdiv_q_2exp (t, t, 1);
+ mpz_powm (t, u, t, p);
+
+ r = mpz_cmp_ui (t, 1);
+ if (r < 0)
+ r = 0;
+ else if (r == 0)
+ r = 1;
+ else
+ {
+ mpz_sub (t, p, t);
+ ASSERT (mpz_cmp_ui (t, 1) == 0);
+ r = -1;
+ }
+ mpz_clear (t);
+ mpz_clear (u);
+
+ return r;
+}
+#endif /* NETTLE_USE_MINI_GMP */
+
static void
test_modulo (gmp_randstate_t rands, const struct ecc_modulo *m)
{
}
#endif
+#if NETTLE_USE_MINI_GMP
+void
+gmp_randinit_default (struct knuth_lfib_ctx *ctx)
+{
+ knuth_lfib_init (ctx, 17);
+}
+void
+mpz_urandomb (mpz_t r, struct knuth_lfib_ctx *ctx, mp_bitcnt_t bits)
+{
+ size_t bytes = (bits+7)/8;
+ uint8_t *buf = xalloc (bytes);
+
+ knuth_lfib_random (ctx, bytes, buf);
+ buf[bytes-1] &= 0xff >> (8*bytes - bits);
+ nettle_mpz_set_str_256_u (r, bytes, buf);
+ free (buf);
+}
+#endif /* NETTLE_USE_MINI_GMP */
+
mp_limb_t *
xalloc_limbs (mp_size_t n)
{
# include "ecc-internal.h"
# include "ecdsa.h"
# include "gmp-glue.h"
+# if NETTLE_USE_MINI_GMP
+# include "knuth-lfib.h"
+# endif
/* Undo dsa-compat name mangling */
#undef dsa_generate_keypair
#define dsa_generate_keypair nettle_dsa_generate_keypair
-#endif
+#endif /* WITH_HOGWEED */
#include "nettle-meta.h"
mpn_zero_p (mp_srcptr ap, mp_size_t n);
#endif
+#if NETTLE_USE_MINI_GMP
+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);
+/* This is cheating */
+#define mpz_rrandomb mpz_urandomb
+
+#endif /* NETTLE_USE_MINI_GMP */
+
mp_limb_t *
xalloc_limbs (mp_size_t n);