/* main-shabal-test.c */
/*
This file is part of the AVR-Crypto-Lib.
- Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
+ Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
/*
* shabal test-suit
- *
+ *
*/
-#include "config.h"
-#include "serial-tools.h"
-#include "uart.h"
-#include "debug.h"
+
+#include "main-test-common.h"
#include "shabal.h"
-#include "cli.h"
#include "hfal_shabal.h"
+#include "hfal-test.h"
+#include "hfal-nessie.h"
+#include "hfal-performance.h"
#include "shavs.h"
#include "nessie_hash_test.h"
#include "performance_test.h"
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
+char *algo_name = "Shabal";
-char* algo_name = "Shabal";
+const hfdesc_t *const algolist[] PROGMEM = {
+ (hfdesc_t*)&shabal192_desc,
+ (hfdesc_t*)&shabal224_desc,
+ (hfdesc_t*)&shabal256_desc,
+ (hfdesc_t*)&shabal384_desc,
+ (hfdesc_t*)&shabal512_desc,
+ NULL
+};
/*****************************************************************************
* additional validation-functions *
*****************************************************************************/
-void testrun_stdtest_shabal192(void* msg, uint16_t size_b){
- uint8_t hash[192/8];
-
- cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (192 bits):"));
-
- cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
- shabal192(hash, msg, size_b);
- cli_putstr_P(PSTR("\r\nhash:"));
- cli_hexdump_block(hash, 192/8, 4, 16);
+void testrun_stdtest_shabal192(void *msg, uint16_t size_b){
+ hfal_test(&shabal192_desc, msg, size_b);
}
-void testrun_stdtest_shabal224(void* msg, uint16_t size_b){
- uint8_t hash[224/8];
-
- cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (224 bits):"));
-
- cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
- shabal224(hash, msg, size_b);
- cli_putstr_P(PSTR("\r\nhash:"));
- cli_hexdump_block(hash, 224/8, 4, 16);
+void testrun_stdtest_shabal224(void *msg, uint16_t size_b){
+ hfal_test(&shabal224_desc, msg, size_b);
}
-void testrun_stdtest_shabal256(void* msg, uint16_t size_b){
- uint8_t hash[256/8];
-
- cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (256 bits):"));
-
- cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
- shabal256(hash, msg, size_b);
- cli_putstr_P(PSTR("\r\nhash:"));
- cli_hexdump_block(hash, 256/8, 4, 16);
+void testrun_stdtest_shabal256(void *msg, uint16_t size_b){
+ hfal_test(&shabal256_desc, msg, size_b);
}
-void testrun_stdtest_shabal384(void* msg, uint16_t size_b){
- uint8_t hash[384/8];
-
- cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (384 bits):"));
-
- cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
- shabal384(hash, msg, size_b);
- cli_putstr_P(PSTR("\r\nhash:"));
- cli_hexdump_block(hash, 384/8, 4, 16);
+void testrun_stdtest_shabal384(void *msg, uint16_t size_b){
+ hfal_test(&shabal384_desc, msg, size_b);
}
-void testrun_stdtest_shabal512(void* msg, uint16_t size_b){
- uint8_t hash[512/8];
-
- cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (512 bits):"));
-
- cli_putstr_P(PSTR("\r\nmessage:"));
- cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
- shabal512(hash, msg, size_b);
- cli_putstr_P(PSTR("\r\nhash:"));
- cli_hexdump_block(hash, 512/8, 4, 16);
+void testrun_stdtest_shabal512(void *msg, uint16_t size_b){
+ hfal_test(&shabal512_desc, msg, size_b);
}
void testrun_stdtest_shabal(void){
testrun_stdtest_shabal512(mb, strlen(mb)*8);
}
-void performance_shabal(void){
- uint64_t t;
- char str[16];
- uint8_t data[64];
- uint8_t hash[512/8];
+void testshort(void){
+ uint8_t ma[64];
+ memset(ma, 0, 64);
+ testrun_stdtest_shabal192(ma, 64*8);
+}
+
+void shabal_ctx_dump(shabal_ctx_t *ctx){
+ uint8_t i;
+ void *p;
+ cli_putstr_P(PSTR("\r\n=== shabal ctx dump ===\r\n size = "));
+ i=sizeof(shabal_ctx_t);
+ if(i>=100)
+ cli_putc('0'+i/100);
+ if(i>=10)
+ cli_putc('0'+(i/10)%10);
+ cli_putc('0'+i%10);
+ cli_putstr_P(PSTR("\r\n a = "));
+ cli_hexdump_block(ctx->a, 12*4, 5, 4*8);
+ cli_putstr_P(PSTR("\r\n b_buffer = "));
+ cli_hexdump_block(ctx->b_buffer, 12*4, 5, 4*8);
+ cli_putstr_P(PSTR("\r\n c_buffer = "));
+ cli_hexdump_block(ctx->c_buffer, 12*4, 5, 4*8);
+ if(ctx->b == &(ctx->b_buffer[0]))
+ cli_putstr_P(PSTR("\r\nb --> b_buffer"));
+ if(ctx->b == &(ctx->c_buffer[0]))
+ cli_putstr_P(PSTR("\r\nb --> c_buffer"));
+ if(ctx->c == &(ctx->b_buffer[0]))
+ cli_putstr_P(PSTR("\r\nc --> b_buffer"));
+ if(ctx->c == &(ctx->c_buffer[0]))
+ cli_putstr_P(PSTR("\r\nc --> c_buffer"));
+ cli_putstr_P(PSTR("\r\n b = "));
+ cli_hexdump(&(ctx->b), 2);
+ p = ctx->b_buffer;
+ cli_putstr_P(PSTR("\r\n b (should) = "));
+ cli_hexdump(&p, 2);
+ cli_putstr_P(PSTR("\r\n c = "));
+ cli_hexdump(&(ctx->c), 2);
+ p = ctx->c_buffer;
+ cli_putstr_P(PSTR("\r\n c (should) = "));
+ cli_hexdump(&p, 2);
+}
+
+
+void testinit_192(void){
shabal_ctx_t ctx;
-
- calibrateTimer();
- print_overhead();
-
- memset(data, 0, 64);
-
- startTimer(1);
- shabal192_init(&ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time (192): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal192_init(&ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time (224): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
shabal192_init(&ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time (256): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal192_init(&ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time (384): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal192_init(&ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx-gen time (512): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal_nextBlock(&ctx, data);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tone-block time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
-
- startTimer(1);
- shabal_lastBlock(&ctx, data, 0);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tlast block time: "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal192_ctx2hash(hash, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx2hash time (192): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal224_ctx2hash(hash, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx2hash time (224): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal256_ctx2hash(hash, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx2hash time (256): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal384_ctx2hash(hash, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx2hash time (384): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- startTimer(1);
- shabal512_ctx2hash(hash, &ctx);
- t = stopTimer();
- cli_putstr_P(PSTR("\r\n\tctx2hash time (512): "));
- ultoa((unsigned long)t, str, 10);
- cli_putstr(str);
-
- cli_putstr_P(PSTR("\r\n"));
+ shabal_ctx_dump(&ctx);
+}
+void testinit_224(void){
+ shabal_ctx_t ctx;
+ shabal224_init(&ctx);
+ shabal_ctx_dump(&ctx);
+}
+
+void testinit_256(void){
+ shabal_ctx_t ctx;
+ shabal256_init(&ctx);
+ shabal_ctx_dump(&ctx);
+}
+
+void testinit_384(void){
+ shabal_ctx_t ctx;
+ shabal384_init(&ctx);
+ shabal_ctx_dump(&ctx);
+}
+
+void testinit_512(void){
+ shabal_ctx_t ctx;
+ shabal512_init(&ctx);
+ shabal_ctx_dump(&ctx);
+}
+void testinit(void){
+ testinit_192();
+ testinit_224();
+ testinit_256();
+ testinit_384();
+ testinit_512();
+}
+
+void performance_shabal(void){
+ hfal_performance_multiple(algolist);
}
void testrun_nessie_shabal(void){
- nessie_hash_ctx.hashsize_b = 192;
- nessie_hash_ctx.blocksize_B = 512/8;
- nessie_hash_ctx.ctx_size_B = sizeof(shabal_ctx_t);
- nessie_hash_ctx.name = "Shabal-192";
- nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal192_init;
- nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)shabal_nextBlock;
- nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)shabal_lastBlock;
- nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal192_ctx2hash;
-
- nessie_hash_run();
-
- nessie_hash_ctx.hashsize_b = 224;
- nessie_hash_ctx.name = "Shabal-224";
- nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal224_init;
- nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal224_ctx2hash;
-
- nessie_hash_run();
-
- nessie_hash_ctx.hashsize_b = 256;
- nessie_hash_ctx.name = "Shabal-256";
- nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal256_init;
- nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal256_ctx2hash;
-
- nessie_hash_run();
-
- nessie_hash_ctx.hashsize_b = 384;
- nessie_hash_ctx.name = "Shabal-384";
- nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal384_init;
- nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal384_ctx2hash;
-
- nessie_hash_run();
-
- nessie_hash_ctx.hashsize_b = 512;
- nessie_hash_ctx.name = "Shabal-512";
- nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal512_init;
- nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal512_ctx2hash;
-
- nessie_hash_run();
-
+ hfal_nessie_multiple(algolist);
}
/*****************************************************************************
* main *
*****************************************************************************/
-const hfdesc_t* algolist[] PROGMEM = {
- (hfdesc_t*)&shabal192_desc,
- (hfdesc_t*)&shabal224_desc,
- (hfdesc_t*)&shabal256_desc,
- (hfdesc_t*)&shabal384_desc,
- (hfdesc_t*)&shabal512_desc,
- NULL
-};
const char nessie_str[] PROGMEM = "nessie";
const char test_str[] PROGMEM = "test";
+const char testinit192_str[] PROGMEM = "testinit192";
+const char testinit_str[] PROGMEM = "testinit";
+const char testshort_str[] PROGMEM = "short";
const char ztest_str[] PROGMEM = "zerotest";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
const char shavs_set_str[] PROGMEM = "shavs_set";
const char shavs_test1_str[] PROGMEM = "shavs_test1";
-
-cmdlist_entry_t cmdlist[] PROGMEM = {
- { nessie_str, NULL, testrun_nessie_shabal},
- { test_str, NULL, testrun_stdtest_shabal},
- { performance_str, NULL, performance_shabal},
- { shavs_list_str, NULL, shavs_listalgos},
- { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
- { shavs_test1_str, NULL, shavs_test1},
- { echo_str, (void*)1, (void_fpt)echo_ctrl},
- { NULL, NULL, NULL}
+const char shavs_test2_str[] PROGMEM = "shavs_test2";
+const char shavs_test3_str[] PROGMEM = "shavs_test3";
+
+const cmdlist_entry_t cmdlist[] PROGMEM = {
+ { nessie_str, NULL, testrun_nessie_shabal },
+ { test_str, NULL, testrun_stdtest_shabal },
+ { testinit192_str, NULL, testinit_192 },
+ { testinit_str, NULL, testinit },
+ { testshort_str, NULL, testshort },
+ { performance_str, NULL, performance_shabal },
+ { shavs_list_str, NULL, shavs_listalgos },
+ { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo },
+ { shavs_test1_str, NULL, shavs_test1 },
+ { shavs_test2_str, NULL, shavs_test2 },
+ { shavs_test3_str, NULL, shavs_test3 },
+ { echo_str, (void*)1, (void_fpt)echo_ctrl },
+ { NULL, NULL, NULL }
};
int main (void){
- DEBUG_INIT();
-
- cli_rx = uart_getc;
- cli_tx = uart_putc;
- shavs_algolist=(hfdesc_t**)algolist;
+ main_setup();
+
+ shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&shabal256_desc;
+
for(;;){
- cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
- cli_putstr(algo_name);
- cli_putstr_P(PSTR("; "));
- cli_putstr(__DATE__);
- cli_putstr_P(PSTR(" "));
- cli_putstr(__TIME__);
- cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
-
- cmd_interface(cmdlist);
+ welcome_msg(algo_name);
+ cmd_interface(cmdlist);
}
-}
+}