static void groestl_small_rounds(uint8_t *m, uint8_t q){ uint8_t r,i,j; uint8_t tmp[8]; for(r=0; r<ROUNDS; ++r){ if(q){ for(i=0; i<64/4; ++i){ ((uint32_t*)m)[i] ^= 0xffffffff; } for(i=0;i<8; ++i){ m[7+i*8] ^= r ^ (i<<4); } }else{ for(i=0;i<8; ++i){ m[i*8] ^= r ^ (i<<4); } } #if DEBUG if(r<2){ cli_putstr("\r\npost add-const"); dump_m(m); } #endif for(i=0;i<8*8; ++i){ m[i] = aes_sbox[m[i]]; } if(q){ shift_columns(m, q_shifts); }else{ shift_columns(m, p_shifts); } #if DEBUG if(r<2){ cli_putstr("\r\npost shift-bytes"); dump_m(m); } #endif for(i=0; i<8; ++i){ memcpy(tmp, m+8*i, 8); for(j=0; j<8; ++j){ m[j+i*8] = gf256mul(matrix[8*j+0],tmp[0], POLYNOM) ^ gf256mul(matrix[8*j+1],tmp[1], POLYNOM) ^ gf256mul(matrix[8*j+2],tmp[2], POLYNOM) ^ gf256mul(matrix[8*j+3],tmp[3], POLYNOM) ^ gf256mul(matrix[8*j+4],tmp[4], POLYNOM) ^ gf256mul(matrix[8*j+5],tmp[5], POLYNOM) ^ gf256mul(matrix[8*j+6],tmp[6], POLYNOM) ^ gf256mul(matrix[8*j+7],tmp[7], POLYNOM); } } #if DEBUG if(r<2){ cli_putstr("\r\npost mix-bytes"); dump_m(m); } #endif } }
void groestl_small_ctx2hash(void* dest, const groestl_small_ctx_t* ctx, uint16_t outlength_b){ uint8_t tmp[64]; memcpy(tmp, ctx->h, 64); groestl_small_rounds(tmp, 0); memxor(tmp, ctx->h, 64); #if DEBUG cli_putstr("\r\npost finalisation"); dump_m(tmp); #endif memcpy(dest, tmp+64-outlength_b/8, outlength_b/8); }
void groestl_small_rounds(uint8_t *m, uint8_t q){ uint8_t r,i,j; uint8_t tmp[8]; #if DEBUG cli_putstr_P(PSTR("\r\n:: BEGIN ")); cli_putc(q?'Q':'P'); #endif for(r=0; r<ROUNDS; ++r){ if(q){ for(i=0; i<8*8; ++i){ m[i] ^= 0xff; } for(i=0; i<8; ++i){ m[7+i*8] ^= r ^ (i<<4); } }else{ for(i=0; i<8; ++i){ m[i*8] ^= r ^ (i<<4); } } #if DEBUG // if(r<2){ cli_putstr_P(PSTR("\r\npost add-const")); dump_m(m); // } #endif for(i=0;i<8*8; ++i){ m[i] = pgm_read_byte(aes_sbox+m[i]); } if(!q){ shift_columns(m, p_shifts); }else{ shift_columns(m, q_shifts); } #if DEBUG if(r<2){ cli_putstr_P(PSTR("\r\npost shift-bytes")); dump_m(m); } #endif for(i=0; i<8; ++i){ memcpy(tmp, m+8*i, 8); for(j=0; j<8; ++j){ m[j+i*8] = gf256mul(pgm_read_byte(matrix+8*j+0),tmp[0], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+1),tmp[1], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+2),tmp[2], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+3),tmp[3], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+4),tmp[4], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+5),tmp[5], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+6),tmp[6], POLYNOM) ^ gf256mul(pgm_read_byte(matrix+8*j+7),tmp[7], POLYNOM); } } #if DEBUG if(r<2){ cli_putstr_P(PSTR("\r\npost mix-bytes")); dump_m(m); } #endif } }