diff options
author | lloyd <[email protected]> | 2010-09-07 22:53:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-07 22:53:52 +0000 |
commit | 3c43fb5878bcf585dd32b1a74ae4dd733a89ac05 (patch) | |
tree | 331fe3bd8f818048b7a32979be16cd9c4881c5ea | |
parent | 8427d5367b400ea3fa934bc7e7cb2e42fa45efce (diff) |
Add a basic test for cryptobox
-rw-r--r-- | checks/validate.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/checks/validate.cpp b/checks/validate.cpp index e1d5117a5..9f6bc44ce 100644 --- a/checks/validate.cpp +++ b/checks/validate.cpp @@ -23,6 +23,10 @@ #include <botan/passhash9.h> #endif +#if defined(BOTAN_HAS_CRYPTO_BOX) + #include <botan/cryptobox.h> +#endif + using namespace Botan; #include "validate.h" @@ -54,6 +58,42 @@ 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 test_passhash(RandomNumberGenerator& rng) { #if defined(BOTAN_HAS_PASSHASH9) @@ -225,6 +265,12 @@ u32bit do_validation_tests(const std::string& filename, errors++; } + if(should_pass && !test_cryptobox(rng)) + { + std::cout << "Cryptobox tests failed" << std::endl; + errors++; + } + return errors; } |