2018-01-14 17:17:34 +11:00
|
|
|
#include "block/tea.hpp"
|
|
|
|
|
|
|
|
#include <cruft/util/tap.hpp>
|
|
|
|
#include <cruft/util/types.hpp>
|
|
|
|
|
|
|
|
using cruft::crypto::block::TEA;
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
// test vectors from 'TeaCrypt', by Logan J. Drews.
|
|
|
|
static const struct {
|
|
|
|
std::array<uint32_t,4> key;
|
|
|
|
std::array<uint32_t,2> dec;
|
|
|
|
std::array<uint32_t,2> enc;
|
|
|
|
} TESTS[] = {
|
|
|
|
|
|
|
|
{
|
|
|
|
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
|
|
|
|
{ 0x00000000, 0x00000000 },
|
|
|
|
{ 0x41EA3A0A, 0x94BAA940 },
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
{ 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
|
|
|
|
{ 0x01020304, 0x05060708 },
|
|
|
|
{ 0x6A2F9CF3, 0xFCCF3C55 },
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
{ 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF },
|
|
|
|
{ 0x01020304, 0x05060708 },
|
|
|
|
{ 0xDEB1C0A2, 0x7E745DB3 },
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
{ 0x00112233, 0x44556677, 0x8899AABB, 0xCCDDEEFF },
|
|
|
|
{ 0x01234567, 0x89ABCDEF },
|
|
|
|
{ 0x126C6B92, 0xC0653A3E },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-08-05 14:51:17 +10:00
|
|
|
cruft::TAP::logger tap;
|
2018-01-14 17:17:34 +11:00
|
|
|
|
|
|
|
for (size_t i = 0; i < std::size (TESTS); ++i) {
|
|
|
|
const auto &t = TESTS[i];
|
|
|
|
TEA gen (t.key);
|
|
|
|
|
2018-12-02 14:20:16 +11:00
|
|
|
std::array<uint32_t,2> enc;
|
|
|
|
gen.encrypt (cruft::view (enc), cruft::view (t.dec));
|
2018-01-14 17:17:34 +11:00
|
|
|
|
2018-12-02 14:20:16 +11:00
|
|
|
std::array<uint32_t,2> dec;
|
|
|
|
gen.decrypt (cruft::view (dec), cruft::view (t.enc));
|
2018-01-14 17:17:34 +11:00
|
|
|
|
2022-03-23 07:41:55 +11:00
|
|
|
tap.expect (enc == t.enc, "TEA_enc {}", i);
|
|
|
|
tap.expect (dec == t.dec, "TEA_dec {}", i);
|
2018-01-14 17:17:34 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|