diff options
Diffstat (limited to 'test_set_keys.cpp')
-rw-r--r-- | test_set_keys.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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 <cstdio> + +template <int sz> constexpr void printKey() { + for (int i = 0; i < sz; ++i) { + printf("%02x ", set_key[i]); + } + printf("\n"); +} + +template <int i> 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<i + 1> b(s); + constexpr Blowfish::Block x(set_key_ptext); + + constexpr auto y = b.encrypt(x); + static_assert(static_cast<uint64_t>(y) == set_key_ctext[i]); + printf("0x%016lx\t", static_cast<uint64_t>(y)); + + constexpr auto z = b.decrypt(y); + static_assert(static_cast<uint64_t>(z) == set_key_ptext); + printf("0x%016lx\t", static_cast<uint64_t>(z)); + + printKey<i + 1>(); + } + } +}; + +void run_set_key_wrapper() { + printf("%-18s\t%-18s\t%-18s\n", "/ encrypt", "/ decrypt", "/ key"); + call_times<set_key_wrapper, NUM_SET_KEY_TESTS>(); + printf("%-18s\t0x%016lx\n", "cleartext", set_key_ptext); +} |