aboutsummaryrefslogtreecommitdiffstats
path: root/checks/validate.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-12-31 14:14:22 +0000
committerlloyd <[email protected]>2013-12-31 14:14:22 +0000
commitabefc88850c37fe97b4a8588aa13fcdefd9f7b5e (patch)
tree5beb26d3e1770a56aeeddafb5157a413f8b3605d /checks/validate.cpp
parentd291e3e82513e046abfdf4b38d38a55483f789fd (diff)
Tests
Diffstat (limited to 'checks/validate.cpp')
-rw-r--r--checks/validate.cpp252
1 files changed, 14 insertions, 238 deletions
diff --git a/checks/validate.cpp b/checks/validate.cpp
index 866f414eb..cb15325ef 100644
--- a/checks/validate.cpp
+++ b/checks/validate.cpp
@@ -19,21 +19,7 @@
#include <botan/selftest.h>
#include <botan/libstate.h>
-#if defined(BOTAN_HAS_PASSHASH9)
- #include <botan/passhash9.h>
-#endif
-
-#if defined(BOTAN_HAS_BCRYPT)
- #include <botan/bcrypt.h>
-#endif
-
-#if defined(BOTAN_HAS_CRYPTO_BOX)
- #include <botan/cryptobox.h>
-#endif
-
-#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
- #include <botan/rfc3394.h>
-#endif
+#include "tests.h"
using namespace Botan;
@@ -66,201 +52,6 @@ u32bit random_word(Botan::RandomNumberGenerator& rng,
#endif
}
-bool test_cryptobox(RandomNumberGenerator& rng)
- {
-#if defined(BOTAN_HAS_CRYPTO_BOX)
-
- std::cout << "Testing CryptoBox: " << std::flush;
-
- const byte msg[] = { 0xAA, 0xBB, 0xCC };
- std::string ciphertext = CryptoBox::encrypt(msg, sizeof(msg),
- "secret password",
- rng);
-
- std::cout << "." << std::flush;
-
- try
- {
- std::string plaintext = CryptoBox::decrypt(ciphertext,
- "secret password");
-
- std::cout << "." << std::flush;
-
- if(plaintext.size() != sizeof(msg) ||
- !same_mem(reinterpret_cast<const byte*>(&plaintext[0]), msg, sizeof(msg)))
- return false;
-
- std::cout << std::endl;
- }
- catch(std::exception& e)
- {
- std::cout << "Error during Cryptobox test " << e.what() << "\n";
- return false;
- }
-#endif
-
- return true;
- }
-
-bool keywrap_test(const char* key_str,
- const char* expected_str,
- const char* kek_str)
- {
- std::cout << '.' << std::flush;
-
- bool ok = true;
-
-#if defined(BOTAN_HAS_RFC3394_KEYWRAP)
- try
- {
- SymmetricKey key(key_str);
- SymmetricKey expected(expected_str);
- SymmetricKey kek(kek_str);
-
- Algorithm_Factory& af = global_state().algorithm_factory();
-
- secure_vector<byte> enc = rfc3394_keywrap(key.bits_of(), kek, af);
-
- if(enc != expected.bits_of())
- {
- std::cout << "NIST key wrap encryption failure: "
- << hex_encode(enc) << " != " << hex_encode(expected.bits_of()) << "\n";
- ok = false;
- }
-
- secure_vector<byte> dec = rfc3394_keyunwrap(expected.bits_of(), kek, af);
-
- if(dec != key.bits_of())
- {
- std::cout << "NIST key wrap decryption failure: "
- << hex_encode(dec) << " != " << hex_encode(key.bits_of()) << "\n";
- ok = false;
- }
- }
- catch(std::exception& e)
- {
- std::cout << e.what() << "\n";
- }
-#endif
-
- return ok;
- }
-
-bool test_keywrap()
- {
- std::cout << "Testing NIST keywrap: " << std::flush;
-
- bool ok = true;
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF",
- "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5",
- "000102030405060708090A0B0C0D0E0F");
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF",
- "96778B25AE6CA435F92B5B97C050AED2468AB8A17AD84E5D",
- "000102030405060708090A0B0C0D0E0F1011121314151617");
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF",
- "64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7",
- "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF0001020304050607",
- "031D33264E15D33268F24EC260743EDCE1C6C7DDEE725A936BA814915C6762D2",
- "000102030405060708090A0B0C0D0E0F1011121314151617");
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF0001020304050607",
- "A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254DA1",
- "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
-
- ok &= keywrap_test("00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F",
- "28C9F404C4B810F4CBCCB35CFB87F8263F5786E2D80ED326CBC7F0E71A99F43BFB988B9B7A02DD21",
- "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
-
- std::cout << "\n";
- return ok;
- }
-
-bool test_bcrypt(RandomNumberGenerator& rng)
- {
-#if defined(BOTAN_HAS_BCRYPT)
- std::cout << "Testing Bcrypt: " << std::flush;
-
- bool ok = true;
-
- // Generated by jBCrypt 0.3
- if(!check_bcrypt("abc",
- "$2a$05$DfPyLs.G6.To9fXEFgUL1O6HpYw3jIXgPcl/L3Qt3jESuWmhxtmpS"))
- {
- std::cout << "Fixed bcrypt test failed\n";
- ok = false;
- }
-
- std::cout << "." << std::flush;
-
- // http://www.openwall.com/lists/john-dev/2011/06/19/2
- if(!check_bcrypt("\xA3",
- "$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq"))
- {
- std::cout << "Fixed bcrypt test 2 failed\n";
- ok = false;
- }
-
- std::cout << "." << std::flush;
-
- for(u16bit level = 1; level != 5; ++level)
- {
- const std::string input = "some test passphrase 123";
- const std::string gen_hash = generate_bcrypt(input, rng, level);
-
- if(!check_bcrypt(input, gen_hash))
- {
- std::cout << "Gen and check for bcrypt failed: "
- << gen_hash << " not valid\n";
- ok = false;
- }
-
- std::cout << "." << std::flush;
- }
-
- std::cout << std::endl;
- return ok;
-#endif
- }
-
-bool test_passhash(RandomNumberGenerator& rng)
- {
-#if defined(BOTAN_HAS_PASSHASH9)
-
- std::cout << "Testing Password Hashing: " << std::flush;
-
- const std::string input = "secret";
- const std::string fixed_hash =
- "$9$AAAKhiHXTIUhNhbegwBXJvk03XXJdzFMy+i3GFMIBYKtthTTmXZA";
-
- std::cout << "." << std::flush;
-
- if(!check_passhash9(input, fixed_hash))
- return false;
-
- std::cout << "." << std::flush;
-
- for(byte alg_id = 0; alg_id <= 2; ++alg_id)
- {
- std::string gen_hash = generate_passhash9(input, rng, 2, alg_id);
-
- if(!check_passhash9(input, gen_hash))
- return false;
-
- std::cout << "." << std::flush;
- }
-
- std::cout << std::endl;
-
-#endif
-
- return true;
- }
-
}
bool failed_test(const std::string&, std::vector<std::string>, bool, bool,
@@ -392,38 +183,23 @@ u32bit do_validation_tests(const std::string& filename,
if(should_pass)
std::cout << std::endl;
- if(should_pass && !test_passhash(rng))
+ if(should_pass)
{
- std::cout << "Passhash9 tests failed" << std::endl;
- errors++;
- }
+ std::vector<test_fn> all_tests;
+ all_tests.push_back(test_aead);
+ all_tests.push_back(test_ocb);
- if(should_pass && !test_bcrypt(rng))
- {
- std::cout << "BCrypt tests failed" << std::endl;
- errors++;
- }
+ all_tests.push_back(test_pbkdf);
+ all_tests.push_back(test_kdf);
+ all_tests.push_back(test_hkdf);
+ all_tests.push_back(test_keywrap);
+ all_tests.push_back(test_transform);
- if(should_pass && !test_keywrap())
- {
- std::cout << "NIST keywrap tests failed" << std::endl;
- errors++;
- }
-
- if(should_pass && !test_cryptobox(rng))
- {
- std::cout << "Cryptobox tests failed" << std::endl;
- errors++;
- }
+ all_tests.push_back(test_passhash9);
+ all_tests.push_back(test_bcrypt);
+ all_tests.push_back(test_cryptobox);
- if(should_pass)
- {
- test_transform();
- test_ocb();
- test_hkdf();
- test_pbkdf();
- test_kdf();
- test_aead();
+ run_tests(all_tests);
}
return errors;