File: dsa-keygen-test.c

package info (click to toggle)
nettle 1.12-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,684 kB
  • ctags: 2,083
  • sloc: ansic: 17,321; asm: 3,437; sh: 3,033; makefile: 434
file content (44 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (7)
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
#include "testutils.h"

#include "knuth-lfib.h"

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

int
test_main(void)
{
#if WITH_PUBLIC_KEY

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

  /* Generate a 1024 bit key with random e */
  knuth_lfib_init(&lfib, 13);

  if (!dsa_generate_keypair(&pub, &key,
			    &lfib, (nettle_random_func) knuth_lfib_random,
			    NULL, verbose ? progress : NULL,
			    1024))
    FAIL();

  test_dsa_key(&pub, &key);
  test_dsa(&pub, &key);

  dsa_public_key_clear(&pub);
  dsa_private_key_clear(&key);
  
  SUCCESS();
  
#else /* !WITH_PUBLIC_KEY */
  SKIP();
#endif /* !WITH_PUBLIC_KEY */
}