From: Niels Möller Date: Tue, 30 Oct 2001 15:29:28 +0000 (+0100) Subject: New file. X-Git-Tag: nettle_1.5_release_20020131~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe1e510126a3e8f4ec48ebf61d0827446a775112;p=thirdparty%2Fnettle.git New file. Rev: src/nettle/testsuite/bignum-test.m4:1.1 --- 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 +#include + +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 */