]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
some tunes at the Makefile + code reorganisation at the nessie test banches
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 8 Apr 2008 03:21:13 +0000 (03:21 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Tue, 8 Apr 2008 03:21:13 +0000 (03:21 +0000)
13 files changed:
Makefile
arcfour.mk
cast5.mk
hmac-sha256.mk
nessie_bc_test.c
nessie_common.c [new file with mode: 0644]
nessie_common.h [new file with mode: 0644]
nessie_hash_test.c
nessie_mac_test.c
nessie_stream_test.c
serpent.mk
sha256.mk
xtea.mk

index 5bae67fc4c1f8f339bfc947d1c1e5ed180609f9d..169eb668bfac7dbed48e70aeebdfaa4b82c906b6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,10 +25,6 @@ ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS))
 
 PRG = remove_me
 
-#Multi_OBJ             = main.o debug.o uart.o serial-tools.o sha256-asm.o xtea-asm.o arcfour-asm.o prng.o cast5.o
-
-#OBJ = $(SERPENT_OBJ)
-
 DEFS      =
 LIBS      =
 
@@ -67,17 +63,53 @@ info:
 #      echo $(ALGORITHMS_NESSIE_TEST)
 #      echo $(ALGORITHMS_PERFORMANCE_TEST)
 
-bc:    $(ALGORITHMS_OBJ)
+%.o: %.c
+       @echo "[gcc]: $@"
+       @$(CC) $(CFLAGS) -c     -o $@ $<
+
+%.o: %.S
+       @echo "[as] : $@"
+       @$(CC) $(ASFLAGS) -c -o $@ $<
+
+
+.PHONY: cores
+cores: $(ALGORITHMS_OBJ)
+
+.PHONY: blockciphers
+blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
+
+.PHONY: streamciphers
+streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
+
+.PHONY:  hashes
+hashes: $(patsubst %, %_OBJ, $(HASHES))
+
+.PHONY:  macs
+macs: $(patsubst %, %_OBJ, $(MACS))
+
+prngs: $(patsubst %, %_OBJ, $(PRNGS))
 
 tests: $(ALGORITHMS_TEST_BIN) \
        $(ALGORITHMS_TEST_BIN_MAIN_ELF) \
        $(ALGORITHMS_TEST_BIN_MAIN_HEX)
 
 
-$(ALGORITHMS_OBJ):  $(ALGORITHMS_OBJ_IMM)
-$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM)
+define OBJ_TEMPLATE
+$(1)_OBJ: $(2)
+#      @echo " ALGO: $(1)"
+#      @echo " REQ:  $(2)"
+endef
 
-#$(ALGORITHMS):  
+$(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ))))
+
+
+$(BLOCK_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(BLOCK_CIPHERS)) 
+$(STREAM_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(STREAM_CIPHERS))
+$(HASHES_OBJ): $(patsubst %,%_OBJ, $(HASHES))
+$(PRNGS_OBJ): $(patsubst %,%_OBJ, $(PRNGS))
+$(MACS_OBJ): $(patsubst %,%_OBJ, $(MACS))
+
+$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM)
        
 .PHONY: all
 all: $(PRG).elf lst text eeprom
index 58c24b90da899bbf5352bae540a7942b0da55479..a05f2363ff1476e4bbf33cec225fbc0bd19b2fb5 100644 (file)
@@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := arcfour-asm.o
 $(ALGO_NAME)_TEST_BIN := main-arcfour-test.o debug.o uart.o serial-tools.o \
-                         nessie_stream_test.o arcfour-asm.o
+                         nessie_stream_test.o nessie_common.o arcfour-asm.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
 
