#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"
#endif
-#undef DEBUG
-
static uint64_t rc[] PROGMEM = {
0x0000000000000001LL, 0x0000000000008082LL,
0x800000000000808ALL, 0x8000000080008000LL,
};
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
pad[0] = ctx->d;
pad[1] = ctx->bs;
pad[2] = 0x01;
- if(length_b/8+1+3<ctx->bs){
+ if(length_b/8+1+3<=ctx->bs){
memcpy(tmp+length_b/8+1, pad, 3);
}else{
- if(length_b/8+1+2<ctx->bs){
+ 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+1<ctx->bs){
+ 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);
}
}
keccak_nextBlock(ctx, tmp);
- keccak_dump_ctx(ctx);
}
void keccak_ctx2hash(void* dest, uint16_t length_b, keccak_ctx_t* ctx){