X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=keccak%2Fkeccak.c;h=7983b0111cf46d2c0d21bfa20edbb400507fd59b;hb=2ba0b7c62ea7479bb2d604e414b0dd7ac29aafe8;hp=59c357ecbaeb4dfe822c56b77f44f06421419f4a;hpb=1b51cba0fd060fa2d4aeb085bb51a634c542181d;p=avr-crypto-lib.git diff --git a/keccak/keccak.c b/keccak/keccak.c index 59c357e..7983b01 100644 --- a/keccak/keccak.c +++ b/keccak/keccak.c @@ -24,14 +24,11 @@ #include "memxor.h" #include "keccak.h" -#define W 64 - #ifdef DEBUG # undef DEBUG #endif -#define DEBUG 1 - +#define DEBUG 0 #if DEBUG #include "cli.h" @@ -63,8 +60,6 @@ void keccak_dump_ctx(keccak_ctx_t* ctx){ #endif -#undef DEBUG - static uint64_t rc[] PROGMEM = { 0x0000000000000001LL, 0x0000000000008082LL, 0x800000000000808ALL, 0x8000000080008000LL, @@ -93,18 +88,18 @@ static uint8_t r[5][5] PROGMEM = { }; void keccak_round(uint64_t a[5][5], uint8_t rci){ - uint64_t c[5], d[5], b[5][5]; + uint64_t b[5][5]; uint8_t i,j; /* theta */ for(i=0; i<5; ++i){ - c[i] = a[0][i] ^ a[1][i] ^ a[2][i] ^ a[3][i] ^ a[4][i]; + b[i][0] = a[0][i] ^ a[1][i] ^ a[2][i] ^ a[3][i] ^ a[4][i]; } for(i=0; i<5; ++i){ - d[i] = c[(4+i)%5] ^ rotl64(c[(i+1)%5], 1); + b[i][1] = b[(4+i)%5][0] ^ rotl64(b[(i+1)%5][0], 1); } for(i=0; i<5; ++i){ for(j=0; j<5; ++j){ - a[j][i] ^= d[i]; + a[j][i] ^= b[i][1]; } } #if DEBUG @@ -181,16 +176,16 @@ void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){ pad[0] = ctx->d; pad[1] = ctx->bs; pad[2] = 0x01; - if(length_b/8+1+3bs){ + if(length_b/8+1+3<=ctx->bs){ memcpy(tmp+length_b/8+1, pad, 3); }else{ - if(length_b/8+1+2bs){ + if(length_b/8+1+2<=ctx->bs){ memcpy(tmp+length_b/8+1, pad, 2); keccak_nextBlock(ctx, tmp); memset(tmp, 0x00, ctx->bs); tmp[0]=0x01; }else{ - if(length_b/8+1+1bs){ + if(length_b/8+1+1<=ctx->bs){ memcpy(tmp+length_b/8+1, pad, 1); keccak_nextBlock(ctx, tmp); memset(tmp, 0x00, ctx->bs); @@ -206,7 +201,6 @@ void keccak_lastBlock(keccak_ctx_t* ctx, const void* block, uint16_t length_b){ } } keccak_nextBlock(ctx, tmp); - keccak_dump_ctx(ctx); } void keccak_ctx2hash(void* dest, uint16_t length_b, keccak_ctx_t* ctx){