word.h 990 Bytes
Newer Older
Martin Schläffer 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 47
#ifndef WORD_H_
#define WORD_H_

#include <stdint.h>

#include "config.h"

typedef uint64_t word_t;

#define WORD_T
#define UINT64_T

#define U64TOWORD
#define WORDTOU64

#define XOR(a, b) \
  do {            \
    (a) ^= (b);   \
  } while (0)

#define AND(a, b) \
  do {            \
    (a) &= (b);   \
  } while (0)

__forceinline word_t ROR64(word_t x, int n) { return x >> n | x << (64 - n); }

__forceinline word_t KEYROT(word_t lo2hi, word_t hi2lo) {
  return lo2hi << 32 | hi2lo >> 32;
}

__forceinline int NOTZERO(word_t a, word_t b) {
  int result = 0;
  for (int i = 0; i < 8; ++i) result |= ((uint8_t*)&a)[i];
  for (int i = 0; i < 8; ++i) result |= ((uint8_t*)&b)[i];
  return result;
}

/* set padding byte in 64-bit Ascon word */
__forceinline word_t PAD(int i) { return WORD_T(0x80ull << (56 - 8 * i)); }

/* byte mask for 64-bit Ascon word (1 <= n <= 8) */
__forceinline word_t XMASK(int n) {
  return WORD_T(0x00ffffffffffffffull >> (n * 8 - 8));
}

#endif /* WORD_H_ */