#include #include #include #include #include #include "threefish512.h" static uint64_t three_512_00_key[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L }; static uint64_t three_512_00_input[] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L }; static uint64_t three_512_00_tweak[] = { 0L, 0L }; static uint64_t three_512_00_result[] = { 0xBC2560EFC6BBA2B1L, 0xE3361F162238EB40L, 0xFB8631EE0ABBD175L, 0x7B9479D4C5479ED1L, 0xCFF0356E58F8C27BL, 0xB1B7B08430F0E7F7L, 0xE9A380A56139ABF1L, 0xBE7B6D4AA11EB47EL }; static uint64_t three_512_01_key[] = { 0x1716151413121110L, 0x1F1E1D1C1B1A1918L, 0x2726252423222120L, 0x2F2E2D2C2B2A2928L, 0x3736353433323130L, 0x3F3E3D3C3B3A3938L, 0x4746454443424140L, 0x4F4E4D4C4B4A4948L }; static uint64_t three_512_01_input[] = { 0xF8F9FAFBFCFDFEFFL, 0xF0F1F2F3F4F5F6F7L, 0xE8E9EAEBECEDEEEFL, 0xE0E1E2E3E4E5E6E7L, 0xD8D9DADBDCDDDEDFL, 0xD0D1D2D3D4D5D6D7L, 0xC8C9CACBCCCDCECFL, 0xC0C1C2C3C4C5C6C7L }; static uint64_t three_512_01_tweak[] = { 0x0706050403020100L, 0x0F0E0D0C0B0A0908L }; static uint64_t three_512_01_result[] = { 0xD4A32EDD6ABEFA1CL, 0x6AD5C4252C3FF743L, 0x35AC875BE2DED68CL, 0x99A6C774EA5CD06CL, 0xDCEC9C4251D7F4F8L, 0xF5761BCB3EF592AFL, 0xFCABCB6A3212DF60L, 0xFD6EDE9FF9A2E14EL }; static const char INDENT[] = " "; static void Show08(size_t cnt, const uint8_t* b) { size_t i; for (i=0;i < cnt;i++) { if (i %16 == 0) printf(INDENT); else if (i % 4 == 0) printf(" "); printf(" %02X",b[i]); if (i %16 == 15 || i==cnt-1) printf("\n"); fflush(stdout); } } /* * ATTENTION: the following tests work for little endian CPU, not tested for * big endian :-) */ static int basicTest512() { int i; ThreefishKey512_t keyCtx; #define Threefish512 (512) uint64_t cipher[Threefish512/64]; uint64_t plain[Threefish512/64]; /* setup and check first vector */ threefishSetKey512(&keyCtx, three_512_00_key, three_512_00_tweak); /* Encrypt */ threefishEncrypt512(&keyCtx, three_512_00_input, cipher); if (memcmp(cipher, three_512_00_result, Threefish512/8) != 0) { printf("Wrong cipher text 512 00\n"); Show08(Threefish512/8, (const uint8_t*)cipher); return 0; } /* Decrypt */ threefishDecrypt512(&keyCtx, cipher, plain); if (memcmp(plain, three_512_00_input, Threefish512/8) != 0) { printf("Decrypt failed 512 00\n"); Show08(Threefish512/8, (const uint8_t*)plain); return 0; } /* setup and check second vector */ threefishSetKey512(&keyCtx, three_512_01_key, three_512_01_tweak); /* Encrypt */ threefishEncrypt512(&keyCtx, three_512_01_input, cipher); /* plaintext feed forward */ for (i = 0; i < Threefish512/64; i++) cipher[i] ^= three_512_01_input[i]; if (memcmp(cipher, three_512_01_result, Threefish512/8) != 0) { printf("Wrong cipher text 512 01\n"); Show08(Threefish512/8, (const uint8_t*)cipher); return 0; } /* Decrypt */ /* plaintext feed backward :-) */ for (i = 0; i < Threefish512/64; i++) cipher[i] ^= three_512_01_input[i]; threefishDecrypt512(&keyCtx, cipher, plain); if (memcmp(plain, three_512_01_input, Threefish512/8) != 0) { printf("Decrypt failed 512 01\n"); Show08(Threefish512/8, (const uint8_t*)plain); return 0; } return 1; } int main(int argc, char* argv[]) { if (!basicTest512()) return 1; return 0; }