aboutsummaryrefslogtreecommitdiffstats
path: root/examples/sig_gen.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-04-04 03:43:52 +0000
committerlloyd <[email protected]>2011-04-04 03:43:52 +0000
commit3b9bfbd07c3723662832caf5b1efe04de28b656d (patch)
treeee2a9324f384efead6e5bb87ac8374e7e8734c90 /examples/sig_gen.cpp
parent04db054f1ae8de572ee9c0cfe227e76f84096bd6 (diff)
Convert most of the documentation to reStructured Text, adding
a makefile to build it with Sphinx (http://sphinx.pocoo.org/). Previously credits.txt listed public domain code sources; instead directly credit the authors in the relevant files and delete that file. Drop the draft FIPS 140 security policy; I can't imagine FIPS 140 validation will ever happen, and if it does, I don't want anything to do with it. Also drop the internals doc, which was so out of date (and incomplete) as to be worthless. Move the tutorials and InSiTo pdfs into old/ for the time being, until anything relevant from them can be filtered out and converted into RST.
Diffstat (limited to 'examples/sig_gen.cpp')
-rw-r--r--examples/sig_gen.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/examples/sig_gen.cpp b/examples/sig_gen.cpp
new file mode 100644
index 000000000..cf273216a
--- /dev/null
+++ b/examples/sig_gen.cpp
@@ -0,0 +1,96 @@
+/*
+* (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/dsa.h>
+#include <botan/pubkey.h>
+using namespace Botan;
+
+bool check(std::map<std::string, std::string>);
+
+int main()
+ {
+ try {
+ Botan::LibraryInitializer init;
+
+ std::ifstream in("SigGen.rsp");
+ if(!in)
+ throw Exception("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 Decoding_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 == "S")
+ {
+ bool result = check(inputs);
+ 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";
+ }
+ inputs["Msg"] = inputs["R"] = inputs["S"] = "";
+ }
+ }
+ }
+ catch(std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+ }
+
+bool check(std::map<std::string, std::string> inputs)
+ {
+ BigInt p("0x"+inputs["P"]),
+ q("0x"+inputs["Q"]),
+ g("0x"+inputs["G"]),
+ y("0x"+inputs["Y"]);
+
+ DSA_PublicKey key(DL_Group(p, q, g), y);
+
+ Pipe pipe(new Hex_Decoder);
+
+ pipe.process_msg(inputs["Msg"]);
+ pipe.start_msg();
+ pipe.write(inputs["R"]);
+ pipe.write(inputs["S"] );
+ pipe.end_msg();
+
+ PK_Verifier verifier(key, "EMSA1(SHA-1)");
+
+ return verifier.verify_message(pipe.read_all(0), pipe.read_all(1));
+ }