aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/pqg_gen.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-01 23:58:46 +0000
committerlloyd <[email protected]>2014-01-01 23:58:46 +0000
commit585356e222c5a6116532ba14cce44a2c6cd9c366 (patch)
tree90a50dec70a8044766fea6a5f9371b7e7c0eb0f3 /doc/examples/pqg_gen.cpp
parent48bd53d1918f9ee765313d62eacd054376c0b49e (diff)
Cull remaining mostly dubious examples. Also remove readme.txt
Diffstat (limited to 'doc/examples/pqg_gen.cpp')
-rw-r--r--doc/examples/pqg_gen.cpp119
1 files changed, 0 insertions, 119 deletions
diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp
deleted file mode 100644
index c272f793e..000000000
--- a/doc/examples/pqg_gen.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
-* (C) 2009 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <vector>
-#include <map>
-#include <memory>
-
-#include <botan/botan.h>
-#include <botan/auto_rng.h>
-#include <botan/hex.h>
-#include <botan/numthry.h>
-#include <botan/dl_group.h>
-using namespace Botan;
-
-bool check(RandomNumberGenerator& rng,
- std::map<std::string, std::string>);
-
-int main()
- {
- try {
- Botan::LibraryInitializer init("use_engines");
-
- AutoSeeded_RNG rng;
-
- std::ifstream in("PQGGen.rsp");
- if(!in)
- throw std::runtime_error("Can't open response file");
-
- std::map<std::string, std::string> inputs;
-
- while(in.good())
- {
- std::string line;
- std::getline(in, line);
-
- if(line == "" || line[0] == '[' || line[0] == '#')
- continue;
-
- std::vector<std::string> name_and_val = split_on(line, '=');
-
- if(name_and_val.size() != 2)
- throw std::runtime_error("Unexpected input: " + line);
-
- name_and_val[0].erase(name_and_val[0].size()-1);
- name_and_val[1].erase(0, 1);
-
- std::string name = name_and_val[0], value = name_and_val[1];
-
- inputs[name] = value;
-
- if(name == "H")
- {
- bool result = check(rng, inputs);
- std::cout << "." << std::flush;
- if(result == false)
- {
- std::cout << " Check failed\n";
-
- std::map<std::string, std::string>::const_iterator i;
-
- for(i = inputs.begin(); i != inputs.end(); i++)
- std::cout << i->first << " = " << i->second << "\n";
-
- std::cout << "\n";
- }
-
- inputs.clear();
- }
- }
- }
- catch(std::exception& e)
- {
- std::cout << e.what() << std::endl;
- return 1;
- }
- return 0;
- }
-
-bool check(RandomNumberGenerator& rng,
- std::map<std::string, std::string> inputs)
- {
- BigInt p("0x"+inputs["P"]),
- q("0x"+inputs["Q"]),
- g("0x"+inputs["G"]),
- h("0x"+inputs["H"]);
-
- if(h < 1 || h >= p-1) return false;
-
- //u32bit c = to_u32bit(inputs["c"]);
-
- std::vector<byte> seed = hex_decode(inputs["Seed"]);
-
- BigInt our_p, our_q;
-
- u32bit qbits = (p.bits() <= 1024) ? 160 : 256;
-
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- bool found = generate_dsa_primes(rng, af, our_p, our_q,
- p.bits(), qbits, seed);
-
- if(!found) /* bad seed */
- return false;
-
- if(our_p != p) return false;
- if(our_q != q) return false;
-
- BigInt our_g = power_mod(h, (p-1)/q, p);
-
- if(our_g != g) return false;
-
- return true;
- }