Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 68 lines (56 sloc) 2.121 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#ifndef __groestl_opt_h
#define __groestl_opt_h

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "brg_endian.h"
#define NEED_UINT_64T
//#include "brg_types.h"

#define u8 unsigned char
#define u32 unsigned int
#define u64 unsigned long long

/* some sizes (number of bytes) */
#define ROWS 8
#define LENGTHFIELDLEN ROWS
#define COLS512 8
#define COLS1024 16
#define SIZE512 (ROWS*COLS512)
#define SIZE1024 (ROWS*COLS1024)

#define ROUNDS512 10
#define ROUNDS1024 14

#define ROTL64(a,n) ((((a)<<(n))|((a)>>(64-(n))))&(0xffffffffffffffffULL))

#if (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
#define EXT_BYTE(var,n) ((u8)((u64)(var) >> (8*(7-(n)))))
#define U64BIG(a) (a)
#endif /* IS_BIG_ENDIAN */

#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
#define EXT_BYTE(var,n) ((u8)((u64)(var) >> (8*n)))
#define U64BIG(a) \
((ROTL64(a, 8) & (0x000000FF000000FFULL)) | \
(ROTL64(a,24) & (0x0000FF000000FF00ULL)) | \
(ROTL64(a,40) & (0x00FF000000FF0000ULL)) | \
(ROTL64(a,56) & (0xFF000000FF000000ULL)))
#endif /* IS_LITTLE_ENDIAN */

enum { LONG = SIZE1024, SHORT = SIZE512 };

/* NIST API begin */
typedef unsigned char BitSequence;
typedef unsigned long long DataLength;
typedef enum { HASH_SUCCESS = 0, HASH_FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
typedef struct {
  u64 *chaining __attribute__((aligned(16))); /* actual state */
  BitSequence *buffer; /* data buffer */
  u64 block_counter; /* message block counter */
  int buf_ptr; /* data buffer pointer */
  int bits_in_last_byte; /* no. of message bits in last byte of
data buffer */
  int hashbitlen; /* output length in bits */
  int size; /* LONG or SHORT */
} hashState;

HashReturn Init(hashState*, int);
HashReturn Update(hashState*, const BitSequence*, DataLength);
HashReturn Final(hashState*, BitSequence*);
HashReturn Hash(int, const BitSequence*, DataLength, BitSequence*);
/* NIST API end */

/* helper functions */
void PrintHash(const BitSequence*, int);

#endif /* __groestl_opt_h */
Something went wrong with that request. Please try again.