permutations.h 812 Bytes
Newer Older
Ferdinand Bachmann committed
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
#ifndef PERMUTATIONS_H_
#define PERMUTATIONS_H_

typedef unsigned char u8;
typedef unsigned int u32;
typedef unsigned long long u64;

typedef struct {
  u32 h;
  u32 l;
} u32_2;

typedef struct {
  u32_2 x0;
  u32_2 x1;
  u32_2 x2;
  u32_2 x3;
  u32_2 x4;
} state;

#define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#define START_ROUND(x) (12 - (x))

u32_2 to_big(u64 in);
u64 from_big(u32_2 in);

#define to_big_immediate(out, in) \
  do { \
    u64 big_in = U64BIG(in); \
    u32 hi = (big_in) >> 32; \
    u32 lo = (u32)(big_in); \
    out.h = hi; \
    out.l = lo; \
  } while (0)

#define from_big_immediate(out, in) \
  do { \
    u32 hi = in.h; \
    u32 lo = in.l; \
    out = (u64)hi << 32 | lo; \
    out = U64BIG(out); \
  } while (0)

void P(state *p, u8 rounds);

#endif  // PERMUTATIONS_H_