loadstore.h 759 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
#ifndef LOADSTORE_H_
#define LOADSTORE_H_

#include <stdint.h>

/* get byte from Ascon 64-bit word */
#define GETBYTE(x, i) ((uint8_t)((uint64_t)(x) >> (56 - 8 * (i))))

/* set byte in Ascon 64-bit word */
#define SETBYTE(b, i) ((uint64_t)(b) << (56 - 8 * (i)))

/* set padding byte in Ascon 64-bit word */
#define PAD(i) SETBYTE(0x80, i)

static inline uint64_t MASK(int n) {
  uint64_t x = 0;
  for (int i = 0; i < n; ++i) x |= SETBYTE(0xff, i);
  return x;
}

static inline uint64_t LOAD(const uint8_t* bytes, int n) {
  uint64_t x = 0;
  for (int i = 0; i < n; ++i) x |= SETBYTE(bytes[i], i);
  return x;
}

static inline void STORE(uint8_t* bytes, uint64_t x, int n) {
  for (int i = 0; i < n; ++i) bytes[i] = GETBYTE(x, i);
}

#endif /* LOADSTORE_H_ */