index 23dadc116c461f16d9f0de7be82d23059e4b717e..2969c828a7474bc5df99e68316ed32f497559fa2 100644 (file)
--- a/cast5.mk
+++ b/cast5.mk
@@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := cast5.o
 $(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o \
-                         cast5.o nessie_bc_test.o
+                         cast5.o nessie_bc_test.o nessie_common.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
 
index e3bf7bec0fd22231d052082a74df225c976d9359..6d957b3b9cc5d183c1ab92d33c66a63e9824ab76 100644 (file)
@@ -6,7 +6,7 @@ MACS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := hmac-sha256.o sha256-asm.o
 $(ALGO_NAME)_TEST_BIN := main-hmac-sha256-test.o debug.o uart.o serial-tools.o \
-                         hmac-sha256.o sha256-asm.o nessie_mac_test.o
+                         hmac-sha256.o sha256-asm.o nessie_mac_test.o nessie_common.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
 
index c8f925738af7b964a8e99f1b4259ef9419e362d2..b6256d4e31e6e77960f3477d8015bb51285d67a2 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include "nessie_bc_test.h"
+#include "nessie_common.h"
 #include "uart.h"
 
-
-
 nessie_bc_ctx_t nessie_bc_ctx;
 
-static void printblock(uint8_t* block, uint16_t blocksize_bit){
-       char tab [] = {'0', '1', '2', '3', 
-                                  '4', '5', '6', '7', 
-                                  '8', '9', 'A', 'B', 
-                                  'C', 'D', 'E', 'F'};
-       uint16_t i;
-       for(i=0; i<(blocksize_bit+7)/8; ++i){
-               uart_putc(tab[(block[i])>>4]);
-               uart_putc(tab[(block[i])&0xf]);
-       }                                  
-}
-
-#define SPACES 31
-#define BYTESPERLINE 16
-
-static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
-       uint8_t name_len;
-       uint8_t i;
-       name_len=strlen(name);
-       if(name_len>SPACES-1){
-               uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
-               return;
-       }
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<SPACES-name_len-1; ++i){
-               uart_putc(' ');
-       }
-       uart_putstr(name);
-       uart_putc('=');
-       /* now the data printing begins */
-       if(size_B<=BYTESPERLINE){
-               /* one line seems sufficient */
-               printblock(buffer, size_B*8);
-       } else {
-               /* we need more lines */
-               printblock(buffer, BYTESPERLINE*8); /* first line */
-               int16_t toprint = size_B - BYTESPERLINE;
-               buffer += BYTESPERLINE;
-               while(toprint > 0){
-                       uart_putstr_P(PSTR("\r\n"));
-                       for(i=0; i<SPACES; ++i){
-                               uart_putc(' ');
-                       }
-                       printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
-                       buffer  += BYTESPERLINE;
-                       toprint -= BYTESPERLINE;
-               }
-       }
-} 
-
 void nessie_bc_enc(uint8_t* key, uint8_t* pt){
        uint8_t ctx[nessie_bc_ctx.ctx_size_B];
        uint8_t buffer[nessie_bc_ctx.blocksize_B];
        uint16_t i;
        
        /* single test */
-       printitem("key", key, (nessie_bc_ctx.keysize_b+7)/8);
+       nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
        nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
        memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
-       printitem("plain", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_enc(buffer, ctx);
-       printitem("cipher", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_dec(buffer, ctx);
-       printitem("decrypted", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
        
        /* 100 times test */
        memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
        for(i=0; i<100; ++i){
                nessie_bc_ctx.cipher_enc(buffer, ctx);
        }
-       printitem("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
 #ifndef NESSIE_NO1KTEST        
        /* 1000 times test, we use the 100 precedig steps to fasten things a bit */
        for(; i<1000; ++i){
                nessie_bc_ctx.cipher_enc(buffer, ctx);
        }
-       printitem("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
 #endif
 }
 
@@ -101,96 +50,30 @@ void nessie_bc_dec(uint8_t* key, uint8_t* ct){
        uint8_t buffer[nessie_bc_ctx.blocksize_B];
        
        /* single test */
-       printitem("key", key, (nessie_bc_ctx.keysize_b+7)/8);
+       nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
        nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
        memcpy(buffer, ct, nessie_bc_ctx.blocksize_B);
-       printitem("cipher", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_dec(buffer, ctx);
-       printitem("plain", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_enc(buffer, ctx);
-       printitem("encrypted", buffer, nessie_bc_ctx.blocksize_B);
+       nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B);
        
 }
 
-static void print_set_vector(uint8_t set, uint16_t vector){
-       uart_putstr_P(PSTR("\r\n\r\nSet "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR(", vector#"));
-       uart_putc((vector<100)?' ':'0'+vector/100);
-       uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
-       uart_putc('0'+vector%10);
-       uart_putc(':');
-}
-
-/* example:
-Test vectors -- set 3
-=====================
- */ 
-static void print_setheader(uint8_t set){
-       uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR("\r\n====================="));
-}
-
-/* example:
-********************************************************************************
-*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-********************************************************************************
-
-Primitive Name: Serpent
-=======================
-Key size: 256 bits
-Block size: 128 bits
-*/
-
-static void print_header(void){
-       uint16_t i;
-       uart_putstr_P(PSTR("\r\n\r\n"
-       "********************************************************************************\r\n"
-       "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte            *\r\n"
-       "********************************************************************************\r\n"
-       "\r\n"));
-       uart_putstr_P(PSTR("Primitive Name: "));
-       uart_putstr(nessie_bc_ctx.name);
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<16+strlen(nessie_bc_ctx.name); ++i){
-               uart_putc('=');
-       }
-       uart_putstr_P(PSTR("\r\nKey size: "));
-       if(nessie_bc_ctx.keysize_b>100){
-               uart_putc('0'+nessie_bc_ctx.keysize_b/100);
-       }
-       if(nessie_bc_ctx.keysize_b>10){
-               uart_putc('0'+(nessie_bc_ctx.keysize_b/10)%10);
-       }
-       uart_putc('0'+nessie_bc_ctx.keysize_b%10);
-       uart_putstr_P(PSTR(" bits\r\nBlock size: "));
-       if(nessie_bc_ctx.blocksize_B*8>100){
-               uart_putc('0'+(nessie_bc_ctx.blocksize_B*8)/100);
-       }
-       if(nessie_bc_ctx.blocksize_B*8>10){
-               uart_putc('0'+((nessie_bc_ctx.blocksize_B*8)/10)%10);
-       }
-       uart_putc('0'+(nessie_bc_ctx.blocksize_B*8)%10);
-       uart_putstr_P(PSTR(" bits"));
-}
-
-static void print_footer(void){
-       uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
-}
-
 void nessie_bc_run(void){
        uint16_t i;
        uint8_t set;
        uint8_t key[(nessie_bc_ctx.keysize_b+7)/8];
        uint8_t buffer[nessie_bc_ctx.blocksize_B];
        
-       print_header();
+       nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b,
+                           nessie_bc_ctx.blocksize_B*8, 0, 0, 0);
        /* test set 1 */
        set=1;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
                key[i/8] |= 0x80>>(i%8);
                memset(buffer, 0, nessie_bc_ctx.blocksize_B);
@@ -198,9 +81,9 @@ void nessie_bc_run(void){
        }
        /* test set 2 */
        set=2;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
                memset(buffer, 0, nessie_bc_ctx.blocksize_B);
                buffer[i/8] |= 0x80>>(i%8);
@@ -208,18 +91,18 @@ void nessie_bc_run(void){
        }
        /* test set 3 */
        set=3;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<256; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
                memset(buffer, i, nessie_bc_ctx.blocksize_B);
                nessie_bc_enc(key, buffer);
        }
        /* test set 4 */
        set=4;
-       print_setheader(set);
+       nessie_print_setheader(set);
        /* 4 - 0*/
-       print_set_vector(set, 0);
+       nessie_print_set_vector(set, 0);
        for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
                key[i]=i;
        }
@@ -228,7 +111,7 @@ void nessie_bc_run(void){
        }
        nessie_bc_enc(key, buffer);
        /* 4 - 1 */
-       print_set_vector(set, 1);       
+       nessie_print_set_vector(set, 1);        
     /* This is the test vectors in Kasumi */
     static uint8_t kasumi_key[] = {
            0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
@@ -245,9 +128,9 @@ void nessie_bc_run(void){
        /* half done ;-) */
        /* test set 5 */
        set=5;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
                key[i/8] |= 0x80>>(i%8);
                memset(buffer, 0, nessie_bc_ctx.blocksize_B);
@@ -255,9 +138,9 @@ void nessie_bc_run(void){
        }
        /* test set 6 */
        set=6;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
                memset(buffer, 0, nessie_bc_ctx.blocksize_B);
                buffer[i/8] |= 0x80>>(i%8);
@@ -265,18 +148,18 @@ void nessie_bc_run(void){
        }
        /* test set 7 */
        set=7;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<256; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
                memset(buffer, i, nessie_bc_ctx.blocksize_B);
                nessie_bc_dec(key, buffer);
        }
        /* test set 8 */
        set=8;
-       print_setheader(set);
+       nessie_print_setheader(set);
        /* 8 - 0*/
-       print_set_vector(set, 0);
+       nessie_print_set_vector(set, 0);
        for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
                key[i]=i;
        }
@@ -285,7 +168,7 @@ void nessie_bc_run(void){
        }
        nessie_bc_dec(key, buffer);
        /* 8 - 1 */
-       print_set_vector(set, 1);       
+       nessie_print_set_vector(set, 1);        
        for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
                key[i]=kasumi_key[i%sizeof(kasumi_key)];
        }
@@ -293,5 +176,5 @@ void nessie_bc_run(void){
                buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
        }
        nessie_bc_dec(key, buffer);
-       print_footer();
+       nessie_print_footer();
 }
diff --git a/nessie_common.c b/nessie_common.c
new file mode 100644 (file)
index 0000000..2f663a6
--- /dev/null
@@ -0,0 +1,155 @@
+/**
+ * 
+ * author: Daniel Otte
+ * email:  daniel.otte@rub.de
+ * license: GPLv3
+ * 
+ * common function for nessie-tests
+ * 
+ * */
+
+#include <string.h>
+#include <stdint.h>
+#include <avr/pgmspace.h>
+#include <stdlib.h> /* utoa() */
+#include "uart.h"
+
+void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){
+       char tab [] = {'0', '1', '2', '3', 
+                                  '4', '5', '6', '7', 
+                                  '8', '9', 'A', 'B', 
+                                  'C', 'D', 'E', 'F'};
+       uint16_t i;
+       for(i=0; i<(blocksize_bit+7)/8; ++i){
+               uart_putc(tab[(block[i])>>4]);
+               uart_putc(tab[(block[i])&0xf]);
+       }                                  
+}
+
+#define SPACES 31
+#define BYTESPERLINE 16
+
+void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
+       uint8_t name_len;
+       uint8_t i;
+       name_len=strlen(name);
+       if(name_len>SPACES-1){
+               uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
+               return;
+       }
+       uart_putstr_P(PSTR("\r\n"));
+       for(i=0; i<SPACES-name_len-1; ++i){
+               uart_putc(' ');
+       }
+       uart_putstr(name);
+       uart_putc('=');
+       /* now the data printing begins */
+       if(size_B<=BYTESPERLINE){
+               /* one line seems sufficient */
+               nessie_print_block(buffer, size_B*8);
+       } else {
+               /* we need more lines */
+               nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
+               int16_t toprint = size_B - BYTESPERLINE;
+               buffer += BYTESPERLINE;
+               while(toprint > 0){
+                       uart_putstr_P(PSTR("\r\n"));
+                       for(i=0; i<SPACES; ++i){
+                               uart_putc(' ');
+                       }
+                       nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
+                       buffer  += BYTESPERLINE;
+                       toprint -= BYTESPERLINE;
+               }
+       }
+} 
+
+
+void nessie_print_set_vector(uint8_t set, uint16_t vector){
+       uart_putstr_P(PSTR("\r\n\r\nSet "));
+       uart_putc('0'+set%10);
+       uart_putstr_P(PSTR(", vector#"));
+       uart_putc((vector<100)?' ':'0'+vector/100);
+       uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
+       uart_putc('0'+vector%10);
+       uart_putc(':');
+}
+
+/* example:
+Test vectors -- set 3
+=====================
+ */ 
+void nessie_print_setheader(uint8_t set){
+       uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
+       uart_putc('0'+set%10);
+       uart_putstr_P(PSTR("\r\n====================="));
+}
+
+/* example:
+********************************************************************************
+*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
+********************************************************************************
+
+Primitive Name: Serpent
+=======================
+Key size: 256 bits
+Block size: 128 bits
+*/
+
+void nessie_print_header(char* name,
+                         uint16_t keysize_b, 
+                         uint16_t blocksize_b,
+                         uint16_t hashsize_b, 
+                         uint16_t macsize_b,
+                         uint16_t ivsize_b ){
+       uint16_t i;
+       uart_putstr_P(PSTR("\r\n\r\n"
+       "********************************************************************************\r\n"
+       "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte            *\r\n"
+       "********************************************************************************\r\n"
+       "\r\n"));
+       uart_putstr_P(PSTR("Primitive Name: "));
+       uart_putstr(name);
+       uart_putstr_P(PSTR("\r\n"));
+       /* underline */ 
+       for(i=0; i<16+strlen(name); ++i){
+               uart_putc('=');
+       }
+       char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
+       if(keysize_b){
+               uart_putstr_P(PSTR("\r\nKey size: "));
+               utoa(keysize_b, str, 10);
+               uart_putstr(str);
+               uart_putstr_P(PSTR(" bits"));
+       }
+       if(blocksize_b){
+               uart_putstr_P(PSTR("\r\nBlock size: "));
+               utoa(blocksize_b, str, 10);
+               uart_putstr(str);
+               uart_putstr_P(PSTR(" bits"));
+       }
+       if(hashsize_b){
+               uart_putstr_P(PSTR("\r\nHash size: "));
+               utoa(hashsize_b, str, 10);
+               uart_putstr(str);
+               uart_putstr_P(PSTR(" bits"));
+       }
+       if(macsize_b){
+               uart_putstr_P(PSTR("\r\nMac size: "));
+               utoa(macsize_b, str, 10);
+               uart_putstr(str);
+               uart_putstr_P(PSTR(" bits"));
+       }
+       if(ivsize_b){
+               uart_putstr_P(PSTR("\r\nIV size: "));
+               utoa(ivsize_b, str, 10);
+               uart_putstr(str);
+               uart_putstr_P(PSTR(" bits"));
+       }
+       uart_putstr_P(PSTR(" bits"));
+}
+
+void nessie_print_footer(void){
+       uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
+}
+
diff --git a/nessie_common.h b/nessie_common.h
new file mode 100644 (file)
index 0000000..629fd77
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * 
+ * author: Daniel Otte
+ * email:  daniel.otte@rub.de
+ * license: GPLv3
+ * 
+ * common function for nessie-tests
+ * 
+ * */
+
+#ifndef NESSIE_COMMON_H_
+#define NESSIE_COMMON_H_
+
+
+#include <stdint.h>
+
+void nessie_print_block(uint8_t* block, uint16_t blocksize_bit);
+void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B);
+void nessie_print_set_vector(uint8_t set, uint16_t vector);
+void nessie_print_setheader(uint8_t set);
+void nessie_print_header(char* name,
+                         uint16_t keysize_b, 
+                         uint16_t blocksize_b,
+                         uint16_t hashsize_b, 
+                         uint16_t macsize_b,
+                         uint16_t ivsize_b );
+void nessie_print_footer(void);
+
+#endif /*NESSIE_COMMON_H_*/
index 598abc08ae9af13c93f1de40076e2f9c9633f7fb..5f8e33c513a8356845d0135c6d6681d8441eebe3 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include "nessie_hash_test.h"
+#include "nessie_common.h"
 #include "uart.h"
 
 nessie_hash_ctx_t nessie_hash_ctx;
 
