From 51528ecf3d90d09351322e172d91eed0cb45b2e7 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 8 Nov 2020 20:34:13 +0200 Subject: Add more test vectors --- test_set_keys.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test_set_keys.cpp (limited to 'test_set_keys.cpp') diff --git a/test_set_keys.cpp b/test_set_keys.cpp new file mode 100644 index 0000000..e963930 --- /dev/null +++ b/test_set_keys.cpp @@ -0,0 +1,42 @@ +#include "blowfish.hpp" +#include "vectors.h" +#include + +template constexpr void printKey() { + for (int i = 0; i < sz; ++i) { + printf("%02x ", set_key[i]); + } + printf("\n"); +} + +template struct set_key_wrapper { + constexpr void operator()() const { + + if constexpr (i < 3) { + printf("skip - minimal key length is 32bits (4bytes): current key " + "length: %i bytes\n", + i + 1); + } else { + constexpr auto s = std::span(set_key, i + 1); + + constexpr Blowfish::Context b(s); + constexpr Blowfish::Block x(set_key_ptext); + + constexpr auto y = b.encrypt(x); + static_assert(static_cast(y) == set_key_ctext[i]); + printf("0x%016lx\t", static_cast(y)); + + constexpr auto z = b.decrypt(y); + static_assert(static_cast(z) == set_key_ptext); + printf("0x%016lx\t", static_cast(z)); + + printKey(); + } + } +}; + +void run_set_key_wrapper() { + printf("%-18s\t%-18s\t%-18s\n", "/ encrypt", "/ decrypt", "/ key"); + call_times(); + printf("%-18s\t0x%016lx\n", "cleartext", set_key_ptext); +} -- cgit v1.2.1