aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-03 02:02:48 +0000
committerlloyd <[email protected]>2010-03-03 02:02:48 +0000
commit82ab6d27cc2b434b4b7ffa528396d67fe6993222 (patch)
tree6be9207091acf15df1936ab072a2562c7f111ff9 /doc
parenta0d6ce4ce5ccb0108cdd155c7abd830432dc6991 (diff)
Fix minor errors and warnings in the examples. Remove boost dependency from
rng_test example.
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/bench.cpp4
-rw-r--r--doc/examples/cpuid.cpp4
-rw-r--r--doc/examples/dsa_ver.cpp4
-rw-r--r--doc/examples/eax_test.cpp8
-rw-r--r--doc/examples/ecdsa.cpp2
-rw-r--r--doc/examples/factor.cpp11
-rw-r--r--doc/examples/fpe.cpp4
-rw-r--r--doc/examples/gen_certs.cpp4
-rw-r--r--doc/examples/hash_quickly.cpp24
-rw-r--r--doc/examples/package.cpp5
-rw-r--r--doc/examples/read_ssh.cpp4
-rw-r--r--doc/examples/ressol.cpp86
-rw-r--r--doc/examples/rng_test.cpp32
-rw-r--r--doc/examples/tls_client.cpp2
-rw-r--r--doc/examples/x509info.cpp4
15 files changed, 78 insertions, 120 deletions
diff --git a/doc/examples/bench.cpp b/doc/examples/bench.cpp
index 87a537493..3bcfbf5f3 100644
--- a/doc/examples/bench.cpp
+++ b/doc/examples/bench.cpp
@@ -13,6 +13,8 @@ using namespace Botan;
#include <iostream>
+namespace {
+
const std::string algos[] = {
"AES-128",
"AES-192",
@@ -85,6 +87,8 @@ void benchmark_algo(const std::string& algo,
std::cout << "\n";
}
+}
+
int main(int argc, char* argv[])
{
LibraryInitializer init;
diff --git a/doc/examples/cpuid.cpp b/doc/examples/cpuid.cpp
index 8adc8be6c..62b565edf 100644
--- a/doc/examples/cpuid.cpp
+++ b/doc/examples/cpuid.cpp
@@ -9,6 +9,8 @@
using namespace Botan;
+namespace {
+
void print_if_feature(const std::string& feature_name, bool exists)
{
if(exists)
@@ -17,6 +19,8 @@ void print_if_feature(const std::string& feature_name, bool exists)
std::cout << '[' << feature_name << ']' << '\n';
}
+}
+
int main()
{
std::cout << "Cache line size = " << CPUID::cache_line_size() << "\n";
diff --git a/doc/examples/dsa_ver.cpp b/doc/examples/dsa_ver.cpp
index 4a2f62ce4..49d9d9bbc 100644
--- a/doc/examples/dsa_ver.cpp
+++ b/doc/examples/dsa_ver.cpp
@@ -25,6 +25,8 @@ signature format, encoded into base64 with a trailing newline.
#include <botan/dsa.h>
using namespace Botan;
+namespace {
+
SecureVector<byte> b64_decode(const std::string& in)
{
Pipe pipe(new Base64_Decoder);
@@ -32,6 +34,8 @@ SecureVector<byte> b64_decode(const std::string& in)
return pipe.read_all();
}
+}
+
int main(int argc, char* argv[])
{
if(argc != 4)
diff --git a/doc/examples/eax_test.cpp b/doc/examples/eax_test.cpp
index 3f7dbcbc8..32311800d 100644
--- a/doc/examples/eax_test.cpp
+++ b/doc/examples/eax_test.cpp
@@ -14,7 +14,9 @@
using namespace Botan;
-unsigned to_string(const std::string& s)
+namespace {
+
+unsigned from_string(const std::string& s)
{
std::istringstream stream(s);
unsigned n;
@@ -211,7 +213,7 @@ void run_tests(std::istream& in)
if(boost::regex_match(line, what, vec_regex, boost::match_extra))
{
- unsigned n = to_string(what[1]);
+ unsigned n = from_string(what[1]);
std::string ciphertext = what[2];
std::string tag = what[3];
@@ -230,6 +232,8 @@ void run_tests(std::istream& in)
}
+}
+
int main()
{
std::ifstream in("eax_tv.txt");
diff --git a/doc/examples/ecdsa.cpp b/doc/examples/ecdsa.cpp
index f55005544..311a13ad9 100644
--- a/doc/examples/ecdsa.cpp
+++ b/doc/examples/ecdsa.cpp
@@ -22,7 +22,7 @@ int main()
{
AutoSeeded_RNG rng;
- EC_Domain_Params params = get_EC_Dom_Pars_by_oid("1.3.132.0.8");
+ EC_Domain_Params params("1.3.132.0.8");
ECDSA_PrivateKey ecdsa(rng, params);
diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp
index 7700d9b2d..b0105426b 100644
--- a/doc/examples/factor.cpp
+++ b/doc/examples/factor.cpp
@@ -17,11 +17,14 @@ using namespace Botan;
#include <iostream>
#include <memory>
-// Pollard's Rho algorithm, as described in the MIT algorithms book
-// We use (x^2+x) mod n instead of (x*2-1) mod n as the random function,
-// it _seems_ to lead to faster factorization for the values I tried.
+namespace {
+/*
+* Pollard's Rho algorithm, as described in the MIT algorithms book. We
+* use (x^2+x) mod n instead of (x*2-1) mod n as the random function,
+* it _seems_ to lead to faster factorization for the values I tried.
+*/
BigInt rho(const BigInt& n, RandomNumberGenerator& rng)
{
BigInt x = BigInt::random_integer(rng, 0, n-1);
@@ -117,6 +120,8 @@ std::vector<BigInt> factorize(const BigInt& n_in,
return factors;
}
+}
+
int main(int argc, char* argv[])
{
if(argc != 2)
diff --git a/doc/examples/fpe.cpp b/doc/examples/fpe.cpp
index 73773994b..9b18d4879 100644
--- a/doc/examples/fpe.cpp
+++ b/doc/examples/fpe.cpp
@@ -18,6 +18,8 @@ using namespace Botan;
#include <iostream>
#include <stdexcept>
+namespace {
+
byte luhn_checksum(u64bit cc_number)
{
byte sum = 0;
@@ -109,6 +111,8 @@ u64bit decrypt_cc_number(u64bit enc_cc,
return cc_derank(dec_cc);
}
+}
+
int main(int argc, char* argv[])
{
LibraryInitializer init;
diff --git a/doc/examples/gen_certs.cpp b/doc/examples/gen_certs.cpp
index 0d04d6d1c..f8c9fe124 100644
--- a/doc/examples/gen_certs.cpp
+++ b/doc/examples/gen_certs.cpp
@@ -20,6 +20,8 @@ using namespace Botan;
#include <iostream>
#include <fstream>
+namespace {
+
void fill_commoninfo(X509_Cert_Options& opts)
{
opts.country = "US";
@@ -77,6 +79,8 @@ void save_pair(const std::string& name,
key_out.close();
}
+}
+
int main()
{
const u32bit seconds_in_a_year = 31556926;
diff --git a/doc/examples/hash_quickly.cpp b/doc/examples/hash_quickly.cpp
index a5236b381..1af0e8f45 100644
--- a/doc/examples/hash_quickly.cpp
+++ b/doc/examples/hash_quickly.cpp
@@ -4,16 +4,6 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/botan.h>
-#include <botan/benchmark.h>
-#include <botan/filters.h>
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <map>
-#include <cstdlib>
-
/*
Try to find the fastest SHA-1 implementation and use it to hash
files. In most programs this isn't worth the bother and
@@ -25,6 +15,18 @@ Of course you could also just do this once and save it as an
application config, which is probably the smart thing to do.
*/
+#include <botan/botan.h>
+#include <botan/benchmark.h>
+#include <botan/filters.h>
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <map>
+#include <cstdlib>
+
+namespace {
+
void set_fastest_implementation(const std::string& algo,
Botan::RandomNumberGenerator& rng,
double ms = 30)
@@ -54,6 +56,8 @@ void set_fastest_implementation(const std::string& algo,
af.set_preferred_provider(algo, fastest_provider);
}
+}
+
int main(int argc, char* argv[])
{
if(argc <= 1)
diff --git a/doc/examples/package.cpp b/doc/examples/package.cpp
index 14d215f73..bdb5b78c0 100644
--- a/doc/examples/package.cpp
+++ b/doc/examples/package.cpp
@@ -4,7 +4,6 @@
* Distributed under the terms of the Botan license
*/
-
#include <botan/botan.h>
#include <botan/serpent.h>
#include <botan/package.h>
@@ -15,6 +14,8 @@
using namespace Botan;
+namespace {
+
std::vector<byte> slurp_file(const std::string& filename)
{
std::ifstream in(filename.c_str());
@@ -33,6 +34,8 @@ std::vector<byte> slurp_file(const std::string& filename)
return out;
}
+}
+
int main(int argc, char* argv[])
{
if(argc != 2)
diff --git a/doc/examples/read_ssh.cpp b/doc/examples/read_ssh.cpp
index 52c758ceb..f6299a29d 100644
--- a/doc/examples/read_ssh.cpp
+++ b/doc/examples/read_ssh.cpp
@@ -17,6 +17,8 @@
using namespace Botan;
+namespace {
+
u32bit read_u32bit(Pipe& pipe)
{
byte out[4] = { 0 };
@@ -104,6 +106,8 @@ Public_Key* read_ssh_pubkey(const std::string& file)
return 0;
}
+}
+
#include <botan/init.h>
#include <iostream>
diff --git a/doc/examples/ressol.cpp b/doc/examples/ressol.cpp
deleted file mode 100644
index 286377fc6..000000000
--- a/doc/examples/ressol.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-* (C) 2009 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/numthry.h>
-#include <botan/auto_rng.h>
-#include <botan/botan.h>
-
-using namespace Botan;
-
-#include <iostream>
-
-void test_ressol(const BigInt& p, RandomNumberGenerator& rng)
- {
- std::cout << p << std::endl;
-
- // const BigInt p_16 = p / 16;
-
- int noroot = 0, false_result = 0;
-
- for(int j = 0; j != 1000; ++j)
- {
- BigInt x = BigInt::random_integer(rng, 0, p);
- //if(x % p_16 == 0)
- //std::cout << "p = " << p << " x = " << x << "\n";
-
- BigInt sqrt_x = ressol(x, p);
-
- if(sqrt_x < 0)
- {
- ++noroot;
- continue;
- }
-
- BigInt check = square(sqrt_x) % p;
-
- if(check != x % p)
- {
- std::cout << "FAIL "
- << "x = " << x << "; "
- << "p = " << p << "; "
- << "s = " << sqrt_x << "; "
- << "s^2%p = " << check << "\n";
- ++false_result;
- }
- }
- /*
- std::cout << "nomatch=" << nomatch << " "
- << "noroot=" << noroot << " "
- << "false=" << false_result << "\n";
- */
- }
-
-int main()
- {
- Botan::LibraryInitializer init;
- AutoSeeded_RNG rng;
-
-#if 0
- std::cout << ressol(8, 17) << "\n";
- std::cout << ressol_orig(8, 17) << "\n";
-#endif
-
-#if 1
- for(int j = 16; j != 1024; ++j)
- {
- std::cout << "Round " << j << "\n";
- BigInt p = random_prime(rng, j);
- test_ressol(p, rng);
- //printf("%d\n", j);
-
-
- }
-#endif
- /*
- for(u32bit j = 9; j != PRIME_TABLE_SIZE; ++j)
- {
- std::cout << "PRIME[" << j << "] == " << PRIMES[j] << std::endl;
- //printf("%d - ", PRIMES[j]);
- test_ressol(PRIMES[j], rng);
- //printf("\n");
- }
- */
- }
diff --git a/doc/examples/rng_test.cpp b/doc/examples/rng_test.cpp
index 05f2c28a4..3d96b7a42 100644
--- a/doc/examples/rng_test.cpp
+++ b/doc/examples/rng_test.cpp
@@ -11,12 +11,12 @@
#include <iostream>
#include <fstream>
-#include <boost/algorithm/string.hpp>
+#include <deque>
#include <stdexcept>
using namespace Botan;
-std::vector<std::pair<std::string, std::string> > read_file(const std::string&);
+namespace {
SecureVector<byte> decode_hex(const std::string& in)
{
@@ -109,18 +109,6 @@ void x931_tests(std::vector<std::pair<std::string, std::string> > vecs,
}
-int main()
- {
- Botan::LibraryInitializer init;
-
- x931_tests(read_file("ANSI931_AES128VST.txt.vst"), "AES-128");
- x931_tests(read_file("ANSI931_AES192VST.txt.vst"), "AES-192");
- x931_tests(read_file("ANSI931_AES256VST.txt.vst"), "AES-256");
- x931_tests(read_file("ANSI931_TDES2VST.txt.vst"), "TripleDES");
- x931_tests(read_file("ANSI931_TDES3VST.txt.vst"), "TripleDES");
- }
-
-
std::vector<std::pair<std::string, std::string> >
read_file(const std::string& fsname)
{
@@ -136,8 +124,7 @@ read_file(const std::string& fsname)
if(line == "")
break;
- std::vector<std::string> l;
- boost::split(l, line, boost::is_any_of(":"));
+ std::vector<std::string> l = split_on(line, ':');
if(l.size() != 2)
throw std::runtime_error("Bad line " + line);
@@ -147,3 +134,16 @@ read_file(const std::string& fsname)
return out;
}
+
+}
+
+int main()
+ {
+ Botan::LibraryInitializer init;
+
+ x931_tests(read_file("ANSI931_AES128VST.txt.vst"), "AES-128");
+ x931_tests(read_file("ANSI931_AES192VST.txt.vst"), "AES-192");
+ x931_tests(read_file("ANSI931_AES256VST.txt.vst"), "AES-256");
+ x931_tests(read_file("ANSI931_TDES2VST.txt.vst"), "TripleDES");
+ x931_tests(read_file("ANSI931_TDES3VST.txt.vst"), "TripleDES");
+ }
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp
index 9e6b510f2..b60941eb2 100644
--- a/doc/examples/tls_client.cpp
+++ b/doc/examples/tls_client.cpp
@@ -38,7 +38,7 @@ int main()
byte buf[16+1] = { 0 };
u32bit got = tls.read(buf, sizeof(buf)-1);
- printf("%s", buf);
+ printf("Got %d bytes: %s", got, buf);
fflush(0);
}
}
diff --git a/doc/examples/x509info.cpp b/doc/examples/x509info.cpp
index 8f4d83c45..52cc4afbd 100644
--- a/doc/examples/x509info.cpp
+++ b/doc/examples/x509info.cpp
@@ -14,6 +14,8 @@ using namespace Botan;
#include <iterator>
#include <algorithm>
+namespace {
+
std::string to_hex(const SecureVector<byte>& bin)
{
Pipe pipe(new Hex_Encoder);
@@ -46,6 +48,8 @@ void do_issuer(const X509_Certificate& cert, const std::string& what)
do_print(what, cert.issuer_info(what));
}
+}
+
int main(int argc, char* argv[])
{
if(argc != 2)