-static void printblock(uint8_t* block, uint16_t blocksize_bit){
-       char tab [] = {'0', '1', '2', '3', 
-                                  '4', '5', '6', '7', 
-                                  '8', '9', 'A', 'B', 
-                                  'C', 'D', 'E', 'F'};
-       uint16_t i;
-       for(i=0; i<(blocksize_bit+7)/8; ++i){
-               uart_putc(tab[(block[i])>>4]);
-               uart_putc(tab[(block[i])&0xf]);
-       }                                  
-}
-
-#define SPACES 31
-#define BYTESPERLINE 16
-
-static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
-       uint8_t name_len;
-       uint8_t i;
-       name_len=strlen(name);
-       if(name_len>SPACES-1){
-               uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
-               return;
-       }
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<SPACES-name_len-1; ++i){
-               uart_putc(' ');
-       }
-       uart_putstr(name);
-       uart_putc('=');
-       /* now the data printing begins */
-       if(size_B<=BYTESPERLINE){
-               /* one line seems sufficient */
-               printblock(buffer, size_B*8);
-       } else {
-               /* we need more lines */
-               printblock(buffer, BYTESPERLINE*8); /* first line */
-               int16_t toprint = size_B - BYTESPERLINE;
-               buffer += BYTESPERLINE;
-               while(toprint > 0){
-                       uart_putstr_P(PSTR("\r\n"));
-                       for(i=0; i<SPACES; ++i){
-                               uart_putc(' ');
-                       }
-                       printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
-                       buffer  += BYTESPERLINE;
-                       toprint -= BYTESPERLINE;
-               }
-       }
-} 
-
-static void print_set_vector(uint8_t set, uint16_t vector){
-       uart_putstr_P(PSTR("\r\n\r\nSet "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR(", vector#"));
-       uart_putc((vector<100)?' ':'0'+vector/100);
-       uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
-       uart_putc('0'+vector%10);
-       uart_putc(':');
-}
-
-/* example:
-Test vectors -- set 3
-=====================
- */ 
-static void print_setheader(uint8_t set){
-       uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR("\r\n====================="));
-}
-
-/* example:
-********************************************************************************
-*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-********************************************************************************
-
-Primitive Name: Serpent
-=======================
-Key size: 256 bits
-Block size: 128 bits
-*/
-
-static void print_header(void){
-       uint16_t i;
-       uart_putstr_P(PSTR("\r\n\r\n"
-       "********************************************************************************\r\n"
-       "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte            *\r\n"
-       "********************************************************************************\r\n"
-       "\r\n"));
-       uart_putstr_P(PSTR("Primitive Name: "));
-       uart_putstr(nessie_hash_ctx.name);
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<16+strlen(nessie_hash_ctx.name); ++i){
-               uart_putc('=');
-       }
-       uart_putstr_P(PSTR("\r\nHash size: "));
-       if(nessie_hash_ctx.hashsize_b >100){
-               uart_putc('0'+nessie_hash_ctx.hashsize_b/100);
-       }
-       if(nessie_hash_ctx.hashsize_b>10){
-               uart_putc('0'+(nessie_hash_ctx.hashsize_b/10)%10);
-       }
-       uart_putc('0'+nessie_hash_ctx.hashsize_b%10);
-       uart_putstr_P(PSTR(" bits\r\n"));
-}
-
-static void print_footer(void){
-       uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
-}
-
 static
 void ascii_hash(char* data, char* desc){
        uint8_t ctx[nessie_hash_ctx.ctx_size_B];
@@ -140,7 +32,7 @@ void ascii_hash(char* data, char* desc){
        }
        nessie_hash_ctx.hash_last(data, sl*8, ctx);
        nessie_hash_ctx.hash_conv(hash, ctx);
-       printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
 }
 
 // message=1 million times "a"
