File: random-prime-test.c

package info (click to toggle)
nettle 3.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,508 kB
  • sloc: ansic: 72,410; asm: 21,179; sh: 4,328; makefile: 837; cpp: 71; awk: 7
file content (28 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (2)
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
#include "testutils.h"

#include "knuth-lfib.h"

void
test_main(void)
{
  struct knuth_lfib_ctx lfib;
  mpz_t p;
  unsigned bits;

  knuth_lfib_init(&lfib, 17);

  mpz_init(p);
  for (bits = 6; bits < 1000; bits = bits + 1 + bits/10)
    {
      if (verbose)
	fprintf(stderr, "bits = %d\n", bits);
      
      nettle_random_prime(p, bits, 0,
			  &lfib, (nettle_random_func *) knuth_lfib_random,
			  NULL, NULL);
      ASSERT (mpz_sizeinbase (p, 2) == bits);
      ASSERT (mpz_probab_prime_p(p, 25));
    }

  mpz_clear(p);
}