diff options
-rw-r--r-- | doc/examples/toolbox.cpp | 235 | ||||
-rw-r--r-- | doc/examples/tss.cpp | 44 | ||||
-rw-r--r-- | src/tests/test_tss.cpp | 61 | ||||
-rw-r--r-- | src/tests/tests.cpp | 1 | ||||
-rw-r--r-- | src/tests/tests.h | 8 |
5 files changed, 65 insertions, 284 deletions
diff --git a/doc/examples/toolbox.cpp b/doc/examples/toolbox.cpp deleted file mode 100644 index 24afa2cbe..000000000 --- a/doc/examples/toolbox.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/* -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/botan.h> - -#if defined(BOTAN_HAS_COMPRESSOR_BZIP2) - #include <botan/bzip2.h> -#endif - -#if defined(BOTAN_HAS_COMPRESSOR_ZLIB) - #include <botan/zlib.h> -#endif - -#include <iostream> -#include <fstream> - -using namespace Botan; - -#include "../../tests/getopt.h" - -class Encoder_Decoder - { - public: - Encoder_Decoder(const std::string& command, - bool decode, - const std::vector<std::string>& args) : - type(command), - args(args), - decode(decode) - { } - - void run(std::istream& in, std::ostream& out) - { - Filter* filt = decode ? decoder(type) : encoder(type); - - DataSource_Stream src(in); - Pipe pipe(filt, new DataSink_Stream(out)); - pipe.process_msg(src); - } - - Filter* encoder(const std::string& type) const - { - if(type == "hex") return new Hex_Encoder; - if(type == "base64") return new Base64_Encoder; - -#if defined(BOTAN_HAS_COMPRESSOR_BZIP2) - if(type == "bzip2") return new Bzip_Compression; -#endif - -#if defined(BOTAN_HAS_COMPRESSOR_ZLIB) - if(type == "zlib") return new Zlib_Compression; -#endif - return 0; - } - - Filter* decoder(const std::string& type) const - { - if(type == "hex") return new Hex_Decoder; - if(type == "base64") return new Base64_Decoder; - -#if defined(BOTAN_HAS_COMPRESSOR_BZIP2) - if(type == "bzip2") return new Bzip_Decompression; -#endif - -#if defined(BOTAN_HAS_COMPRESSOR_ZLIB) - if(type == "zlib") return new Zlib_Decompression; -#endif - - return 0; - } - - private: - std::string type; - std::vector<std::string> args; - bool decode; - }; - -void run_command(const std::string& command, - const std::vector<std::string>& arguments, - const OptionParser& opts) - { - if(command == "hex" || - command == "base64" || - command == "bzip2" || - command == "zlib") - { - bool decode = opts.is_set("decode"); - - std::string output = opts.value_or_else("output", "-"); - std::string input = opts.value_or_else("input", "-"); - - Encoder_Decoder enc_dec(command, decode, arguments); - - try - { - if(output == "-") - { - if(input == "-") - enc_dec.run(std::cin, std::cout); - else - { - std::ifstream in(input.c_str()); - enc_dec.run(in, std::cout); - } - } - else // output != "-" - { - std::ofstream out(output.c_str()); - - if(input == "-") - enc_dec.run(std::cin, out); - else - { - std::ifstream in(input.c_str()); - enc_dec.run(in, out); - } - } - } - catch(Botan::Stream_IO_Error& e) - { - std::cout << "I/O failure - " << e.what() << '\n'; - } - } - else if(command == "hash" || - command == "sha1" || - command == "md5") - { - std::string hash; - - if(command == "md5") - hash = "MD5"; - if(command == "sha1") - hash = "SHA-160"; - else - hash = opts.value_or_else("hash", "SHA-160"); // sha1 is default - - Pipe pipe(new Hash_Filter(get_hash(hash)), - new Hex_Encoder(false, 0, Hex_Encoder::Lowercase)); - - for(size_t i = 0; i != arguments.size(); ++i) - { - std::string file_name = arguments[i]; - - u32bit previously = pipe.message_count(); - - if(file_name == "-") - { - pipe.start_msg(); - std::cin >> pipe; - pipe.end_msg(); - } - else - { - std::ifstream in(file_name.c_str()); - if(in) - { - pipe.start_msg(); - in >> pipe; - pipe.end_msg(); - } - else - std::cerr << "Could not read " << file_name << '\n'; - } - - if(pipe.message_count() > previously) - std::cout << pipe.read_all_as_string(Pipe::LAST_MESSAGE) << " " - << file_name << '\n'; - } - - } - else - { - std::cerr << "Command " << command << " not known\n"; - } - } - -int main(int argc, char* argv[]) - { - LibraryInitializer init; - - OptionParser opts("help|version|seconds=|" - "input=|output=|decode|" - "hash=|key="); - - try - { - opts.parse(argv); - } - catch(std::runtime_error& e) - { - std::cout << "Command line problem: " << e.what() << '\n'; - return 2; - } - - if(opts.is_set("version") || argc <= 1) - { - std::cerr << "Botan Toolbox v" << version_string() << '\n'; - std::cerr << "Commands: hash hex base64 "; -#if defined(BOTAN_HAS_COMPRESSOR_BZIP2) - std::cerr << "bzip2 "; -#endif - -#if defined(BOTAN_HAS_COMPRESSOR_ZLIB) - std::cerr << "zlib "; -#endif - - std::cerr << "\n"; - - return 0; - } - - if(opts.is_set("help")) - { - std::vector<std::string> what = opts.leftovers(); - - for(size_t i = 0; i != what.size(); ++i) - std::cerr << what[i] << "? Never heard of it\n"; - return 0; - } - - std::vector<std::string> args = opts.leftovers(); - - if(args.size() == 0) - return 0; - - std::string command = args[0]; - args.erase(args.begin()); - - run_command(command, args, opts); - - return 0; - } diff --git a/doc/examples/tss.cpp b/doc/examples/tss.cpp deleted file mode 100644 index aecf95796..000000000 --- a/doc/examples/tss.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/botan.h> -#include <botan/tss.h> -#include <iostream> -#include <stdio.h> - -namespace { - -void print(const Botan::secure_vector<Botan::byte>& r) - { - for(Botan::u32bit i = 0; i != r.size(); ++i) - printf("%02X", r[i]); - printf("\n"); - } - -} - -int main() - { - using namespace Botan; - - LibraryInitializer init; - - AutoSeeded_RNG rng; - - byte id[16]; - for(int i = 0; i != 16; ++i) - id[i] = i; - - const byte S2[] = { 0xDE, 0xAD, 0xCA, 0xFE, 0xBA, 0xBE, 0xBE, 0xEF }; - - std::vector<RTSS_Share> shares = - RTSS_Share::split(4, 6, S2, sizeof(S2), id, rng); - - for(size_t i = 0; i != shares.size(); ++i) - std::cout << i << " = " << shares[i].to_string() << "\n"; - - print(RTSS_Share::reconstruct(shares)); - } diff --git a/src/tests/test_tss.cpp b/src/tests/test_tss.cpp new file mode 100644 index 000000000..f9caddb6f --- /dev/null +++ b/src/tests/test_tss.cpp @@ -0,0 +1,61 @@ +/* +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include "tests.h" +#include <botan/auto_rng.h> +#include <botan/hex.h> +#include <botan/tss.h> +#include <iostream> +#include <stdio.h> + +namespace { + +void print(const Botan::secure_vector<Botan::byte>& r) + { + for(Botan::u32bit i = 0; i != r.size(); ++i) + printf("%02X", r[i]); + printf("\n"); + } + +} + +size_t test_tss() + { + using namespace Botan; + + AutoSeeded_RNG rng; + + size_t fails = 0; + + byte id[16]; + for(int i = 0; i != 16; ++i) + id[i] = i; + + const secure_vector<byte> S = hex_decode_locked("7465737400"); + + std::vector<RTSS_Share> shares = + RTSS_Share::split(2, 4, &S[0], S.size(), id, rng); + + auto back = RTSS_Share::reconstruct(shares); + + if(S != back) + { + std::cout << "TSS-0: " << hex_encode(S) << " != " << hex_encode(back) << "\n"; + ++fails; + } + + shares.resize(shares.size()-1); + + back = RTSS_Share::reconstruct(shares); + + if(S != back) + { + std::cout << "TSS-1: " << hex_encode(S) << " != " << hex_encode(back) << "\n"; + ++fails; + } + + return fails; + } diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 49f55c165..622894803 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -174,6 +174,7 @@ size_t run_all_tests() all_tests.push_back(test_passhash9); all_tests.push_back(test_bcrypt); all_tests.push_back(test_cryptobox); + all_tests.push_back(test_tss); all_tests.push_back(test_bigint); all_tests.push_back(test_pubkey); diff --git a/src/tests/tests.h b/src/tests/tests.h index cb1e0f585..dff493f5f 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -39,11 +39,8 @@ size_t test_block(); size_t test_stream(); size_t test_hash(); size_t test_mac(); - size_t test_modes(); - size_t test_rngs(); - size_t test_hkdf(); size_t test_pbkdf(); size_t test_kdf(); @@ -57,14 +54,14 @@ size_t test_keywrap(); size_t test_bcrypt(); size_t test_passhash9(); size_t test_cryptobox(); +size_t test_tss(); +// File driven tests size_t test_bigint(); - size_t test_pubkey(); size_t test_pk_keygen(); size_t test_ecc(); - size_t test_ecdsa(); size_t test_ecdh(); @@ -72,6 +69,7 @@ size_t test_x509(); size_t test_cvc(); size_t test_tls(); + size_t test_nist_x509(); #endif |