@@ -162,7 +54,7 @@ void amillion_hash(void){
        }
        nessie_hash_ctx.hash_last(block, n*8, ctx);
        nessie_hash_ctx.hash_conv(hash, ctx);
-       printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
 }
 
 
@@ -192,7 +84,7 @@ void zero_hash(uint16_t n){
        }
        nessie_hash_ctx.hash_last(block, n, ctx);
        nessie_hash_ctx.hash_conv(hash, ctx);
-       printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
 }
 
 static
@@ -234,7 +126,7 @@ void one_in512_hash(uint16_t pos){
        }
        nessie_hash_ctx.hash_last(block, n, ctx);
        nessie_hash_ctx.hash_conv(hash, ctx);
-       printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
 }
 
 static
@@ -256,13 +148,13 @@ void tv4_hash(void){
        }
        nessie_hash_ctx.hash_last(block, n, ctx);
        nessie_hash_ctx.hash_conv(hash, ctx);
-       printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
        for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */
                nessie_hash_ctx.hash_init(ctx);
                nessie_hash_ctx.hash_last(hash, nessie_hash_ctx.hashsize_b, ctx);
                nessie_hash_ctx.hash_conv(hash, ctx);
        }
-       printitem("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
+       nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
 }
 
 /*
@@ -281,7 +173,7 @@ void nessie_hash_run(void){
        uint16_t i;
        uint8_t set;
        
-       print_header();
+       nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0);
        /* test set 1 */
        char* challange[8][2]= {
                {"", "\"\" (empty string)"},
@@ -299,32 +191,32 @@ void nessie_hash_run(void){
                 "8 times \"1234567890\""}      
        };
        set=1;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<8; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                ascii_hash(challange[i][0], challange[i][1]);
        }
