From c2f5c041cba0cafdf3a554a5fe8445ce16eeb562 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 11 Oct 2016 20:01:27 +0200 Subject: tests: added sanity check for included primes --- tests/suite/Makefile.am | 5 +++-- tests/suite/prime-check.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/suite/prime-check.c diff --git a/tests/suite/Makefile.am b/tests/suite/Makefile.am index 6ef7456071..00f4aa6080 100644 --- a/tests/suite/Makefile.am +++ b/tests/suite/Makefile.am @@ -34,13 +34,14 @@ EXTRA_DIST = crl/long.crl crl/long.pem data/test1.cat data/test2.cat \ data/test1.cat.data data/test2.cat.data \ data/test1.cat.out data/test2.cat.out data/ca.pem -check_PROGRAMS = rng +check_PROGRAMS = rng prime-check AM_LDFLAGS = -no-install LDADD = ../../lib/libgnutls.la \ ../../gl/libgnu.la \ ../libutils.la \ $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB) +prime_check_LDADD = $(LDADD) -lhogweed -lgmp libecore_la_CPPFLAGS = -I$(top_srcdir)/tests/suite/ecore/ \ -I$(top_srcdir)/tests/suite/ecore/src/include \ @@ -128,7 +129,7 @@ nodist_check_SCRIPTS += eagain.sh endif endif -TESTS = $(nodist_check_SCRIPTS) +TESTS = $(nodist_check_SCRIPTS) prime-check TEST_EXTENSIONS = .sh diff --git a/tests/suite/prime-check.c b/tests/suite/prime-check.c new file mode 100644 index 0000000000..ee0af1773c --- /dev/null +++ b/tests/suite/prime-check.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 Nikos Mavrogiannopoulos + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * GnuTLS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuTLS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GnuTLS; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include + +/* Tests whether the included parameters are indeed prime */ + +static void test_prime(const gnutls_datum_t * prime) +{ + mpz_t p; + unsigned bits = prime->size * 8; + + nettle_mpz_init_set_str_256_u(p, prime->size, prime->data); + + assert(mpz_sizeinbase(p, 2) == bits); + assert(mpz_probab_prime_p(p, 18)); + + mpz_clear(p); +} + +int main(int argc, char **argv) +{ + test_prime(&gnutls_srp_4096_group_prime); + test_prime(&gnutls_srp_3072_group_prime); + test_prime(&gnutls_srp_2048_group_prime); + test_prime(&gnutls_srp_1536_group_prime); + test_prime(&gnutls_srp_1024_group_prime); + + test_prime(&gnutls_ffdhe_8192_group_prime); + test_prime(&gnutls_ffdhe_4096_group_prime); + test_prime(&gnutls_ffdhe_3072_group_prime); + test_prime(&gnutls_ffdhe_2048_group_prime); + + return 0; +} -- cgit v1.2.1