6fee1da5d697028beb14e6b8b602166e1f80180c
[platform/upstream/nettle.git] / testsuite / dsa-keygen-test.c
1 #include "testutils.h"
2
3 #include "knuth-lfib.h"
4
5 static void
6 progress(void *ctx UNUSED, int c)
7 {
8   fputc(c, stderr);
9 }
10
11 void
12 test_main(void)
13 {
14   struct dsa_public_key pub;
15   struct dsa_private_key key;
16   struct dsa_params *params;
17
18   struct knuth_lfib_ctx lfib;
19   
20   dsa_private_key_init(&key);
21   dsa_public_key_init(&pub);
22
23   knuth_lfib_init(&lfib, 13);
24
25   params = (struct dsa_params *) &pub;
26   ASSERT (dsa_compat_generate_keypair(&pub, &key,
27                                &lfib,
28                                (nettle_random_func *) knuth_lfib_random,
29                                NULL, verbose ? progress : NULL,
30                                1024, 160));
31
32   test_dsa_key(params, pub.y, key.x, 160);
33   test_dsa160(&pub, &key, NULL);
34
35   ASSERT (dsa_compat_generate_keypair(&pub, &key,
36                                &lfib,
37                                (nettle_random_func *) knuth_lfib_random,
38                                NULL, verbose ? progress : NULL,
39                                2048, 256));
40
41   test_dsa_key(params, pub.y, key.x, 256);
42   test_dsa256(&pub, &key, NULL);
43   
44   ASSERT (dsa_compat_generate_keypair(&pub, &key,
45                                &lfib,
46                                (nettle_random_func *) knuth_lfib_random,
47                                NULL, verbose ? progress : NULL,
48                                2048, 224));
49
50   test_dsa_key(params, pub.y, key.x, 224);
51   test_dsa256(&pub, &key, NULL);
52
53   /* Test with large q */
54   if (!dsa_generate_params (params,
55                             &lfib,
56                             (nettle_random_func *) knuth_lfib_random,
57                             NULL, verbose ? progress : NULL,
58                             1024, 768))
59     FAIL();
60
61   dsa_generate_keypair (params, pub.y, key.x,
62                         &lfib,
63                         (nettle_random_func *) knuth_lfib_random);
64   test_dsa_key(params, pub.y, key.x, 768);
65   test_dsa256(&pub, &key, NULL);
66   
67   dsa_public_key_clear(&pub);
68   dsa_private_key_clear(&key);
69 }