-       print_set_vector(set, i);
+       nessie_print_set_vector(set, i);
        amillion_hash();
        /* test set 2 */
        set=2;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<1024; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                zero_hash(i);
        }
        /* test set 3 */
        set=3;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<512; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                one_in512_hash(i);
        }
        /* test set 4 */
        set=4;
-       print_setheader(set);
-       print_set_vector(set, 0);
+       nessie_print_setheader(set);
+       nessie_print_set_vector(set, 0);
        tv4_hash();
 
-       print_footer();
+       nessie_print_footer();
 }
index c5a851fbd00e759502ff42df049f2474eb42d9fe..5e2a88d196137cdf6113671748874c7939298112 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdint.h>
 #include <string.h>
 #include "nessie_mac_test.h"
+#include "nessie_common.h"
 #include "uart.h"
 
 nessie_mac_ctx_t nessie_mac_ctx;
@@ -17,117 +18,8 @@ nessie_mac_ctx_t nessie_mac_ctx;
 #define KEYSIZE_B ((nessie_mac_ctx.keysize_b+7)/8)
 #define MACSIZE_B ((nessie_mac_ctx.macsize_b+7)/8)
 
-#define PRINTKEY printitem("key", key, KEYSIZE_B)
-#define PRINTMAC printitem("MAC", mac, MACSIZE_B)
-
-static void printblock(uint8_t* block, uint16_t blocksize_bit){
-       char tab [] = {'0', '1', '2', '3', 
-                                  '4', '5', '6', '7', 
-                                  '8', '9', 'A', 'B', 
-                                  'C', 'D', 'E', 'F'};
-       uint16_t i;
-       for(i=0; i<(blocksize_bit+7)/8; ++i){
-               uart_putc(tab[(block[i])>>4]);
-               uart_putc(tab[(block[i])&0xf]);
-       }                                  
-}
-
-#define SPACES 31
-#define BYTESPERLINE 16
-
-static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
-       uint8_t name_len;
-       uint8_t i;
-       name_len=strlen(name);
-       if(name_len>SPACES-1){
-               uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
-               return;
-       }
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<SPACES-name_len-1; ++i){
-               uart_putc(' ');
-       }
-       uart_putstr(name);
-       uart_putc('=');
-       /* now the data printing begins */
-       if(size_B<=BYTESPERLINE){
-               /* one line seems sufficient */
-               printblock(buffer, size_B*8);
-       } else {
-               /* we need more lines */
-               printblock(buffer, BYTESPERLINE*8); /* first line */
-               int16_t toprint = size_B - BYTESPERLINE;
-               buffer += BYTESPERLINE;
-               while(toprint > 0){
-                       uart_putstr_P(PSTR("\r\n"));
-                       for(i=0; i<SPACES; ++i){
-                               uart_putc(' ');
-                       }
-                       printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
-                       buffer  += BYTESPERLINE;
-                       toprint -= BYTESPERLINE;
-               }
-       }
-} 
-
-static void print_set_vector(uint8_t set, uint16_t vector){
-       uart_putstr_P(PSTR("\r\n\r\nSet "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR(", vector#"));
-       uart_putc((vector<100)?' ':'0'+vector/100);
-       uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
-       uart_putc('0'+vector%10);
-       uart_putc(':');
-}
-
-/* example:
-Test vectors -- set 3
-=====================
- */ 
-static void print_setheader(uint8_t set){
-       uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR("\r\n====================="));
-}
-
-/* example:
-********************************************************************************
-*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-********************************************************************************
-
-Primitive Name: Serpent
-=======================
-Key size: 256 bits
-Block size: 128 bits
-*/
-
-static void print_header(void){
-       uint16_t i;
-       uart_putstr_P(PSTR("\r\n\r\n"
-       "********************************************************************************\r\n"
-       "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte            *\r\n"
-       "********************************************************************************\r\n"
-       "\r\n"));
-       uart_putstr_P(PSTR("Primitive Name: "));
-       uart_putstr(nessie_mac_ctx.name);
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<16+strlen(nessie_mac_ctx.name); ++i){
-               uart_putc('=');
-       }
-       uart_putstr_P(PSTR("\r\nHash size: "));
-       if(nessie_mac_ctx.macsize_b >100){
-               uart_putc('0'+nessie_mac_ctx.macsize_b/100);
-       }
-       if(nessie_mac_ctx.macsize_b>10){
-               uart_putc('0'+(nessie_mac_ctx.macsize_b/10)%10);
-       }
-       uart_putc('0'+nessie_mac_ctx.macsize_b%10);
-       uart_putstr_P(PSTR(" bits\r\n"));
-}
-
-static void print_footer(void){
-       uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
-}
+#define PRINTKEY nessie_print_item("key", key, KEYSIZE_B)
+#define PRINTMAC nessie_print_item("MAC", mac, MACSIZE_B)
 
 static
 void ascii_mac(char* data, char* desc, uint8_t* key){
@@ -273,7 +165,7 @@ void tv4_mac(uint8_t* key){
                nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx);
                nessie_mac_ctx.mac_conv(mac, ctx);
        }
