X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=twister-big.c;h=795190951d3263d4a78718ff887c0fc98bd25d7c;hb=e5a49deb52521f019e37779d6e9d81ec4f02aba4;hp=9eea96607a3d1b2ce57085b4e4d1d27b34586f15;hpb=288c82e97b3c37666b1c11475b45a956b3e5e8e0;p=avr-crypto-lib.git diff --git a/twister-big.c b/twister-big.c index 9eea966..7951909 100644 --- a/twister-big.c +++ b/twister-big.c @@ -1,4 +1,21 @@ /* twister-big.c */ +/* + 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 + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include #include @@ -6,85 +23,6 @@ #include "twister.h" #include "twister-big.h" -#undef DEBUG -#define DEBUG - -/*********************************************************************/ -/*********************************************************************/ - -#ifdef DEBUG -#include -#include "uart.h" -void print_checksum(twister_big_ctx_t* ctx, PGM_P s){ - uint8_t i; - uart_putstr_P(PSTR("\r\n")); - uart_putstr_P(s); - uart_putstr_P(PSTR("\r\n checksum:\r\n")); - for(i=0; i<8; ++i){ - uart_putstr_P(PSTR(" [ ")); - uart_hexdump(&(ctx->checksum[i][0]), 8); - uart_putstr_P(PSTR("]\r\n")); - } -} - -/*********************************************************************/ - -void print_matrix(void* m, PGM_P s){ - uint8_t i; - uart_putstr_P(PSTR("\r\n")); - uart_putstr_P(s); - uart_putstr_P(PSTR("\r\n matrix:\r\n")); - for(i=0; i<8; ++i){ - uart_putstr_P(PSTR(" [ ")); - uart_hexdump(((uint8_t*)m)+i*8, 8); - uart_putstr_P(PSTR("]\r\n")); - } -} - -/*********************************************************************/ - -#define DEBUG_CHKSUM(a,s) print_checksum((a),PSTR(s)) -#else -#define DEBUG_CHKSUM(a,s) -#endif - - -#ifdef DEBUG -# define DEBUG_PRINT(ctx, msg) debug_print((ctx), PSTR(msg)) -#else -# define DEBUG_PRINT(ctx, msg) -#endif - -#ifdef DEBUG - -/*********************************************************************/ - -void print_twister_state(twister_state_t* ctx){ - uint8_t i; - uart_putstr_P(PSTR("\r\nState:\r\n matrix:\r\n")); - for(i=0; i<8; ++i){ - uart_putstr_P(PSTR("\t[ ")); - uart_hexdump(&(ctx->s[i][0]), 8); - uart_putstr_P(PSTR("]\r\n")); - } - uart_putstr_P(PSTR("counter: ")); - uart_hexdump(&(ctx->counter), 8); - - uart_putstr_P(PSTR("\r\nlength_counter_b: ")); - uart_hexdump(&(ctx->length_counter_b), 8); - uart_putstr_P(PSTR("\r\n")); -} - -/*********************************************************************/ - -void debug_print(twister_state_t* ctx, PGM_P msg){ - uart_putstr_P(PSTR("\r\n")); - uart_putstr_P(msg); - print_twister_state(ctx); -} - -#endif - /*********************************************************************/ static @@ -104,7 +42,6 @@ void checksum_update(twister_big_ctx_t* ctx, uint8_t col){ carry = sum>>8; } -// DEBUG_CHKSUM(ctx, "post run"); } /*********************************************************************/ @@ -120,7 +57,7 @@ void twister_big_init(twister_big_ctx_t* ctx, uint16_t hashsize_b){ /*********************************************************************/ -void twister_big_nextBlock(twister_big_ctx_t* ctx, void* msg){ +void twister_big_nextBlock(twister_big_ctx_t* ctx, const void* msg){ uint8_t tmp[8][8]; /* 1st maxi round */ @@ -178,7 +115,7 @@ void twister_inject_chksum(twister_big_ctx_t* ctx, uint8_t col){ /*********************************************************************/ -void twister_big_lastBlock(twister_big_ctx_t* ctx, void* msg, uint16_t length_b){ +void twister_big_lastBlock(twister_big_ctx_t* ctx, const void* msg, uint16_t length_b){ uint8_t tmp[64]; while(length_b>512){ twister_big_nextBlock(ctx, msg); @@ -192,8 +129,6 @@ void twister_big_lastBlock(twister_big_ctx_t* ctx, void* msg, uint16_t length_b) ctx->state.length_counter_b -= 512 - length_b; twister_mini_round(&(ctx->state), &(ctx->state.length_counter_b)); -// DEBUG_PRINT(&(ctx->state), "pre check-round"); - memcpy(tmp, ctx->state.s, 64); twister_inject_chksum(ctx, 0); twister_inject_chksum(ctx, 1); @@ -212,8 +147,6 @@ void twister_big_lastBlock(twister_big_ctx_t* ctx, void* msg, uint16_t length_b) twister_blank_round(&(ctx->state)); memxor(ctx->state.s, tmp, 64); - -// DEBUG_PRINT(&(ctx->state), "post check-round"); } /*********************************************************************/ @@ -231,13 +164,13 @@ void twister384_init(twister384_ctx_t* ctx){ /*********************************************************************/ -void twister384_nextBlock(twister384_ctx_t* ctx, void* msg){ +void twister384_nextBlock(twister384_ctx_t* ctx, const void* msg){ twister_big_nextBlock(ctx, msg); } /*********************************************************************/ -void twister384_lastBlock(twister384_ctx_t* ctx, void* msg, uint16_t length_b){ +void twister384_lastBlock(twister384_ctx_t* ctx, const void* msg, uint16_t length_b){ twister_big_lastBlock(ctx, msg, length_b); } @@ -249,7 +182,7 @@ void twister384_ctx2hash(void* dest, twister384_ctx_t* ctx){ /*********************************************************************/ -void twister384(void* dest, void* msg, uint32_t msg_length_b){ +void twister384(void* dest, const void* msg, uint32_t msg_length_b){ twister_big_ctx_t ctx; twister_big_init(&ctx, 384); while(msg_length_b >=512){ @@ -271,13 +204,13 @@ void twister512_init(twister512_ctx_t* ctx){ /*********************************************************************/ -void twister512_nextBlock(twister512_ctx_t* ctx, void* msg){ +void twister512_nextBlock(twister512_ctx_t* ctx, const void* msg){ twister_big_nextBlock(ctx, msg); } /*********************************************************************/ -void twister512_lastBlock(twister512_ctx_t* ctx, void* msg, uint16_t length_b){ +void twister512_lastBlock(twister512_ctx_t* ctx, const void* msg, uint16_t length_b){ twister_big_lastBlock(ctx, msg, length_b); } @@ -289,7 +222,7 @@ void twister512_ctx2hash(void* dest, twister512_ctx_t* ctx){ /*********************************************************************/ -void twister512(void* dest, void* msg, uint32_t msg_length_b){ +void twister512(void* dest, const void* msg, uint32_t msg_length_b){ twister_big_ctx_t ctx; twister_big_init(&ctx, 512); while(msg_length_b >=512){