nessie for the rest (skipjack seems broken, shabea req. more testing)
This commit is contained in:
parent
33c19d7ea9
commit
91bece1f78
|
@ -12,7 +12,7 @@ ERASECMD =
|
||||||
|
|
||||||
CC = avr-gcc
|
CC = avr-gcc
|
||||||
|
|
||||||
override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.c,%.d,$^) -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
|
override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.c,%.d,$<) -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
|
||||||
|
|
||||||
override LDFLAGS = -Wl,-Map,
|
override LDFLAGS = -Wl,-Map,
|
||||||
override ASFLAGS = -mmcu=$(MCU_TARGET)
|
override ASFLAGS = -mmcu=$(MCU_TARGET)
|
||||||
|
|
|
@ -27,14 +27,42 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
#include "nessie_hash_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
|
char* algo_name = "MD5";
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void md5_next_dummy(void* buffer, void* ctx){
|
||||||
|
md5_nextBlock(ctx, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void md5_last_dummy(void* buffer, uint16_t size_b, void* ctx){
|
||||||
|
md5_lastBlock(ctx, buffer, size_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void md5_ctx2hash_dummy(void* buffer, void* ctx){
|
||||||
|
memcpy(buffer, ctx, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_nessie_md5(void){
|
||||||
|
nessie_hash_ctx.hashsize_b = 128;
|
||||||
|
nessie_hash_ctx.blocksize_B = 512/8;
|
||||||
|
nessie_hash_ctx.ctx_size_B = sizeof(md5_ctx_t);
|
||||||
|
nessie_hash_ctx.name = algo_name;
|
||||||
|
nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)md5_init;
|
||||||
|
nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)md5_next_dummy;
|
||||||
|
nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)md5_last_dummy;
|
||||||
|
nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)md5_ctx2hash_dummy;
|
||||||
|
|
||||||
|
nessie_hash_run();
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
|
@ -85,15 +113,17 @@ int main (void){
|
||||||
uart_putstr("\r\n");
|
uart_putstr("\r\n");
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
|
uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
|
||||||
restart:
|
PGM_P u = PSTR("nessie\0test\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_md5, testrun_md5};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_md5();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
} /* while (1) */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
103
main-seed-test.c
103
main-seed-test.c
|
@ -32,14 +32,82 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "seed.h"
|
#include "seed.h"
|
||||||
|
#include "nessie_bc_test.h"
|
||||||
|
#include "cli.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <util/delay.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char* cipher_name = "Seed";
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void seed_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||||
|
seed_init(key, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testrun_nessie_seed(void){
|
||||||
|
nessie_bc_ctx.blocksize_B = 16;
|
||||||
|
nessie_bc_ctx.keysize_b = 128;
|
||||||
|
nessie_bc_ctx.name = cipher_name;
|
||||||
|
nessie_bc_ctx.ctx_size_B = sizeof(seed_ctx_t);
|
||||||
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)seed_encrypt;
|
||||||
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_decrypt;
|
||||||
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)seed_genctx_dummy;
|
||||||
|
|
||||||
|
nessie_bc_run();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_performance_seed(void){
|
||||||
|
uint16_t i,c;
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t key[16], data[16];
|
||||||
|
seed_ctx_t ctx;
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
getOverhead(&c, &i);
|
||||||
|
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
||||||
|
utoa(c, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
utoa(i, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
memset(key, 0, 16);
|
||||||
|
memset(data, 0, 16);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
seed_init(key, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
seed_encrypt(data, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
seed_decrypt(data, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
|
@ -49,30 +117,24 @@ void testencrypt(uint8_t* block, uint8_t* key){
|
||||||
seed_ctx_t ctx;
|
seed_ctx_t ctx;
|
||||||
uart_putstr("\r\n==testy-encrypt==\r\n key: ");
|
uart_putstr("\r\n==testy-encrypt==\r\n key: ");
|
||||||
uart_hexdump(key,16);
|
uart_hexdump(key,16);
|
||||||
seed_init(&ctx, key);
|
seed_init(key, &ctx);
|
||||||
uart_putstr("\r\n plain: ");
|
uart_putstr("\r\n plain: ");
|
||||||
uart_hexdump(block,16);
|
uart_hexdump(block,16);
|
||||||
_delay_ms(50);
|
seed_encrypt(block, &ctx);
|
||||||
seed_encrypt(&ctx, block);
|
|
||||||
uart_putstr("\r\n crypt: ");
|
uart_putstr("\r\n crypt: ");
|
||||||
uart_hexdump(block,16);
|
uart_hexdump(block,16);
|
||||||
// uart_putstr("\r\n post-state: ");
|
|
||||||
// uart_hexdump(ctx.k,16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testdecrypt(uint8_t* block, uint8_t* key){
|
void testdecrypt(uint8_t* block, uint8_t* key){
|
||||||
seed_ctx_t ctx;
|
seed_ctx_t ctx;
|
||||||
uart_putstr("\r\n==testy-decrypt==\r\n key: ");
|
uart_putstr("\r\n==testy-decrypt==\r\n key: ");
|
||||||
uart_hexdump(key,16);
|
uart_hexdump(key,16);
|
||||||
seed_init(&ctx, key);
|
seed_init(key, &ctx);
|
||||||
uart_putstr("\r\n crypt: ");
|
uart_putstr("\r\n crypt: ");
|
||||||
uart_hexdump(block,16);
|
uart_hexdump(block,16);
|
||||||
_delay_ms(50);
|
seed_decrypt(block, &ctx);
|
||||||
seed_decrypt(&ctx, block);
|
|
||||||
uart_putstr("\r\n plain: ");
|
uart_putstr("\r\n plain: ");
|
||||||
uart_hexdump(block,16);
|
uart_hexdump(block,16);
|
||||||
// uart_putstr("\r\n post-state: ");
|
|
||||||
// uart_hexdump(ctx.k,16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_seed(void){
|
void testrun_seed(void){
|
||||||
|
@ -101,7 +163,6 @@ void testrun_seed(void){
|
||||||
testencrypt(datas[i],keys[i]);
|
testencrypt(datas[i],keys[i]);
|
||||||
testdecrypt(datas[i],keys[i]);
|
testdecrypt(datas[i],keys[i]);
|
||||||
}
|
}
|
||||||
// testdecrypt(data,key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,21 +175,23 @@ int main (void){
|
||||||
char str[20];
|
char str[20];
|
||||||
|
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
uart_putstr("\r\n");
|
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (seed)\r\nloaded and running\r\n");
|
uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
|
uart_putstr(cipher_name);
|
||||||
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_seed, testrun_seed, testrun_performance_seed};
|
||||||
|
|
||||||
restart:
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_seed();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,14 +27,37 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
|
#include "nessie_hash_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
|
char* algo_name = "SHA-1";
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void sha1_next_dummy(void* buffer, void* ctx){
|
||||||
|
sha1_nextBlock(ctx, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sha1_last_dummy(void* buffer, uint16_t size_b, void* ctx){
|
||||||
|
sha1_lastBlock(ctx, buffer, size_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testrun_nessie_sha1(void){
|
||||||
|
nessie_hash_ctx.hashsize_b = 160;
|
||||||
|
nessie_hash_ctx.blocksize_B = 512/8;
|
||||||
|
nessie_hash_ctx.ctx_size_B = sizeof(sha1_ctx_t);
|
||||||
|
nessie_hash_ctx.name = algo_name;
|
||||||
|
nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha1_init;
|
||||||
|
nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha1_next_dummy;
|
||||||
|
nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha1_last_dummy;
|
||||||
|
nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha1_ctx2hash;
|
||||||
|
|
||||||
|
nessie_hash_run();
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
|
@ -93,17 +116,18 @@ int main (void){
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
|
uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
|
||||||
|
|
||||||
restart:
|
PGM_P u = PSTR("nessie\0test\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_sha1, testrun_sha1};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_sha1();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
char* algo_name = "SHA-256";
|
char* algo_name = "SHA-256";
|
||||||
|
|
||||||
|
@ -73,16 +74,17 @@ int main (void){
|
||||||
uart_putstr(algo_name);
|
uart_putstr(algo_name);
|
||||||
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
restart:
|
PGM_P u = PSTR("nessie\0test\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "nessie")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_nessie_sha256();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,81 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "shabea.h"
|
#include "shabea.h"
|
||||||
|
#include "nessie_bc_test.h"
|
||||||
|
#include "cli.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <util/delay.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
char* cipher_name = "Shabea";
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void shabea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||||
|
memcpy(ctx, key, keysize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shabea_enc_dummy(void* buffer, void* ctx){
|
||||||
|
shabea256(buffer, ctx, 256, 1, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shabea_dec_dummy(void* buffer, void* ctx){
|
||||||
|
shabea256(buffer, ctx, 256, 0, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_nessie_shabea(void){
|
||||||
|
nessie_bc_ctx.blocksize_B = 32;
|
||||||
|
nessie_bc_ctx.keysize_b = 256;
|
||||||
|
nessie_bc_ctx.name = cipher_name;
|
||||||
|
nessie_bc_ctx.ctx_size_B = 32;
|
||||||
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)shabea_enc_dummy;
|
||||||
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)shabea_dec_dummy;
|
||||||
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)shabea_genctx_dummy;
|
||||||
|
|
||||||
|
nessie_bc_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_performance_shabea(void){
|
||||||
|
uint16_t i,c;
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t key[32], data[32];
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
getOverhead(&c, &i);
|
||||||
|
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
||||||
|
utoa(c, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
utoa(i, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
memset(key, 0, 32);
|
||||||
|
memset(data, 0, 32);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
shabea256(data, key, 256, 1, 16);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
shabea256(data, key, 256, 0, 16);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
|
@ -49,7 +116,6 @@ void testencrypt(uint8_t* block, uint8_t* key){
|
||||||
uart_hexdump(key,16);
|
uart_hexdump(key,16);
|
||||||
uart_putstr("\r\n plain: ");
|
uart_putstr("\r\n plain: ");
|
||||||
uart_hexdump(block,32);
|
uart_hexdump(block,32);
|
||||||
_delay_ms(50);
|
|
||||||
shabea256(block,key,128,1,16);
|
shabea256(block,key,128,1,16);
|
||||||
uart_putstr("\r\n crypt: ");
|
uart_putstr("\r\n crypt: ");
|
||||||
uart_hexdump(block,32);
|
uart_hexdump(block,32);
|
||||||
|
@ -61,7 +127,6 @@ void testdecrypt(uint8_t* block, uint8_t* key){
|
||||||
uart_hexdump(key,16);
|
uart_hexdump(key,16);
|
||||||
uart_putstr("\r\n crypt: ");
|
uart_putstr("\r\n crypt: ");
|
||||||
uart_hexdump(block,32);
|
uart_hexdump(block,32);
|
||||||
_delay_ms(50);
|
|
||||||
shabea256(block,key,128,0,16);
|
shabea256(block,key,128,0,16);
|
||||||
uart_putstr("\r\n plain: ");
|
uart_putstr("\r\n plain: ");
|
||||||
uart_hexdump(block,32);
|
uart_hexdump(block,32);
|
||||||
|
@ -101,7 +166,6 @@ void testrun_shabea(void){
|
||||||
testencrypt(datas[i],keys[i]);
|
testencrypt(datas[i],keys[i]);
|
||||||
testdecrypt(datas[i],keys[i]);
|
testdecrypt(datas[i],keys[i]);
|
||||||
}
|
}
|
||||||
// testdecrypt(data,key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,19 +180,22 @@ int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
uart_putstr("\r\n");
|
uart_putstr("\r\n");
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (shabea)\r\nloaded and running\r\n");
|
uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
|
uart_putstr(cipher_name);
|
||||||
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_shabea, testrun_shabea, testrun_performance_shabea};
|
||||||
|
|
||||||
restart:
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_shabea();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,14 +27,73 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "skipjack.h"
|
#include "skipjack.h"
|
||||||
|
#include "nessie_bc_test.h"
|
||||||
|
#include "cli.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
char* cipher_name = "Skipjack";
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void skipjack_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
|
||||||
|
memcpy(ctx, key, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testrun_nessie_skipjack(void){
|
||||||
|
nessie_bc_ctx.blocksize_B = 8;
|
||||||
|
nessie_bc_ctx.keysize_b = 80;
|
||||||
|
nessie_bc_ctx.name = cipher_name;
|
||||||
|
nessie_bc_ctx.ctx_size_B = 10;
|
||||||
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)skipjack_enc;
|
||||||
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)skipjack_dec;
|
||||||
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)skipjack_genctx_dummy;
|
||||||
|
|
||||||
|
nessie_bc_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_performance_skipjack(void){
|
||||||
|
uint16_t i,c;
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t key[10], data[8];
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
getOverhead(&c, &i);
|
||||||
|
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
||||||
|
utoa(c, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
utoa(i, str, 10);
|
||||||
|
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
memset(key, 0, 10);
|
||||||
|
memset(data, 0, 8);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
skipjack_enc(data, key);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
skipjack_dec(data, key);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
|
@ -82,17 +141,18 @@ int main (void){
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n");
|
uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n");
|
||||||
|
|
||||||
restart:
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_skipjack, testrun_skipjack, testrun_performance_skipjack};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_skipjack();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ ALGO_NAME := MD5
|
||||||
HASHES += $(ALGO_NAME)
|
HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := md5.o
|
$(ALGO_NAME)_OBJ := md5.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o md5.o
|
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o md5.o \
|
||||||
|
nessie_hash_test.o nessie_common.o cli.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := seed.o seed-asm.o
|
$(ALGO_NAME)_OBJ := seed.o seed-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-seed-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-seed-test.o debug.o uart.o serial-tools.o \
|
||||||
seed.o seed-asm.o
|
seed.o seed-asm.o nessie_bc_test.o nessie_common.o \
|
||||||
|
cli.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := sha1-asm.o
|
$(ALGO_NAME)_OBJ := sha1-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \
|
||||||
sha1-asm.o
|
sha1-asm.o nessie_hash_test.o nessie_common.o cli.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := sha256-asm.o
|
$(ALGO_NAME)_OBJ := sha256-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
|
||||||
sha256-asm.o nessie_hash_test.o nessie_common.o
|
sha256-asm.o nessie_hash_test.o nessie_common.o cli.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o
|
$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-shabea-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-shabea-test.o debug.o uart.o serial-tools.o \
|
||||||
shabea.o sha256-asm.o
|
shabea.o sha256-asm.o nessie_bc_test.o \
|
||||||
|
nessie_common.o cli.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := skipjack.o
|
$(ALGO_NAME)_OBJ := skipjack.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-skipjack-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-skipjack-test.o debug.o uart.o serial-tools.o \
|
||||||
skipjack.o
|
skipjack.o nessie_bc_test.o nessie_common.o cli.o \
|
||||||
|
performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
6
seed.c
6
seed.c
|
@ -220,7 +220,7 @@ typedef struct{
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void seed_init(seed_ctx_t * ctx, uint8_t * key){
|
void seed_init(uint8_t * key, seed_ctx_t * ctx){
|
||||||
memcpy(ctx->k, key, 128/8);
|
memcpy(ctx->k, key, 128/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ void seed_init(seed_ctx_t * ctx, uint8_t * key){
|
||||||
#define L (((uint64_t*)buffer)[0])
|
#define L (((uint64_t*)buffer)[0])
|
||||||
#define R (((uint64_t*)buffer)[1])
|
#define R (((uint64_t*)buffer)[1])
|
||||||
|
|
||||||
void seed_encrypt(seed_ctx_t * ctx, void * buffer){
|
void seed_encrypt(void * buffer, seed_ctx_t * ctx){
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
keypair_t k;
|
keypair_t k;
|
||||||
for(r=0; r<8; ++r){
|
for(r=0; r<8; ++r){
|
||||||
|
@ -262,7 +262,7 @@ void seed_encrypt(seed_ctx_t * ctx, void * buffer){
|
||||||
#define L (((uint64_t*)buffer)[0])
|
#define L (((uint64_t*)buffer)[0])
|
||||||
#define R (((uint64_t*)buffer)[1])
|
#define R (((uint64_t*)buffer)[1])
|
||||||
|
|
||||||
void seed_decrypt(seed_ctx_t * ctx, void * buffer){
|
void seed_decrypt(void * buffer, seed_ctx_t * ctx){
|
||||||
int8_t r;
|
int8_t r;
|
||||||
keypair_t k;
|
keypair_t k;
|
||||||
for(r=7; r>=0; --r){
|
for(r=7; r>=0; --r){
|
||||||
|
|
6
seed.h
6
seed.h
|
@ -36,8 +36,8 @@ typedef struct{
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
void seed_init(seed_ctx_t * ctx, uint8_t * key);
|
void seed_init(uint8_t * key, seed_ctx_t * ctx);
|
||||||
void seed_encrypt(seed_ctx_t * ctx, void * buffer);
|
void seed_encrypt(void * buffer, seed_ctx_t * ctx);
|
||||||
void seed_decrypt(seed_ctx_t * ctx, void * buffer);
|
void seed_decrypt(void * buffer, seed_ctx_t * ctx);
|
||||||
|
|
||||||
#endif /*SEED_H_*/
|
#endif /*SEED_H_*/
|
||||||
|
|
14
shabea.c
14
shabea.c
|
@ -55,26 +55,26 @@ void memxor(uint8_t * dest, uint8_t * src, uint8_t length){
|
||||||
|
|
||||||
#define L ((uint8_t*)block+ 0)
|
#define L ((uint8_t*)block+ 0)
|
||||||
#define R ((uint8_t*)block+16)
|
#define R ((uint8_t*)block+16)
|
||||||
void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds){
|
void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds){
|
||||||
int8_t r; /**/
|
int8_t r; /**/
|
||||||
uint8_t tb[HALFSIZEB+2+(keysize+7)/8]; /**/
|
uint8_t tb[HALFSIZEB+2+(keysize_b+7)/8]; /**/
|
||||||
uint16_t kbs; /* bytes used for the key / temporary block */
|
uint16_t kbs; /* bytes used for the key / temporary block */
|
||||||
sha256_hash_t hash;
|
sha256_hash_t hash;
|
||||||
|
|
||||||
r = (enc?0:(rounds-1));
|
r = (enc?0:(rounds-1));
|
||||||
kbs = (keysize+7)/8;
|
kbs = (keysize_b+7)/8;
|
||||||
memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */
|
memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */
|
||||||
tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */
|
tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */
|
||||||
|
|
||||||
for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
|
for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
|
||||||
memcpy(tb, R, HALFSIZEB); /* copy right half into tb */
|
memcpy(tb, R, HALFSIZEB); /* copy right half into tb */
|
||||||
tb[HALFSIZEB+1] = r;
|
tb[HALFSIZEB+1] = r;
|
||||||
sha256(&hash, tb, HALFSIZE+16+keysize);
|
sha256(&hash, tb, HALFSIZE+16+keysize_b);
|
||||||
if(!(r==(enc?(rounds-1):0))){
|
if(!(r==(enc?(rounds-1):0))){
|
||||||
/* swap */
|
/* swap */
|
||||||
memxor(hash, L, HALFSIZE);
|
memxor(hash, L, HALFSIZEB);
|
||||||
memcpy(L, R, HALFSIZE);
|
memcpy(L, R, HALFSIZEB);
|
||||||
memcpy(R, hash, HALFSIZE);
|
memcpy(R, hash, HALFSIZEB);
|
||||||
} else {
|
} else {
|
||||||
/* no swap */
|
/* no swap */
|
||||||
memxor(L, hash, HALFSIZE);
|
memxor(L, hash, HALFSIZE);
|
||||||
|
|
2
shabea.h
2
shabea.h
|
@ -31,5 +31,5 @@
|
||||||
#ifndef SHABEA_H_
|
#ifndef SHABEA_H_
|
||||||
#define SHABEA_H_
|
#define SHABEA_H_
|
||||||
|
|
||||||
void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds);
|
void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds);
|
||||||
#endif /*SHABEA_H_*/
|
#endif /*SHABEA_H_*/
|
||||||
|
|
Loading…
Reference in New Issue