-       printitem("iterated 100000 times", mac, MACSIZE_B);
+       nessie_print_item("iterated 100000 times", mac, MACSIZE_B);
 }
 
 
@@ -285,7 +177,8 @@ void nessie_mac_run(void){
                           0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
        uint8_t key[KEYSIZE_B];
        
-       print_header();
+       nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0,
+                           nessie_mac_ctx.macsize_b, 0);
        /* test set 1 */
        char* challange[10][2]= {
                {"", "\"\" (empty string)"},
@@ -305,55 +198,55 @@ void nessie_mac_run(void){
                {"Now is the time for it", "\"Now is the time for it\""}
        };
        set=1;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<KEYSIZE_B; ++i){
                key[i] = keyproto[i%sizeof(keyproto)];
        }
        for(i=0; i<10; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                ascii_mac(challange[i][0], challange[i][1], key);
        }
-       print_set_vector(set, i);
+       nessie_print_set_vector(set, i);
        amillion_mac(key);
        for(i=0; i<KEYSIZE_B; ++i){
                key[i] = keyproto[16+i%8];
        }
        for(i=0; i<10; ++i){
-               print_set_vector(set, 11+i);
+               nessie_print_set_vector(set, 11+i);
                ascii_mac(challange[i][0], challange[i][1], key);
        }
