You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

// test unit for speck-64/128 and speck-128/256
// odzhan
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "speck.h"
// ******************************
// test vectors for SPECK-64/128
// 128-bit key
uint8_t key64[16]=
{ 0x00, 0x01, 0x02, 0x03,
0x08, 0x09, 0x0a, 0x0b,
0x10, 0x11, 0x12, 0x13,
0x18, 0x19, 0x1a, 0x1b };
// 64-bit plain text
uint8_t plain64[8]=
{ 0x74, 0x65, 0x72, 0x3b,
0x2d, 0x43, 0x75, 0x74 };
// 64-bit cipher text
uint8_t cipher64[8]=
{ 0x48, 0xa5, 0x6f, 0x8c,
0x8b, 0x02, 0x4e, 0x45 };
// ******************************
// test vectors for SPECK-128/128
// 128-bit key
uint8_t key128a[16] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
// 128-bit plain text
uint8_t plain128a[16] =
{ 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x69, 0x74,
0x20, 0x65, 0x71, 0x75, 0x69, 0x76, 0x61, 0x6c };
// 128-bit cipher text
uint8_t cipher128a[16] =
{ 0x18, 0x0d, 0x57, 0x5c, 0xdf, 0xfe, 0x60, 0x78,
0x65, 0x32, 0x78, 0x79, 0x51, 0x98, 0x5d, 0xa6 };
// ******************************
// test vectors for SPECK-128/256
// 256-bit key
uint8_t key128b[32]=
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
// 128-bit plain text
uint8_t plain128b[16]=
{ 0x70, 0x6f, 0x6f, 0x6e, 0x65, 0x72, 0x2e, 0x20,
0x49, 0x6e, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65 };
// 128-bit cipher text
uint8_t cipher128b[16]=
{ 0x43, 0x8f, 0x18, 0x9c, 0x8d, 0xb4, 0xee, 0x4e,
0x3e, 0xf5, 0xc0, 0x05, 0x04, 0x01, 0x09, 0x41 };
int main(void) {
uint8_t data[32];
int equ;
memcpy(data, plain64, 8);
speck64(key64, data);
equ = (memcmp(data, cipher64, 8)==0);
printf("SPECK-64/128 test : %s\n", equ ? "OK" : "FAILED");
memcpy(data, plain128a, 16);
speck128a(key128a, data);
equ = (memcmp(data, cipher128a, 16)==0);
printf("SPECK-128/128 test : %s\n", equ ? "OK" : "FAILED");
memcpy(data, plain128b, 16);
speck128b(key128b, data);
equ = (memcmp(data, cipher128b, 16)==0);
printf("SPECK-128/256 test : %s\n", equ ? "OK" : "FAILED");