From 93df4df5d3c96e3f225158eeef0e675e43dde1fc Mon Sep 17 00:00:00 2001 From: bg Date: Sun, 13 Apr 2008 12:58:26 +0000 Subject: [PATCH] updated some testsuits --- des.mk | 3 +- main-des-test.c | 234 ------------------------------------- main-tdes-test.c | 245 --------------------------------------- obsolete/main-rc6-test.c | 177 ++++++++++++++++++++++++++++ tdes.mk | 7 +- uart.c | 2 +- uart.h | 2 +- 7 files changed, 185 insertions(+), 485 deletions(-) delete mode 100644 main-des-test.c delete mode 100644 main-tdes-test.c create mode 100644 obsolete/main-rc6-test.c diff --git a/des.mk b/des.mk index f78040b..2cc8d7c 100644 --- a/des.mk +++ b/des.mk @@ -5,7 +5,8 @@ ALGO_NAME := DES BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := des.o -$(ALGO_NAME)_TEST_BIN := main-des-test.o debug.o uart.o serial-tools.o des.o +$(ALGO_NAME)_TEST_BIN := main-des-test.o debug.o uart.o serial-tools.o des.o \ + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/main-des-test.c b/main-des-test.c deleted file mode 100644 index 22dee88..0000000 --- a/main-des-test.c +++ /dev/null @@ -1,234 +0,0 @@ -/** - * \file main-des-test.c - * \author Daniel Otte - * \date 2007-06-17 - * \brief test suit for DES - * \par License - * GPL - * - */ -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "des.h" - -#include -#include - - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void testencrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,8); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); - des_encrypt(block,block,key); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); -} - -void testdecrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,8); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); - des_decrypt(block,block,key); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); -} - -/******************************************************************************/ - -void testrun_des(void){ - -/* uint8_t key[]= { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */ -/* uint8_t data[]={ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */ - - - uint8_t key[] = { 0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e }; - uint8_t data[]= { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; - testencrypt(data,key); - testdecrypt(data,key); -} - -/******************************************************************************/ - -void nessie_testenc(uint8_t* data, uint8_t* key){ - uint16_t i; - uart_putstr("\r\n\t key = \t"); uart_hexdump(key, 8); - uart_putstr("\r\n\t plain = \t"); uart_hexdump(data, 8); - des_encrypt(data,data,key); - uart_putstr("\r\n\t cipher = \t"); uart_hexdump(data, 8); - des_decrypt(data,data,key); - uart_putstr("\r\n\t decrypted = \t"); uart_hexdump(data, 8); - - for(i=0;i<100; ++i) - des_encrypt(data,data,key); - uart_putstr("\r\n\tIterated 100 times = \t"); uart_hexdump(data, 8); - for(;i<1000; ++i) - des_encrypt(data,data,key); - uart_putstr("\r\n\tIterated 1000 times = \t"); uart_hexdump(data, 8); - -} - -/******************************************************************************/ -/* -Set 8, vector# 0: - key=0001020304050607 - cipher=0011223344556677 - plain=41AD068548809D02 - encrypted=0011223344556677 -*/ -void nessie_testdec(uint8_t* data, uint8_t* key){ - uart_putstr("\r\n\t key = \t"); uart_hexdump(key, 8); - uart_putstr("\r\n\t cipher = \t"); uart_hexdump(data, 8); - des_decrypt(data,data,key); - uart_putstr("\r\n\t plain = \t"); uart_hexdump(data, 8); - des_encrypt(data,data,key); - uart_putstr("\r\n\t encrypted = \t"); uart_hexdump(data, 8); -} - -/******************************************************************************/ - -void nessie_testrun(void){ - /* - Set 1, vector# 0: - key=8000000000000000 - plain=0000000000000000 - cipher=95A8D72813DAA94D - decrypted=0000000000000000 - Iterated 100 times=F749E1F8DEFAF605 - Iterated 1000 times=F396DD0B33D04244 - */ - uint8_t key[8]; - uint8_t data[8]; - uint16_t set=1, vector; - /* set 1 */ - for(vector=0;vector<64;++vector){ - memset(key, 0, 8); - memset(data, 0, 8); - key[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testenc(data, key); - } - /* set 2 */ - set = 2; - for(vector=0;vector<64;++vector){ - memset(key, 0, 8); - memset(data, 0, 8); - data[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testenc(data, key); - } - /* set 3 */ - set = 3; - for(vector=0;vector<256;++vector){ - memset(key, vector, 8); - memset(data, vector, 8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testenc(data, key); - } - /* set 4 */ - set = 4; - { uint8_t lk[2][8] = { /* local keys */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, - { 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00 } }; - uint8_t ld[2][8] = { /* local data */ - { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, - { 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 } }; - - for(vector=0;vector<2;++vector){ - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testenc(ld[vector], lk[vector]); - } - } - /* set 5 */ - set = 5; - for(vector=0;vector<64;++vector){ - memset(key, 0, 8); - memset(data, 0, 8); - key[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testdec(data, key); - } - /* set 6 */ - set = 6; - for(vector=0;vector<64;++vector){ - memset(key, 0, 8); - memset(data, 0, 8); - data[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testdec(data, key); - } - /* set 7 */ - set = 7; - for(vector=0;vector<256;++vector){ - memset(key, vector, 8); - memset(data, vector, 8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testdec(data, key); - } - /* set 8 */ - set = 8; - { uint8_t lk[2][8] = { /* local keys */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, - { 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00 } }; - uint8_t ld[2][8] = { /* local data */ - { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, - { 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 } }; - - for(vector=0;vector<2;++vector){ - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testdec(ld[vector], lk[vector]); - } - } - -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr("\r\n\r\nCrypto-VS (DES; "); - uart_putstr(__DATE__);uart_putstr(", ");uart_putstr(__TIME__); - uart_putstr(")\r\nloaded and running\r\n"); - -restart: - while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (!strcmp(str, "test")) { testrun_des(); } - else if (!strcmp(str, "nessie")) { nessie_testrun();} - else {DEBUG_S("DBG: 1b\r\n"); goto error;} - - goto restart; - continue; - error: - uart_putstr("ERROR\r\n"); - } - - -} - diff --git a/main-tdes-test.c b/main-tdes-test.c deleted file mode 100644 index fbb88d6..0000000 --- a/main-tdes-test.c +++ /dev/null @@ -1,245 +0,0 @@ -/** - * \file main-tdes-test.c - * \author Daniel Otte - * \date 2007-06-17 - * \brief test suit for TDES/TDEA - * \par License - * GPL - * - */ -#include "config.h" -#include "serial-tools.h" -#include "uart.h" -#include "debug.h" - -#include "des.h" - -#include -#include - - -/***************************************************************************** - * additional validation-functions * - *****************************************************************************/ - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void testencrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,8); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); - tdes_encrypt(block,block,key); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); -} - -void testdecrypt(uint8_t* block, uint8_t* key){ - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,8); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,8); - tdes_decrypt(block,block,key); - uart_putstr("\r\n plain: "); - uart_hexdump(block,8); -} - -/******************************************************************************/ - -void testrun_des(void){ - -/* uint8_t key[]= { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */ -/* uint8_t data[]={ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; */ - - - uint8_t key[] = { 0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, - 0x92, 0x2f, 0xb5, 0x10, 0xc7, 0x1f, 0x43, 0x6e, - 0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e - }; - uint8_t data[]= { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; - testencrypt(data,key); - testdecrypt(data,key); -} - -/******************************************************************************/ - -void nessie_testenc(uint8_t* data, uint8_t* key){ - uint16_t i; - uart_putstr("\r\n\t key = \t"); uart_hexdump(key, 24); - uart_putstr("\r\n\t plain = \t"); uart_hexdump(data, 8); - tdes_encrypt(data,data,key); - uart_putstr("\r\n\t cipher = \t"); uart_hexdump(data, 8); - tdes_decrypt(data,data,key); - uart_putstr("\r\n\t decrypted = \t"); uart_hexdump(data, 8); - - for(i=0;i<100; ++i) - tdes_encrypt(data,data,key); - uart_putstr("\r\n\tIterated 100 times = \t"); uart_hexdump(data, 8); - for(;i<1000; ++i) - tdes_encrypt(data,data,key); - uart_putstr("\r\n\tIterated 1000 times = \t"); uart_hexdump(data, 8); - -} - -/******************************************************************************/ -/* -Set 8, vector# 0: - key=0001020304050607 - cipher=0011223344556677 - plain=41AD068548809D02 - encrypted=0011223344556677 -*/ -void nessie_testdec(uint8_t* data, uint8_t* key){ - uart_putstr("\r\n\t key = \t"); uart_hexdump(key, 24); - uart_putstr("\r\n\t cipher = \t"); uart_hexdump(data, 8); - tdes_decrypt(data,data,key); - uart_putstr("\r\n\t plain = \t"); uart_hexdump(data, 8); - tdes_encrypt(data,data,key); - uart_putstr("\r\n\t encrypted = \t"); uart_hexdump(data, 8); -} - -/******************************************************************************/ - -void nessie_testrun(void){ - /* - Set 1, vector# 0: - key=8000000000000000 - plain=0000000000000000 - cipher=95A8D72813DAA94D - decrypted=0000000000000000 - Iterated 100 times=F749E1F8DEFAF605 - Iterated 1000 times=F396DD0B33D04244 - */ - uint8_t key[24]; - uint8_t data[8]; - uint16_t set=1, vector; - /* set 1 */ - for(vector=0;vector<192;++vector){ - memset(key, 0, 24); - memset(data, 0, 8); - key[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testenc(data, key); - } - /* set 2 */ - set = 2; - for(vector=0;vector<64;++vector){ - memset(key, 0, 24); - memset(data, 0, 8); - data[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testenc(data, key); - } - /* set 3 */ - set = 3; - for(vector=0;vector<256;++vector){ - memset(key, vector, 24); - memset(data, vector, 8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testenc(data, key); - } - /* set 4 */ - set = 4; - { uint8_t lk[2][24] = { /* local keys */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, - { 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00, - 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48, - 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00 } }; - uint8_t ld[2][8] = { /* local data */ - { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, - { 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 } }; - - for(vector=0;vector<2;++vector){ - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testenc(ld[vector], lk[vector]); - } - } - /* set 5 */ - set = 5; - for(vector=0;vector<192;++vector){ - memset(key, 0, 24); - memset(data, 0, 8); - key[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testdec(data, key); - } - /* set 6 */ - set = 6; - for(vector=0;vector<64;++vector){ - memset(key, 0, 24); - memset(data, 0, 8); - data[vector/8] = 1<<(7-vector%8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 1); - nessie_testdec(data, key); - } - /* set 7 */ - set = 7; - for(vector=0;vector<256;++vector){ - memset(key, vector, 24); - memset(data, vector, 8); - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testdec(data, key); - } - /* set 8 */ - set = 8; - { uint8_t lk[2][24] = { - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, - { 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00, - 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48, - 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00 } }; - uint8_t ld[2][8] = { /* local data */ - { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, - { 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 } }; - - for(vector=0;vector<2;++vector){ - uart_putstr("\r\n Set "); uart_hexdump(&set, 1); - uart_putstr(", vector# "); uart_hexdump(&vector, 2); - nessie_testdec(ld[vector], lk[vector]); - } - } - -} - -/***************************************************************************** - * main * - *****************************************************************************/ - -int main (void){ - char str[20]; - - DEBUG_INIT(); - uart_putstr("\r\n"); - - uart_putstr("\r\n\r\nCrypto-VS (TDES/TDEA; "); - uart_putstr(__DATE__);uart_putstr(", ");uart_putstr(__TIME__); - uart_putstr(")\r\nloaded and running\r\n"); - -restart: - while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (!strcmp(str, "test")) { testrun_des(); } - else if (!strcmp(str, "nessie")) { nessie_testrun();} - else {DEBUG_S("DBG: 1b\r\n"); goto error;} - - goto restart; - continue; - error: - uart_putstr("ERROR\r\n"); - } - - -} - diff --git a/obsolete/main-rc6-test.c b/obsolete/main-rc6-test.c new file mode 100644 index 0000000..0c886d1 --- /dev/null +++ b/obsolete/main-rc6-test.c @@ -0,0 +1,177 @@ +/* + * rc6 test-suit + * +*/ + +#include "config.h" +#include "serial-tools.h" +#include "uart.h" +#include "debug.h" + +#include "rc6.h" + +#include +#include +#include + + +#ifndef BOOL +#define BOOL + #ifndef __BOOL + #define __BOOL + #ifndef __BOOL__ + #define __BOOL__ + typedef enum{false=0,true=1} bool; + #endif + #endif +#endif + + + +/***************************************************************************** + * additional validation-functions * + *****************************************************************************/ + +/***************************************************************************** + * self tests * + *****************************************************************************/ + +void test_encrypt(uint8_t *block, uint8_t *key, uint16_t keylength, bool print){ + rc6_ctx_t s; + if (print){ + uart_putstr("\r\nRC6 (enc):\r\n key:\t"); + uart_hexdump(key, keylength/8); + uart_putstr("\r\n plaintext:\t"); + uart_hexdump(block, 16); + } + if (rc6_init(&s, key, keylength)){ + uart_putstr("RC6 init failed!"); + return; + } + rc6_enc(&s, block); + if (print){ + uart_putstr("\r\n ciphertext:\t"); + uart_hexdump(block, 16); + } + rc6_free(&s); +} + +void test_decrypt(uint8_t *block, uint8_t *key, uint16_t keylength, bool print){ + rc6_ctx_t s; + if (print){ + uart_putstr("\r\nRC6 (dec):\r\n key:\t"); + uart_hexdump(key, keylength/8); + uart_putstr("\r\n ciphertext:\t"); + uart_hexdump(block, 16); + } + if (rc6_init(&s, key, keylength)){ + uart_putstr("RC6 init failed!"); + return; + } + rc6_dec(&s, block); + if (print){ + uart_putstr("\r\n plaintext:\t"); + uart_hexdump(block, 16); + } + rc6_free(&s); +} + +/* + * Test vectors for encryption with RC6 + plaintext 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + user key 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + ciphertext 8f c3 a5 36 56 b1 f7 78 c1 29 df 4e 98 48 a4 1e + + plaintext 02 13 24 35 46 57 68 79 8a 9b ac bd ce df e0 f1 + user key 01 23 45 67 89 ab cd ef 01 12 23 34 45 56 67 78 + ciphertext 52 4e 19 2f 47 15 c6 23 1f 51 f6 36 7e a4 3f 18 + + plaintext 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + user key 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 + ciphertext 6c d6 1b cb 19 0b 30 38 4e 8a 3f 16 86 90 ae 82 + + plaintext 02 13 24 35 46 57 68 79 8a 9b ac bd ce df e0 f1 + user key 01 23 45 67 89 ab cd ef 01 12 23 34 45 56 67 78 + 89 9a ab bc cd de ef f0 + ciphertext 68 83 29 d0 19 e5 05 04 1e 52 e9 2a f9 52 91 d4 + + plaintext 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + user key 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + ciphertext 8f 5f bd 05 10 d1 5f a8 93 fa 3f da 6e 85 7e c2 + + plaintext 02 13 24 35 46 57 68 79 8a 9b ac bd ce df e0 f1 + user key 01 23 45 67 89 ab cd ef 01 12 23 34 45 56 67 78 + 89 9a ab bc cd de ef f0 10 32 54 76 98 ba dc fe + ciphertext c8 24 18 16 f0 d7 e4 89 20 ad 16 a1 67 4e 5d 48 + * + */ + + uint8_t PROGMEM testkey[6][256/8]={ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, + 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, + 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe}}; + uint8_t PROGMEM testplain[2][128/8]={ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x02, 0x13, 0x24, 0x35, 0x46, 0x57, 0x68, 0x79, 0x8a, 0x9b, 0xac, 0xbd, 0xce, 0xdf, 0xe0, 0xf1}}; + uint8_t PROGMEM testcipher[6][128/8]={ + {0x8f, 0xc3, 0xa5, 0x36, 0x56, 0xb1, 0xf7, 0x78, 0xc1, 0x29, 0xdf, 0x4e, 0x98, 0x48, 0xa4, 0x1e}, + {0x52, 0x4e, 0x19, 0x2f, 0x47, 0x15, 0xc6, 0x23, 0x1f, 0x51, 0xf6, 0x36, 0x7e, 0xa4, 0x3f, 0x18}, + {0x6c, 0xd6, 0x1b, 0xcb, 0x19, 0x0b, 0x30, 0x38, 0x4e, 0x8a, 0x3f, 0x16, 0x86, 0x90, 0xae, 0x82}, + {0x68, 0x83, 0x29, 0xd0, 0x19, 0xe5, 0x05, 0x04, 0x1e, 0x52, 0xe9, 0x2a, 0xf9, 0x52, 0x91, 0xd4}, + {0x8f, 0x5f, 0xbd, 0x05, 0x10, 0xd1, 0x5f, 0xa8, 0x93, 0xfa, 0x3f, 0xda, 0x6e, 0x85, 0x7e, 0xc2}, + {0xc8, 0x24, 0x18, 0x16, 0xf0, 0xd7, 0xe4, 0x89, 0x20, 0xad, 0x16, 0xa1, 0x67, 0x4e, 0x5d, 0x48}}; + + +void testrun_rc6(void){ + uint16_t keysize[]={128, 128, 192, 192, 256, 256}; + uint8_t i; + uint8_t block[16]; + uint8_t key[32]; + memset(block, 0, 16); + memset(key, 0, 16); + + test_encrypt(block, key, 128, true); + for(i=0; i<6; ++i){ + memcpy_P(block, testplain[i&1], 128/8); + memcpy_P(key, testkey[i], keysize[i]/8); + test_encrypt(block, key, keysize[i], true); + memcpy_P(key, testkey[i], keysize[i]/8); + test_decrypt(block, key, keysize[i], true); + } +} + + + +/***************************************************************************** + * main * + *****************************************************************************/ + +int main (void){ + char str[20]; + + + DEBUG_INIT(); + uart_putstr("\r\n"); + + uart_putstr("\r\n\r\nCrypto-VS (RC6)\r\nloaded and running\r\n"); +restart: + while(1){ + if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} + if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} + testrun_rc6(); + goto restart; + continue; + error: + uart_putstr("ERROR\r\n"); + } /* while (1) */ +} + diff --git a/tdes.mk b/tdes.mk index 9ef9e97..66b5168 100644 --- a/tdes.mk +++ b/tdes.mk @@ -1,11 +1,12 @@ -# Makefile for triple-DES +# Makefile for DES ALGO_NAME := TDES -# comment out the following line for removement of triple-DES from the build process +# comment out the following line for removement of DES from the build process BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := des.o -$(ALGO_NAME)_TEST_BIN := main-tdes-test.o debug.o uart.o serial-tools.o des.o +$(ALGO_NAME)_TEST_BIN := main-tdes-test.o debug.o uart.o serial-tools.o des.o \ + nessie_bc_test.o nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/uart.c b/uart.c index 94de47e..5867254 100644 --- a/uart.c +++ b/uart.c @@ -235,7 +235,7 @@ void uart_putstr_P(PGM_P str) { } } -void uart_hexdump(void* buf, int len) +void uart_hexdump(const void* buf, int len) { unsigned char table[]={'0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f'}; diff --git a/uart.h b/uart.h index a72b167..e0d467f 100644 --- a/uart.h +++ b/uart.h @@ -24,7 +24,7 @@ void uart_init(void); void uart_putc(char c); void uart_putstr(char * str); void uart_putstr_P(PGM_P str); -void uart_hexdump(void* buf, int len); +void uart_hexdump(const void* buf, int len); char uart_getc(void); char uart_getc_nb(char *c); /* returns 1 on success */ -- 2.39.5