-       print_set_vector(set, 11+i);
+       nessie_print_set_vector(set, 11+i);
        amillion_mac(key);
        /* test set 2 */
        set=2;
        for(i=0; i<KEYSIZE_B; ++i){
                key[i] = keyproto[i%sizeof(keyproto)];
        }
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<1024; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                zero_mac(i, key);
        }
        /* test set 3 */
        set=3;
-       print_setheader(set);
+       nessie_print_setheader(set);
        /* we use the same key as above */
        for(i=0; i<512; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                one_in512_mac(i, key);
        }
        /* test set 4 */
        set=4;
-       print_setheader(set);
+       nessie_print_setheader(set);
        /* we use the same key as above */
-       print_set_vector(set, 0);
+       nessie_print_set_vector(set, 0);
        tv4_mac(key);
        /* test set 5 */
        for(i=0; i<nessie_mac_ctx.keysize_b; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, KEYSIZE_B);
                key[i>>3]=0x80>>(i&0x7);
                ascii_mac("ABC", "\"ABC\"", key);
        }
-       print_footer();
+       nessie_print_footer();
 }
index b271dea2e86f621474e6f90145d39762b2669adc..3f7c7785e89a143d5559581769816d1f6226bbc8 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include "nessie_stream_test.h"
+#include "nessie_common.h"
 #include "uart.h"
 
 nessie_stream_ctx_t nessie_stream_ctx;
 
-static void printblock(uint8_t* block, uint16_t blocksize_bit){
-       char tab [] = {'0', '1', '2', '3', 
-                                  '4', '5', '6', '7', 
-                                  '8', '9', 'A', 'B', 
-                                  'C', 'D', 'E', 'F'};
-       uint16_t i;
-       for(i=0; i<(blocksize_bit+7)/8; ++i){
-               uart_putc(tab[(block[i])>>4]);
-               uart_putc(tab[(block[i])&0xf]);
-       }                                  
-}
 
-#define SPACES 31
-#define BYTESPERLINE 16
-
-static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
-       uint8_t name_len;
-       uint8_t i;
-       name_len=strlen(name);
-       if(name_len>SPACES-1){
-               uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
-               return;
-       }
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<SPACES-name_len-1; ++i){
-               uart_putc(' ');
-       }
-       uart_putstr(name);
-       uart_putc('=');
-       /* now the data printing begins */
-       if(size_B<=BYTESPERLINE){
-               /* one line seems sufficient */
-               printblock(buffer, size_B*8);
-       } else {
-               /* we need more lines */
-               printblock(buffer, BYTESPERLINE*8); /* first line */
-               int16_t toprint = size_B - BYTESPERLINE;
-               buffer += BYTESPERLINE;
-               while(toprint > 0){
-                       uart_putstr_P(PSTR("\r\n"));
-                       for(i=0; i<SPACES; ++i){
-                               uart_putc(' ');
-                       }
-                       printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
-                       buffer  += BYTESPERLINE;
-                       toprint -= BYTESPERLINE;
-               }
-       }
-} 
+#define BLOCKSIZE_B 64
 
 static
 void memxor(void* dest, void* src, uint8_t length){
@@ -71,9 +25,8 @@ void memxor(void* dest, void* src, uint8_t length){
                dest = (uint8_t*)dest +1;
                src  = (uint8_t*)src +1;
        }
-} 
+}
 
