From fe1e510126a3e8f4ec48ebf61d0827446a775112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Tue, 30 Oct 2001 16:29:28 +0100 Subject: [PATCH] New file. Rev: src/nettle/testsuite/bignum-test.m4:1.1 --- testsuite/bignum-test.m4 | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 testsuite/bignum-test.m4 diff --git a/testsuite/bignum-test.m4 b/testsuite/bignum-test.m4 new file mode 100644 index 00000000..7344cbeb --- /dev/null +++ b/testsuite/bignum-test.m4 @@ -0,0 +1,47 @@ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#if HAVE_LIBGMP +#include "bignum.h" + +#include <stdlib.h> +#include <string.h> + +static void +test_bignum(const char *hex, unsigned length, const uint8_t *base256) +{ + mpz_t a; + mpz_t b; + uint8_t *buf; + + mpz_init_set_str(a, hex, 16); + nettle_mpz_init_set_str_256(b, length, base256); + + if (mpz_cmp(a, b)) + FAIL; + + buf = alloca(length + 1); + memset(buf, 17, length + 1); + + nettle_mpz_get_str_256(length, buf, a); + if (!MEMEQ(length, buf, base256)) + FAIL; + + if (buf[length] != 17) + FAIL; + + mpz_clear(a); mpz_clear(b); +} +#endif /* HAVE_LIBGMP */ + +BEGIN_TEST + +#if HAVE_LIBGMP +test_bignum("0", 0, ""); +test_bignum("010203040506", 7, H("00010203040506")); + +#else /* !HAVE_LIBGMP */ +SKIP +#endif /* !HAVE_LIBGMP */ -- GitLab