diff --git a/test/specktest.c b/test/specktest.c index 947426fc..0f914ab0 100644 --- a/test/specktest.c +++ b/test/specktest.c @@ -64,25 +64,36 @@ int main(int argc, char **argv) #include -int main(int argc, char **argv) +int main(int argc, char** argv) { - speck_key_t key; - unsigned char userkey[2] = { 0x01, 0x02, }; - unsigned char msg[2] = { 0xab, 0xcd, }; - SPECK_TYPE S[SPECK_ROUNDS]; - - unsigned char cbuf[2]; - unsigned char mbuf[2]; + int sum = 0; +#ifdef SPECK_32_64 + uint16_t key[4] = { 0x0100, 0x0908, 0x1110, 0x1918 }; + uint16_t plain[2] = { 0x694c, 0x6574 }; + uint16_t enc[2] = { 0x42f2, 0xa868 }; +#endif - speck_set_encrypt_key(&key, userkey); - speck_expand(&key, S); - speck_encrypt(msg, cbuf, S); - speck_decrypt(cbuf, mbuf, S); +#ifdef SPECK_64_128 + uint32_t key[4] = { 0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918 }; + uint32_t plain[2] = { 0x7475432d, 0x3b726574 }; + uint32_t enc[2] = { 0x454e028b, 0x8c6fa548 }; +#endif - if (memcmp(msg, mbuf, 2)) { - return -1; +#ifdef SPECK_128_256 + uint64_t key[4] = { 0x0706050403020100, 0x0f0e0d0c0b0a0908, 0x1716151413121110, 0x1f1e1d1c1b1a1918 }; + uint64_t plain[2] = { 0x202e72656e6f6f70, 0x65736f6874206e49 }; + uint64_t enc[2] = { 0x4eeeb48d9c188f43, 0x4109010405c0f53e }; +#endif + SPECK_TYPE buffer[2] = { 0 }; + SPECK_TYPE exp[SPECK_ROUNDS]; + speck_set_encrypt_key(key, exp); + speck_encrypt(plain, buffer, exp); + speck_decrypt(enc, buffer, exp); + if (memcmp(buffer, plain, sizeof(enc))) + { + sum++; } - - return 0; + + return sum; } #endif