summaryrefslogtreecommitdiff
path: root/tests/keygen.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-11-04 12:03:40 +0000
committerWerner Koch <wk@gnupg.org>2003-11-04 12:03:40 +0000
commitcaa019c4830e5d35dc2b988a0377b34034af8316 (patch)
tree2476eaa5e3970f7a4ee7d978aa53c24ad6c45035 /tests/keygen.c
parent56daf753b3749534bc180bbf8b9adc018a888885 (diff)
downloadlibgcrypt-caa019c4830e5d35dc2b988a0377b34034af8316.tar.gz
* Makefile.am (noinst_PROGRAMS): Use this so that test programs
get always build. * keygen.c (check_nonce): New. (main): Add a basic check for the nocen function.
Diffstat (limited to 'tests/keygen.c')
-rw-r--r--tests/keygen.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/keygen.c b/tests/keygen.c
index 1d855f07..6cc8d4cb 100644
--- a/tests/keygen.c
+++ b/tests/keygen.c
@@ -176,7 +176,43 @@ check_rsa_keys (void)
}
+static void
+check_nonce (void)
+{
+ char a[32], b[32];
+ int i,j;
+ int oops=0;
+ if (verbose)
+ fprintf (stderr, "checking gcry_create_nonce\n");
+
+ gcry_create_nonce (a, sizeof a);
+ for (i=0; i < 10; i++)
+ {
+ gcry_create_nonce (b, sizeof b);
+ if (!memcmp (a, b, sizeof a))
+ die ("identical nounce found\n");
+ }
+ for (i=0; i < 10; i++)
+ {
+ gcry_create_nonce (a, sizeof a);
+ if (!memcmp (a, b, sizeof a))
+ die ("identical nounce found\n");
+ }
+
+ again:
+ for (i=1,j=0; i < sizeof a; i++)
+ if (a[0] == a[i])
+ j++;
+ if (j+1 == sizeof (a))
+ {
+ if (oops)
+ die ("impossible nonce found\n");
+ oops++;
+ gcry_create_nonce (a, sizeof a);
+ goto again;
+ }
+}
int
main (int argc, char **argv)
@@ -196,7 +232,9 @@ main (int argc, char **argv)
gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
/* No valuable keys are create, so we can speed up our RNG. */
gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+
check_rsa_keys ();
+ check_nonce ();
return error_count? 1:0;
}