Exemple #1
0
/* initialise context */
HashReturn Init(hashState* ctx) {
  u8 i = 0;

  /* output size (in bits) must be a positive integer less than or
     equal to 512, and divisible by 8 */
  if (LENGTH <= 0 || (LENGTH%8) || LENGTH > 512)
    return BAD_HASHLEN;

  /* set number of state columns and state size depending on
     variant */
  ctx->columns = COLS;
  ctx->statesize = SIZE;
#if (LENGTH <= 256)
    ctx->v = SHORT;
#else
    ctx->v = LONG;
#endif

  SET_CONSTANTS();

  for (i=0; i<SIZE/8; i++)
    ctx->chaining[i] = 0;
  for (i=0; i<SIZE; i++)
    ctx->buffer[i] = 0;

  if (ctx->chaining == NULL || ctx->buffer == NULL)
    return FAIL;

  /* set initial value */
  ctx->chaining[ctx->columns-1] = U64BIG((u64)LENGTH);

  INIT(ctx->chaining);

  /* set other variables */
  ctx->buf_ptr = 0;
  ctx->block_counter = 0;
  ctx->bits_in_last_byte = 0;

  return SUCCESS;
}
Exemple #2
0
HashReturn_gr init_groestl( hashState_groestl* ctx, int hashlen )
{
  int i;

  ctx->hashlen = hashlen;
  SET_CONSTANTS();

  if (ctx->chaining == NULL || ctx->buffer == NULL)
    return FAIL_GR;

  for ( i = 0; i < SIZE512; i++ )
  {
     ctx->chaining[i] = _mm_setzero_si128();
     ctx->buffer[i]   = _mm_setzero_si128();
  }
  ((u64*)ctx->chaining)[COLS-1] = U64BIG((u64)LENGTH);
  INIT(ctx->chaining);
  ctx->buf_ptr = 0;
  ctx->rem_ptr = 0;

  return SUCCESS_GR;
}