-
-
Notifications
You must be signed in to change notification settings - Fork 665
/
blake2_common.h
45 lines (37 loc) · 945 Bytes
/
blake2_common.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
40
41
42
43
44
45
#include <stdint.h>
#include "byte_order.h"
static inline uint32_t load32(const void *src) {
uint32_t w;
memcpy(&w, src, sizeof w);
#if BYTE_ORDER == BIG_ENDIAN
REVERSE32(w, w);
#endif
return w;
}
static inline uint64_t load64(const void *src) {
uint64_t w;
memcpy(&w, src, sizeof w);
#if BYTE_ORDER == BIG_ENDIAN
REVERSE64(w, w);
#endif
return w;
}
static inline void store16(void *dst, uint16_t w) { memcpy(dst, &w, sizeof w); }
static inline void store32(void *dst, uint32_t w) {
#if BYTE_ORDER == BIG_ENDIAN
REVERSE32(w, w);
#endif
memcpy(dst, &w, sizeof w);
}
static inline void store64(void *dst, uint64_t w) {
#if BYTE_ORDER == BIG_ENDIAN
REVERSE64(w, w);
#endif
memcpy(dst, &w, sizeof w);
}
static inline uint32_t rotr32(const uint32_t w, const unsigned c) {
return (w >> c) | (w << (32 - c));
}
static inline uint64_t rotr64(const uint64_t w, const unsigned c) {
return (w >> c) | (w << (64 - c));
}