-#define BLOCKSIZE_B 64
 
 static 
 void nessie_gen_block(void* ctx, uint8_t* block){
@@ -92,13 +45,13 @@ void nessie_stream_enc(uint8_t* key){
        
        memset(xorbuffer, 0, BLOCKSIZE_B);
        
-       printitem("key", key, (nessie_stream_ctx.keysize_b+7)/8);
+       nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
        
        nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[0..63]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
        
        for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
                nessie_gen_block(ctx, buffer);
@@ -107,11 +60,11 @@ void nessie_stream_enc(uint8_t* key){
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[192..255]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[256..319]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
        
        for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
                nessie_gen_block(ctx, buffer);
@@ -120,9 +73,9 @@ void nessie_stream_enc(uint8_t* key){
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[448..511]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
        
-       printitem("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
+       nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
        
 }
 
@@ -136,13 +89,13 @@ void nessie_stream_enc_large(uint8_t* key){
        
        memset(xorbuffer, 0, BLOCKSIZE_B);
        
-       printitem("key", key, (nessie_stream_ctx.keysize_b+7)/8);
+       nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
        
        nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[0..63]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
        
        for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
                nessie_gen_block(ctx, buffer);
@@ -151,11 +104,11 @@ void nessie_stream_enc_large(uint8_t* key){
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[65472..65535]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[65536..65599]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
        
        for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
                nessie_gen_block(ctx, buffer);
@@ -164,100 +117,42 @@ void nessie_stream_enc_large(uint8_t* key){
        
        nessie_gen_block(ctx, buffer);
        memxor(xorbuffer, buffer, BLOCKSIZE_B);
-       printitem("stream[131008..131071]", buffer, BLOCKSIZE_B);
+       nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
        
-       printitem("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
+       nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
        
 }
 
-static void print_set_vector(uint8_t set, uint16_t vector){
-       uart_putstr_P(PSTR("\r\n\r\nSet "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR(", vector#"));
-       uart_putc((vector<100)?' ':'0'+vector/100);
-       uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
-       uart_putc('0'+vector%10);
-       uart_putc(':');
-}
-
-/* example:
-Test vectors -- set 3
-=====================
- */ 
-static void print_setheader(uint8_t set){
-       uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
-       uart_putc('0'+set%10);
-       uart_putstr_P(PSTR("\r\n====================="));
-}
-
-/* example:
-********************************************************************************
-*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
-********************************************************************************
-
-Primitive Name: Serpent
-=======================
-Key size: 256 bits
-Block size: 128 bits
-*/
-
-static void print_header(void){
-       uint16_t i;
-       uart_putstr_P(PSTR("\r\n\r\n"
-       "********************************************************************************\r\n"
-       "* micro-cryt - crypto primitives for microcontrolles by Daniel Otte            *\r\n"
-       "********************************************************************************\r\n"
-       "\r\n"));
-       uart_putstr_P(PSTR("Primitive Name: "));
-       uart_putstr(nessie_stream_ctx.name);
-       uart_putstr_P(PSTR("\r\n"));
-       for(i=0; i<16+strlen(nessie_stream_ctx.name); ++i){
-               uart_putc('=');
-       }
-       uart_putstr_P(PSTR("\r\nKey size: "));
-       if(nessie_stream_ctx.keysize_b>100){
-               uart_putc('0'+nessie_stream_ctx.keysize_b/100);
-       }
-       if(nessie_stream_ctx.keysize_b>10){
-               uart_putc('0'+(nessie_stream_ctx.keysize_b/10)%10);
-       }
-       uart_putc('0'+nessie_stream_ctx.keysize_b%10);
-       uart_putstr_P(PSTR(" bits\r\n"));
-}
-
-static void print_footer(void){
-       uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
-}
-
 void nessie_stream_run(void){
        uint16_t i;
        uint8_t set;
        uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
        
-       print_header();
+       nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
+                           0, 0, 0, 0);
        /* test set 1 */
        set=1;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, 0, (nessie_stream_ctx.keysize_b+7)/8);
                key[i/8] |= 0x80>>(i%8);
                nessie_stream_enc(key);
        }
        /* test set 2 */
        set=2;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<256; ++i){
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
                nessie_stream_enc(key);
        }
        /* test set 3 */
        set=3;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<256; ++i){
                uint8_t j;
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
                        key[j]=(i+j)&0xff;
                }
@@ -265,15 +160,15 @@ void nessie_stream_run(void){
        }
        /* test set 4 */
        set=4;
-       print_setheader(set);
+       nessie_print_setheader(set);
        for(i=0; i<4; ++i){
                uint8_t j;
-               print_set_vector(set, i);
+               nessie_print_set_vector(set, i);
                for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
                        key[j]=(i*5+j*0x53)&0xff;
                }
                nessie_stream_enc_large(key);
        }
 
-       print_footer();
+       nessie_print_footer();
 }
index 5975ec0e8604ea177400eb7ff23835f9c54c126c..ff6bd467b468c88be76968c00786fa11e88c7330 100644 (file)
@@ -7,7 +7,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := serpent.o serpent-sboxes-bitslice.o
 $(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
-                         serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o
+                         serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o \
+                         nessie_common.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
 
index dae003c8b6efa33e445c21d62d95d61222bdcc45..9d9dbaa5e80015d50eaad3057df5ade5d6782fc6 100644 (file)
--- a/sha256.mk
+++ b/sha256.mk
@@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := sha256-asm.o
 $(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
-                         sha256-asm.o nessie_hash_test.o
+                         sha256-asm.o nessie_hash_test.o nessie_common.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
 
diff --git a/xtea.mk b/xtea.mk
index e7b0a1d21fb437eea1996d6c867d783506014c24..0dd003efb65a8a4103f71a47fa5751d41ec3f544 100644 (file)
--- a/xtea.mk
+++ b/xtea.mk
@@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_OBJ      := xtea-asm.o
 $(ALGO_NAME)_TEST_BIN := main-xtea-test.o debug.o uart.o serial-tools.o \
-                         xtea-asm.o nessie_bc_test.o
+                         xtea-asm.o nessie_bc_test.o nessie_common.o
 $(ALGO_NAME)_NESSIE_TEST      := "nessie"
 $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"