-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.h
39 lines (30 loc) · 979 Bytes
/
word.h
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
#ifndef WORD_H_
#define WORD_H_
#include <stdint.h>
/* get byte from 64-bit Ascon word */
#define GETBYTE(x, i) ((uint8_t)((uint64_t)(x) >> (56 - 8 * (i))))
/* set byte in 64-bit Ascon word */
#define SETBYTE(b, i) ((uint64_t)(b) << (56 - 8 * (i)))
/* set padding byte in 64-bit Ascon word */
#define PAD(i) SETBYTE(0x80, i)
/* define domain separation bit in 64-bit Ascon word */
#define DSEP() SETBYTE(0x01, 7)
/* load bytes into 64-bit Ascon word */
static inline uint64_t LOADBYTES(const uint8_t* bytes, int n) {
int i;
uint64_t x = 0;
for (i = 0; i < n; ++i) x |= SETBYTE(bytes[i], i);
return x;
}
/* store bytes from 64-bit Ascon word */
static inline void STOREBYTES(uint8_t* bytes, uint64_t x, int n) {
int i;
for (i = 0; i < n; ++i) bytes[i] = GETBYTE(x, i);
}
/* clear bytes in 64-bit Ascon word */
static inline uint64_t CLEARBYTES(uint64_t x, int n) {
int i;
for (i = 0; i < n; ++i) x &= ~SETBYTE(0xff, i);
return x;
}
#endif /* WORD_H_ */