X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=test_src%2Fnessie_hash_test.c;h=27df4c1d9cf5044bd99199d0b7016d74d594b1c7;hb=5c68d38237aa51b91a26309c24e8e38c7fbdffbe;hp=a870b8283ca58dc09ce69b76bee89f8ee4d30cd2;hpb=2159c273c9d3361571a6ff1ab63d9bc76582fbab;p=avr-crypto-lib.git diff --git a/test_src/nessie_hash_test.c b/test_src/nessie_hash_test.c index a870b82..27df4c1 100644 --- a/test_src/nessie_hash_test.c +++ b/test_src/nessie_hash_test.c @@ -1,6 +1,6 @@ /* nessie_hash_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 @@ -29,26 +29,32 @@ #include #include "nessie_hash_test.h" #include "nessie_common.h" -#include "uart.h" +#include "dbz_strings.h" nessie_hash_ctx_t nessie_hash_ctx; +#define HASHSIZE_B ((nessie_hash_ctx.hashsize_b+7)/8) +#define BLOCKSIZE_B (nessie_hash_ctx.blocksize_B) + static -void ascii_hash(char* data, char* desc){ +void ascii_hash_P(PGM_P data, PGM_P desc){ uint8_t ctx[nessie_hash_ctx.ctx_size_B]; - uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; + uint8_t hash[HASHSIZE_B]; uint16_t sl; + uint8_t buffer[BLOCKSIZE_B]; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(desc); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + NESSIE_PUTSTR_P(desc); nessie_hash_ctx.hash_init(ctx); - sl = strlen(data); - while(sl>=nessie_hash_ctx.blocksize_B){ - nessie_hash_ctx.hash_next(data, ctx); - data += nessie_hash_ctx.blocksize_B; - sl -= nessie_hash_ctx.blocksize_B; + sl = strlen_P(data); + while(sl>=BLOCKSIZE_B){ + memcpy_P(buffer, data, BLOCKSIZE_B); + nessie_hash_ctx.hash_next(ctx, buffer); + data += BLOCKSIZE_B; + sl -= BLOCKSIZE_B; } - nessie_hash_ctx.hash_last(data, sl*8, ctx); + memcpy_P(buffer, data, sl); + nessie_hash_ctx.hash_last(ctx, buffer, sl*8); nessie_hash_ctx.hash_conv(hash, ctx); nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); } @@ -61,16 +67,18 @@ void amillion_hash(void){ uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; uint8_t block[nessie_hash_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\"")); memset(block, 'a', nessie_hash_ctx.blocksize_B); nessie_hash_ctx.hash_init(ctx); while(n>=nessie_hash_ctx.blocksize_B){ - nessie_hash_ctx.hash_next(block, ctx); + nessie_hash_ctx.hash_next(ctx, block); n -= nessie_hash_ctx.blocksize_B; + NESSIE_SEND_ALIVE_A(i++); } - nessie_hash_ctx.hash_last(block, n*8, ctx); + nessie_hash_ctx.hash_last(ctx, block, n*8); nessie_hash_ctx.hash_conv(hash, ctx); nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); } @@ -82,25 +90,25 @@ void zero_hash(uint16_t n){ uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; uint8_t block[nessie_hash_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")); memset(block, 0, nessie_hash_ctx.blocksize_B); nessie_hash_ctx.hash_init(ctx); while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); + nessie_hash_ctx.hash_next(ctx, block); n -= nessie_hash_ctx.blocksize_B*8; } - nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_last(ctx, block, n); nessie_hash_ctx.hash_conv(hash, ctx); nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); } @@ -115,34 +123,34 @@ void one_in512_hash(uint16_t pos){ "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")); /* now the real stuff */ memset(block, 0, 512/8); block[pos>>3] = 0x80>>(pos&0x7); nessie_hash_ctx.hash_init(ctx); while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); + nessie_hash_ctx.hash_next(ctx, block); n -= nessie_hash_ctx.blocksize_B*8; } - nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_last(ctx, block, n); nessie_hash_ctx.hash_conv(hash, ctx); nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8); } @@ -151,26 +159,37 @@ static void tv4_hash(void){ uint8_t ctx[nessie_hash_ctx.ctx_size_B]; uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8]; - uint8_t block[256/8]; - uint16_t n=256; + uint8_t block[nessie_hash_ctx.hashsize_b/8]; + uint16_t n=nessie_hash_ctx.hashsize_b; uint32_t i; - uart_putstr_P(PSTR("\r\n message=")); - uart_putstr(PSTR("256 zero bits")); + NESSIE_PUTSTR_P(PSTR("\r\n message=")); + if(nessie_hash_ctx.hashsize_b>=10000) + NESSIE_PUTC('0' + (nessie_hash_ctx.hashsize_b/10000)%10); + if(nessie_hash_ctx.hashsize_b>=1000) + NESSIE_PUTC('0' + (nessie_hash_ctx.hashsize_b/1000)%10); + if(nessie_hash_ctx.hashsize_b>=100) + NESSIE_PUTC('0' + (nessie_hash_ctx.hashsize_b/100)%10); + if(nessie_hash_ctx.hashsize_b>=10) + NESSIE_PUTC('0' + (nessie_hash_ctx.hashsize_b/10)%10); + NESSIE_PUTC('0' + nessie_hash_ctx.hashsize_b%10); + + NESSIE_PUTSTR_P(PSTR(" zero bits")); memset(block, 0, 256/8); nessie_hash_ctx.hash_init(ctx); while(n>=nessie_hash_ctx.blocksize_B*8){ - nessie_hash_ctx.hash_next(block, ctx); + nessie_hash_ctx.hash_next(ctx, block); n -= nessie_hash_ctx.blocksize_B*8; } - nessie_hash_ctx.hash_last(block, n, ctx); + nessie_hash_ctx.hash_last(ctx, block, n); nessie_hash_ctx.hash_conv(hash, ctx); 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_last(ctx, hash, nessie_hash_ctx.hashsize_b); nessie_hash_ctx.hash_conv(hash, ctx); + NESSIE_SEND_ALIVE_A(i); } nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8); } @@ -193,26 +212,34 @@ void nessie_hash_run(void){ 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)"}, - {"a", "\"a\""}, - {"abc", "\"abc\""}, - {"message digest", "\"message digest\""}, - {"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""}, - {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" , "\"A...Za...z0...9\""}, - {"1234567890" "1234567890" "1234567890" "1234567890" - "1234567890" "1234567890" "1234567890" "1234567890", - "8 times \"1234567890\""} - }; + char* challange_dbz= PSTR( + "\0" + "\"\" (empty string)\0" + "a\0" + "\"a\"\0" + "abc\0" + "\"abc\"\0" + "message digest\0" + "\"message digest\"\0" + "abcdefghijklmnopqrstuvwxyz\0" + "\"abcdefghijklmnopqrstuvwxyz\"\0" + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\0" + "\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\"\0" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789\0" + "\"A...Za...z0...9\"\0" + "1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890\0" + "8 times \"1234567890\"\0" + ); + PGM_P challange[16]; set=1; nessie_print_setheader(set); + dbz_splitup_P(challange_dbz, challange); for(i=0; i<8; ++i){ nessie_print_set_vector(set, i); - ascii_hash(challange[i][0], challange[i][1]); + ascii_hash_P(challange[2*i], challange[2*i+1]); } nessie_print_set_vector(set, i); amillion_hash();