aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/prime.cpp
blob: 82efa75d2713523079aabe81ddab78a0bf310dd2 (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
/*
* (C) 2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "apps.h"

#if defined(BOTAN_HAS_NUMBERTHEORY)

#include <botan/numthry.h>

#include <algorithm>
#include <iostream>

namespace {

int prime(const std::vector<std::string> &args)
   {
   if(args.size() < 2)
      {
      std::cout << "Usage: " << args[0] << " bits count" << std::endl;
      return 1;
      }

   AutoSeeded_RNG rng;
   const size_t bits = to_u32bit(args[1]);
   const size_t cnt = args.size() >= 3 ? to_u32bit(args[2]) : 1;

   for(size_t i = 0; i != cnt; ++i)
      {
      const BigInt p = random_prime(rng, bits);
      std::cout << p << std::endl;

      if(p.bits() != bits)
         {
         std::cout << "Result not exactly requested bit size, got " << p.bits() << std::endl;
         }
      }

   return 0;
   }

}

REGISTER_APP(prime);

#endif