diff options
author | Jack Lloyd <[email protected]> | 2016-12-31 13:10:47 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-31 13:10:47 -0500 |
commit | 656db0a3509706a5a8abc0ce96cf460d82792828 (patch) | |
tree | ea39258f1b8d52f80961225ec8b0bbb24084501b /src | |
parent | 2f9d7b71d3fb99bf63271246537da2c8dd472314 (diff) |
Add a simple test of the all or nothing transform
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/misc/aont/package.h | 4 | ||||
-rw-r--r-- | src/tests/test_package_transform.cpp | 56 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/lib/misc/aont/package.h b/src/lib/misc/aont/package.h index 48d4b44e0..d090e0725 100644 --- a/src/lib/misc/aont/package.h +++ b/src/lib/misc/aont/package.h @@ -16,7 +16,7 @@ namespace Botan { /** * Rivest's Package Tranform * @param rng the random number generator to use -* @param cipher the block cipher to use +* @param cipher the block cipher to use (aont_package takes ownership) * @param input the input data buffer * @param input_len the length of the input data in bytes * @param output the output data buffer (must be at least @@ -29,7 +29,7 @@ void BOTAN_DLL aont_package(RandomNumberGenerator& rng, /** * Rivest's Package Tranform (Inversion) -* @param cipher the block cipher to use +* @param cipher the block cipher to use (aont_package takes ownership) * @param input the input data buffer * @param input_len the length of the input data in bytes * @param output the output data buffer (must be at least 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); + + +} |