aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_package_transform.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-12-31 13:10:47 -0500
committerJack Lloyd <[email protected]>2016-12-31 13:10:47 -0500
commit656db0a3509706a5a8abc0ce96cf460d82792828 (patch)
treeea39258f1b8d52f80961225ec8b0bbb24084501b /src/tests/test_package_transform.cpp
parent2f9d7b71d3fb99bf63271246537da2c8dd472314 (diff)
Add a simple test of the all or nothing transform
Diffstat (limited to 'src/tests/test_package_transform.cpp')
-rw-r--r--src/tests/test_package_transform.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/test_package_transform.cpp b/src/tests/test_package_transform.cpp
new file mode 100644
index 000000000..fb3ee3d00
--- /dev/null
+++ b/src/tests/test_package_transform.cpp
@@ -0,0 +1,56 @@
+/*
+* (C) 2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+#include <botan/package.h>
+
+namespace Botan_Tests {
+
+class Package_Transform_Tests : public Test
+ {
+ public:
+ std::vector<Test::Result> run() override
+ {
+ Test::Result result("Package transform");
+
+ std::unique_ptr<Botan::BlockCipher> cipher(Botan::BlockCipher::create("AES-128"));
+ std::vector<uint8_t> input = unlock(Test::rng().random_vec(Test::rng().next_byte()));
+ std::vector<uint8_t> output(input.size() + cipher->block_size());
+
+ // aont_package owns/deletes the passed cipher object, kind of a bogus API
+ Botan::aont_package(Test::rng(),
+ cipher->clone(),
+ input.data(), input.size(),
+ output.data());
+
+ std::vector<uint8_t> decoded(output.size() - cipher->block_size());
+ Botan::aont_unpackage(cipher->clone(),
+ output.data(), output.size(),
+ decoded.data());
+ result.test_eq("Package transform is reversible", decoded, input);
+
+ output[0] ^= 1;
+ Botan::aont_unpackage(cipher->clone(),
+ output.data(), output.size(),
+ decoded.data());
+ result.test_ne("Bitflip breaks package transform", decoded, input);
+
+ output[0] ^= 1;
+ Botan::aont_unpackage(cipher->clone(),
+ output.data(), output.size(),
+ decoded.data());
+ result.test_eq("Package transform is still reversible", decoded, input);
+
+ // More tests including KATs would be useful for these functions
+
+ return std::vector<Test::Result>{result};
+ }
+ };
+
+BOTAN_REGISTER_TEST("package_transform", Package_Transform_Tests);
+
+
+}