summaryrefslogtreecommitdiff
path: root/testsuite/dsa-keygen-test.c
blob: bdfb3632461da781f5460729bf4c450a165db78e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "testutils.h"

#include "knuth-lfib.h"

static void
progress(void *ctx UNUSED, int c)
{
  fputc(c, stderr);
}

void
test_main(void)
{
  struct dsa_public_key pub;
  struct dsa_private_key key;
  struct dsa_params *params;

  struct knuth_lfib_ctx lfib;
  
  dsa_private_key_init(&key);
  dsa_public_key_init(&pub);

  knuth_lfib_init(&lfib, 13);

  params = (struct dsa_params *) &pub;
  ASSERT (dsa_compat_generate_keypair(&pub, &key,
			       &lfib,
			       (nettle_random_func *) knuth_lfib_random,
			       NULL, verbose ? progress : NULL,
			       1024, 160));

  test_dsa_key(params, pub.y, key.x, 160);
  test_dsa160(&pub, &key, NULL);

  ASSERT (dsa_compat_generate_keypair(&pub, &key,
			       &lfib,
			       (nettle_random_func *) knuth_lfib_random,
			       NULL, verbose ? progress : NULL,
			       2048, 256));

  test_dsa_key(params, pub.y, key.x, 256);
  test_dsa256(&pub, &key, NULL);
  
  ASSERT (dsa_compat_generate_keypair(&pub, &key,
			       &lfib,
			       (nettle_random_func *) knuth_lfib_random,
			       NULL, verbose ? progress : NULL,
			       2048, 224));

  test_dsa_key(params, pub.y, key.x, 224);
  test_dsa256(&pub, &key, NULL);


  /* Test with large q */
  if (!dsa_generate_params (params,
			    &lfib,
			    (nettle_random_func *) knuth_lfib_random,
			    NULL, verbose ? progress : NULL,
			    1024, 768))
    FAIL();

  dsa_generate_keypair (params, pub.y, key.x,
			&lfib,
			(nettle_random_func *) knuth_lfib_random);
  test_dsa_key(params, pub.y, key.x, 768);
  test_dsa256(&pub, &key, NULL);
  
  dsa_public_key_clear(&pub);
  dsa_private_key_clear(&key);
}