X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fnessie_mac_test.c;h=d3005428ccbc49f5e9fd64653d0e7711d9cd9f87;hb=83d0614d8b17eac97f891f7de2bb3ef265751dea;hp=f8cfb2835080b084fe26a44dd57b9a4490ca505d;hpb=cf1c79ef3fa4bb22f0cab28b2b6e958293aca739;p=avr-crypto-lib.git diff --git a/test_src/nessie_mac_test.c b/test_src/nessie_mac_test.c index f8cfb28..d300542 100644 --- a/test_src/nessie_mac_test.c +++ b/test_src/nessie_mac_test.c @@ -1,6 +1,6 @@ /* nessie_mac_test.c */ /* - This file is part of the Crypto-avr-lib/microcrypt-lib. + This file is part of the AVR-Crypto-Lib. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify @@ -27,6 +27,7 @@ * */ #include #include +#include #include "nessie_mac_test.h" #include "nessie_common.h" #include "uart.h" @@ -45,8 +46,8 @@ void ascii_mac(char* data, char* desc, uint8_t* key){ uint8_t mac[MACSIZE_B]; uint16_t sl; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(desc); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + NESSIE_PUTSTR(desc); PRINTKEY; nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx); sl = strlen(data); @@ -68,9 +69,10 @@ void amillion_mac(uint8_t* key){ uint8_t mac[MACSIZE_B]; uint8_t block[nessie_mac_ctx.blocksize_B]; uint32_t n=1000000LL; + uint16_t i=0; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("1 million times \"a\"")); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + NESSIE_PUTSTR_P(PSTR("1 million times \"a\"")); PRINTKEY; memset(block, 'a', nessie_mac_ctx.blocksize_B); @@ -78,6 +80,7 @@ void amillion_mac(uint8_t* key){ while(n>nessie_mac_ctx.blocksize_B){ nessie_mac_ctx.mac_next(block, ctx); n -= nessie_mac_ctx.blocksize_B; + NESSIE_SEND_ALIVE_A(i++); } nessie_mac_ctx.mac_last(block, n*8, key, nessie_mac_ctx.keysize_b, ctx); nessie_mac_ctx.mac_conv(mac, ctx); @@ -91,17 +94,17 @@ void zero_mac(uint16_t n, uint8_t* key){ uint8_t mac[MACSIZE_B]; uint8_t block[nessie_mac_ctx.blocksize_B]; - uart_putstr_P(PSTR("\r\n message=")); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); if(n>=10000) - uart_putc('0'+n/10000); + NESSIE_PUTC('0'+n/10000); if(n>=1000) - uart_putc('0'+(n/1000)%10); + NESSIE_PUTC('0'+(n/1000)%10); if(n>=100) - uart_putc('0'+(n/100)%10); + NESSIE_PUTC('0'+(n/100)%10); if(n>=10) - uart_putc('0'+(n/10)%10); - uart_putc('0'+n%10); - uart_putstr_P(PSTR(" zero bits")); + NESSIE_PUTC('0'+(n/10)%10); + NESSIE_PUTC('0'+n%10); + NESSIE_PUTSTR_P(PSTR(" zero bits")); PRINTKEY; memset(block, 0, nessie_mac_ctx.blocksize_B); @@ -125,24 +128,24 @@ void one_in512_mac(uint16_t pos, uint8_t* key){ "08", "04", "02", "01" }; pos&=511; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr_P(PSTR("512-bit string: ")); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + NESSIE_PUTSTR_P(PSTR("512-bit string: ")); if((pos/8) >=10){ - uart_putc('0'+(pos/8/10)%10); + NESSIE_PUTC('0'+(pos/8/10)%10); } else { - uart_putc(' '); + NESSIE_PUTC(' '); } - uart_putc('0'+(pos/8)%10); - uart_putstr_P(PSTR("*00,")); - uart_putstr(tab[pos&7]); - uart_putc(','); + NESSIE_PUTC('0'+(pos/8)%10); + NESSIE_PUTSTR_P(PSTR("*00,")); + NESSIE_PUTSTR(tab[pos&7]); + NESSIE_PUTC(','); if(63-(pos/8) >=10){ - uart_putc('0'+((63-pos/8)/10)%10); + NESSIE_PUTC('0'+((63-pos/8)/10)%10); } else { - uart_putc(' '); + NESSIE_PUTC(' '); } - uart_putc('0'+(63-pos/8)%10); - uart_putstr_P(PSTR("*00")); + NESSIE_PUTC('0'+(63-pos/8)%10); + NESSIE_PUTSTR_P(PSTR("*00")); PRINTKEY; /* now the real stuff */ @@ -162,18 +165,29 @@ void one_in512_mac(uint16_t pos, uint8_t* key){ } static -void tv4_mac(uint8_t* key){ +void tv4_mac(void){ uint8_t ctx[nessie_mac_ctx.ctx_size_B]; uint8_t mac[MACSIZE_B]; - uint8_t block[256/8]; - uint16_t n=256; + uint8_t block[MACSIZE_B]; + uint8_t core_key[] = { + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF + }; + uint8_t key[KEYSIZE_B]; + uint16_t n=MACSIZE_B*8; uint32_t i; + char str[6]; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(PSTR("256 zero bits")); - memset(block, 0, 256/8); - - nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + utoa(MACSIZE_B*8, str, 10); + NESSIE_PUTSTR(str); + NESSIE_PUTSTR_P(PSTR(" zero bits")); + memset(block, 0, MACSIZE_B); + for(i=0; inessie_mac_ctx.blocksize_B*8){ nessie_mac_ctx.mac_next(block, ctx); n -= nessie_mac_ctx.blocksize_B*8; @@ -185,6 +199,7 @@ void tv4_mac(uint8_t* key){ nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);; 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); + NESSIE_SEND_ALIVE_A(i); } nessie_print_item("iterated 100000 times", mac, MACSIZE_B); } @@ -262,8 +277,10 @@ void nessie_mac_run(void){ nessie_print_setheader(set); /* we use the same key as above */ nessie_print_set_vector(set, 0); - tv4_mac(key); + tv4_mac(); /* test set 5 */ + set=5; + nessie_print_setheader(set); for(i=0; i