]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: added sanity check for included primes
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 11 Oct 2016 18:01:27 +0000 (20:01 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 14 Oct 2016 20:55:38 +0000 (22:55 +0200)
tests/suite/Makefile.am
tests/suite/prime-check.c [new file with mode: 0644]

index 6ef7456071721289f4a70f050d7533ad79e09ab1..00f4aa6080e5082cee155bea2ce3cafc0947f624 100644 (file)
@@ -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 (file)
index 0000000..ee0af17
--- /dev/null
@@ -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 <nettle/bignum.h>
+#include <gmp.h>
+#include <gnutls/gnutls.h>
+#include <assert.h>
+
+/* 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;
+}