blob: 74686a29841f2fa5ff128378543b293c4bcc7ec6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/*
* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include "tests.h"
#include <iostream>
#if defined(BOTAN_HAS_CRYPTO_BOX)
#include <botan/cryptobox.h>
#endif
using namespace Botan;
size_t test_cryptobox()
{
size_t fails = 0;
#if defined(BOTAN_HAS_CRYPTO_BOX)
auto& rng = test_rng();
const byte msg[] = { 0xAA, 0xBB, 0xCC };
std::string ciphertext = CryptoBox::encrypt(msg, sizeof(msg),
"secret password",
rng);
try
{
std::string plaintext = CryptoBox::decrypt(ciphertext,
"secret password");
if(plaintext.size() != sizeof(msg) ||
!same_mem(reinterpret_cast<const byte*>(&plaintext[0]), msg, sizeof(msg)))
++fails;
}
catch(std::exception& e)
{
std::cout << "Error during Cryptobox test " << e.what() << std::endl;
++fails;
}
test_report("Cryptobox", 1, fails);
#endif
return fails;
}
|