aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_block.cpp13
-rw-r--r--src/tests/test_hash.cpp17
-rw-r--r--src/tests/test_hkdf.cpp11
-rw-r--r--src/tests/test_kdf.cpp1
-rw-r--r--src/tests/test_keywrap.cpp1
-rw-r--r--src/tests/test_mac.cpp14
-rw-r--r--src/tests/test_ocb.cpp30
-rw-r--r--src/tests/test_pbkdf.cpp1
-rw-r--r--src/tests/test_rng.cpp9
-rw-r--r--src/tests/test_stream.cpp15
-rw-r--r--src/tests/tests.cpp3
11 files changed, 46 insertions, 69 deletions
diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp
index eb4ea58bf..066f2201a 100644
--- a/src/tests/test_block.cpp
+++ b/src/tests/test_block.cpp
@@ -1,13 +1,13 @@
/*
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
-#include <botan/libstate.h>
#include <botan/block_cipher.h>
+#include <botan/lookup.h>
#include <botan/hex.h>
#include <iostream>
#include <fstream>
@@ -25,9 +25,7 @@ size_t block_test(const std::string& algo,
const secure_vector<byte> pt = hex_decode_locked(in_hex);
const secure_vector<byte> ct = hex_decode_locked(out_hex);
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- const auto providers = af.providers_of(algo);
+ const std::vector<std::string> providers = get_block_cipher_providers(algo);
size_t fails = 0;
if(providers.empty())
@@ -35,16 +33,15 @@ size_t block_test(const std::string& algo,
for(auto provider: providers)
{
- const BlockCipher* proto = af.prototype_block_cipher(algo, provider);
+ std::unique_ptr<BlockCipher> cipher(get_block_cipher(algo, provider));
- if(!proto)
+ if(!cipher)
{
std::cout << "Unable to get " << algo << " from " << provider << "\n";
++fails;
continue;
}
- std::unique_ptr<BlockCipher> cipher(proto->clone());
cipher->set_key(key);
secure_vector<byte> buf = pt;
diff --git a/src/tests/test_hash.cpp b/src/tests/test_hash.cpp
index fb8d54e1f..e301f2d4c 100644
--- a/src/tests/test_hash.cpp
+++ b/src/tests/test_hash.cpp
@@ -1,12 +1,12 @@
/*
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
-#include <botan/libstate.h>
+#include <botan/lookup.h>
#include <botan/hash.h>
#include <botan/hex.h>
#include <iostream>
@@ -20,22 +20,21 @@ size_t hash_test(const std::string& algo,
const std::string& in_hex,
const std::string& out_hex)
{
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- const auto providers = af.providers_of(algo);
size_t fails = 0;
+ const std::vector<std::string> providers = get_hash_function_providers(algo);
+
if(providers.empty())
{
- std::cout << "Unknown algo " << algo << "\n";
+ std::cout << "Unknown hash '" << algo << "'\n";
++fails;
}
for(auto provider: providers)
{
- auto proto = af.prototype_hash_function(algo, provider);
+ std::unique_ptr<HashFunction> hash(get_hash(algo, provider));
- if(!proto)
+ if(!hash)
{
std::cout << "Unable to get " << algo << " from " << provider << "\n";
++fails;
@@ -44,8 +43,6 @@ size_t hash_test(const std::string& algo,
const std::vector<byte> in = hex_decode(in_hex);
- std::unique_ptr<HashFunction> hash(proto->clone());
-
hash->update(in);
auto h = hash->final();
diff --git a/src/tests/test_hkdf.cpp b/src/tests/test_hkdf.cpp
index 74a4ce4c7..eff379831 100644
--- a/src/tests/test_hkdf.cpp
+++ b/src/tests/test_hkdf.cpp
@@ -10,8 +10,8 @@
#include <fstream>
#if defined(BOTAN_HAS_HKDF)
-#include <botan/libstate.h>
#include <botan/hkdf.h>
+#include <botan/lookup.h>
using namespace Botan;
@@ -23,16 +23,13 @@ secure_vector<byte> hkdf(const std::string& hkdf_algo,
const secure_vector<byte>& info,
size_t L)
{
- Algorithm_Factory& af = global_state().algorithm_factory();
-
const std::string algo = hkdf_algo.substr(5, hkdf_algo.size()-6);
- const MessageAuthenticationCode* mac_proto = af.prototype_mac("HMAC(" + algo + ")");
-
- if(!mac_proto)
+ MessageAuthenticationCode* mac = get_mac("HMAC(" + algo + ")");
+ if(!mac)
throw std::invalid_argument("Bad HKDF hash '" + algo + "'");
- HKDF hkdf(mac_proto->clone(), mac_proto->clone());
+ HKDF hkdf(mac->clone(), mac); // HKDF needs 2 MACs, identical here
hkdf.start_extract(&salt[0], salt.size());
hkdf.extract(&ikm[0], ikm.size());
diff --git a/src/tests/test_kdf.cpp b/src/tests/test_kdf.cpp
index b08da5c26..2ce8077ef 100644
--- a/src/tests/test_kdf.cpp
+++ b/src/tests/test_kdf.cpp
@@ -6,6 +6,7 @@
#include "tests.h"
+#include <botan/kdf.h>
#include <botan/lookup.h>
#include <botan/hex.h>
#include <iostream>
diff --git a/src/tests/test_keywrap.cpp b/src/tests/test_keywrap.cpp
index c07d023d7..ffe9b52bb 100644
--- a/src/tests/test_keywrap.cpp
+++ b/src/tests/test_keywrap.cpp
@@ -6,7 +6,6 @@
#include "tests.h"
-#include <botan/libstate.h>
#include <botan/hex.h>
#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp
index 8be57afbe..302f39625 100644
--- a/src/tests/test_mac.cpp
+++ b/src/tests/test_mac.cpp
@@ -1,12 +1,12 @@
/*
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
-#include <botan/libstate.h>
+#include <botan/lookup.h>
#include <botan/mac.h>
#include <botan/hex.h>
#include <iostream>
@@ -21,9 +21,7 @@ size_t mac_test(const std::string& algo,
const std::string& in_hex,
const std::string& out_hex)
{
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- const auto providers = af.providers_of(algo);
+ const std::vector<std::string> providers = get_mac_providers(algo);
size_t fails = 0;
if(providers.empty())
@@ -34,17 +32,15 @@ size_t mac_test(const std::string& algo,
for(auto provider: providers)
{
- auto proto = af.prototype_mac(algo, provider);
+ std::unique_ptr<MessageAuthenticationCode> mac(get_mac(algo, provider));
- if(!proto)
+ if(!mac)
{
std::cout << "Unable to get " << algo << " from " << provider << "\n";
++fails;
continue;
}
- std::unique_ptr<MessageAuthenticationCode> mac(proto->clone());
-
const std::vector<byte> in = hex_decode(in_hex);
const std::vector<byte> exp = hex_decode(out_hex);
diff --git a/src/tests/test_ocb.cpp b/src/tests/test_ocb.cpp
index 0e31941cb..95f91ab50 100644
--- a/src/tests/test_ocb.cpp
+++ b/src/tests/test_ocb.cpp
@@ -13,7 +13,7 @@
#include <botan/sha2_32.h>
#include <botan/aes.h>
#include <botan/loadstor.h>
-#include <botan/libstate.h>
+#include <botan/lookup.h>
using namespace Botan;
@@ -53,17 +53,16 @@ std::vector<byte> ocb_encrypt(OCB_Encryption& enc,
return unlock(buf);
}
-size_t test_ocb_long(Algorithm_Factory& af,
- size_t keylen, size_t taglen,
+size_t test_ocb_long(size_t keylen, size_t taglen,
const std::string &expected)
{
// Test from RFC 7253 Appendix A
const std::string algo = "AES-" + std::to_string(keylen);
- OCB_Encryption enc(af.make_block_cipher(algo), taglen / 8);
+ OCB_Encryption enc(get_block_cipher(algo), taglen / 8);
- OCB_Decryption dec(af.make_block_cipher(algo), taglen / 8);
+ OCB_Decryption dec(get_block_cipher(algo), taglen / 8);
std::vector<byte> key(keylen/8);
key[keylen/8-1] = taglen;
@@ -110,17 +109,16 @@ size_t test_ocb()
size_t fails = 0;
#if defined(BOTAN_HAS_AEAD_OCB)
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- fails += test_ocb_long(af, 128, 128, "67E944D23256C5E0B6C61FA22FDF1EA2");
- fails += test_ocb_long(af, 192, 128, "F673F2C3E7174AAE7BAE986CA9F29E17");
- fails += test_ocb_long(af, 256, 128, "D90EB8E9C977C88B79DD793D7FFA161C");
- fails += test_ocb_long(af, 128, 96, "77A3D8E73589158D25D01209");
- fails += test_ocb_long(af, 192, 96, "05D56EAD2752C86BE6932C5E");
- fails += test_ocb_long(af, 256, 96, "5458359AC23B0CBA9E6330DD");
- fails += test_ocb_long(af, 128, 64, "192C9B7BD90BA06A");
- fails += test_ocb_long(af, 192, 64, "0066BC6E0EF34E24");
- fails += test_ocb_long(af, 256, 64, "7D4EA5D445501CBE");
+
+ fails += test_ocb_long(128, 128, "67E944D23256C5E0B6C61FA22FDF1EA2");
+ fails += test_ocb_long(192, 128, "F673F2C3E7174AAE7BAE986CA9F29E17");
+ fails += test_ocb_long(256, 128, "D90EB8E9C977C88B79DD793D7FFA161C");
+ fails += test_ocb_long(128, 96, "77A3D8E73589158D25D01209");
+ fails += test_ocb_long(192, 96, "05D56EAD2752C86BE6932C5E");
+ fails += test_ocb_long(256, 96, "5458359AC23B0CBA9E6330DD");
+ fails += test_ocb_long(128, 64, "192C9B7BD90BA06A");
+ fails += test_ocb_long(192, 64, "0066BC6E0EF34E24");
+ fails += test_ocb_long(256, 64, "7D4EA5D445501CBE");
test_report("OCB long", 9, fails);
#endif
diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp
index bf9741e21..39340e8a7 100644
--- a/src/tests/test_pbkdf.cpp
+++ b/src/tests/test_pbkdf.cpp
@@ -6,6 +6,7 @@
#include "tests.h"
+#include <botan/pbkdf.h>
#include <botan/lookup.h>
#include <botan/hex.h>
#include <iostream>
diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp
index 48c1fe863..1f8edf332 100644
--- a/src/tests/test_rng.cpp
+++ b/src/tests/test_rng.cpp
@@ -7,8 +7,8 @@
#include "test_rng.h"
#include "tests.h"
-#include <botan/libstate.h>
#include <botan/hex.h>
+#include <botan/lookup.h>
#include <iostream>
#include <fstream>
@@ -41,21 +41,18 @@ RandomNumberGenerator* get_rng(const std::string& algo_str, const std::string& i
const auto ikm = hex_decode(ikm_hex);
- Algorithm_Factory& af = global_state().algorithm_factory();
-
const auto algo_name = parse_algorithm_name(algo_str);
const std::string rng_name = algo_name[0];
#if defined(BOTAN_HAS_HMAC_DRBG)
if(rng_name == "HMAC_DRBG")
- return new HMAC_DRBG(af.make_mac("HMAC(" + algo_name[1] + ")"),
- new AllOnce_RNG(ikm));
+ return new HMAC_DRBG(get_mac("HMAC(" + algo_name[1] + ")"), new AllOnce_RNG(ikm));
#endif
#if defined(BOTAN_HAS_X931_RNG)
if(rng_name == "X9.31-RNG")
- return new ANSI_X931_RNG(af.make_block_cipher(algo_name[1]),
+ return new ANSI_X931_RNG(get_block_cipher(algo_name[1]),
new Fixed_Output_RNG(ikm));
#endif
diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp
index 3144e9f47..af782d219 100644
--- a/src/tests/test_stream.cpp
+++ b/src/tests/test_stream.cpp
@@ -6,8 +6,8 @@
#include "tests.h"
-#include <botan/libstate.h>
#include <botan/stream_cipher.h>
+#include <botan/lookup.h>
#include <botan/hex.h>
#include <iostream>
#include <fstream>
@@ -27,29 +27,26 @@ size_t stream_test(const std::string& algo,
const secure_vector<byte> ct = hex_decode_locked(out_hex);
const secure_vector<byte> nonce = hex_decode_locked(nonce_hex);
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- const auto providers = af.providers_of(algo);
+ const std::vector<std::string> providers = get_stream_cipher_providers(algo);
size_t fails = 0;
if(providers.empty())
{
- std::cout << "Unknown algo " << algo << "\n";
+ std::cout << "Unknown stream cipher " << algo << "\n";
++fails;
}
for(auto provider: providers)
{
- const StreamCipher* proto = af.prototype_stream_cipher(algo, provider);
+ std::unique_ptr<StreamCipher> cipher(get_stream_cipher(algo, provider));
- if(!proto)
+ if(!cipher)
{
- std::cout << "Unable to get " << algo << " from provider '" << provider << "'\n";
+ std::cout << "Unable to get " << algo << " from " << provider << "\n";
++fails;
continue;
}
- std::unique_ptr<StreamCipher> cipher(proto->clone());
cipher->set_key(key);
if(nonce.size())
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 88ff4171d..931287464 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -5,7 +5,6 @@
*/
#include "tests.h"
-#include <botan/init.h>
#include <iostream>
#include <fstream>
#include <botan/auto_rng.h>
@@ -301,7 +300,5 @@ int main(int argc, char* argv[])
return 1;
}
- Botan::LibraryInitializer init;
-
return run_tests(tests);
}