diff options
-rw-r--r-- | src/tests/data/fpe_fe1.vec | 14 | ||||
-rw-r--r-- | src/tests/test_fpe.cpp | 45 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/tests/data/fpe_fe1.vec b/src/tests/data/fpe_fe1.vec new file mode 100644 index 000000000..4108a56a2 --- /dev/null +++ b/src/tests/data/fpe_fe1.vec @@ -0,0 +1,14 @@ + +# FE1 outputs generated by botan + +Mod = 100000 +In = 666 +Out = 48166 +Key = AABB +Tweak = CCDD + +Mod = 100000 +In = 48166 +Out = 69575 +Key = AABB +Tweak = CCDD diff --git a/src/tests/test_fpe.cpp b/src/tests/test_fpe.cpp new file mode 100644 index 000000000..38c4f9a1c --- /dev/null +++ b/src/tests/test_fpe.cpp @@ -0,0 +1,45 @@ +/* +* (C) 2016 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "tests.h" + +#if defined(BOTAN_HAS_FPE_FE1) + #include <botan/fpe_fe1.h> +#endif + +namespace Botan_Tests { + +class FPE_FE1_Tests : public Text_Based_Test + { + public: + FPE_FE1_Tests() : Text_Based_Test("fpe_fe1.vec", {"Mod", "In", "Out", "Key", "Tweak"}) {} + + Test::Result run_one_test(const std::string& algo, const VarMap& vars) override + { + const Botan::BigInt modulus = get_req_bn(vars, "Mod"); + const Botan::BigInt input = get_req_bn(vars, "In"); + const Botan::BigInt expected = get_req_bn(vars, "Out"); + const std::vector<uint8_t> key = get_req_bin(vars, "Key"); + const std::vector<uint8_t> tweak = get_req_bin(vars, "Tweak"); + + Test::Result result("FPE_FE1"); + + const Botan::BigInt got = Botan::FPE::fe1_encrypt(modulus, input, key, tweak); + + result.test_eq("ciphertext", got, expected); + + const Botan::BigInt decry = Botan::FPE::fe1_decrypt(modulus, got, key, tweak); + + result.test_eq("decrypted", decry, input); + + return result; + } + + }; + +BOTAN_REGISTER_TEST("fpe_fe1", FPE_FE1_Tests); + +} |