diff options
Diffstat (limited to 'checks/validate.cpp')
-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; } |