2 * BLAKE2 reference source code package - reference C implementations
4 * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
5 * You may use this under the terms of the CC0, the OpenSSL Licence, or the
6 * Apache Public License 2.0, at your option. The terms of these licenses can
9 * - OpenSSL license : https://www.openssl.org/source/license.html
10 * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11 * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
13 * More information about the BLAKE2 hash function can be found at
17 /* crypto/blake2/blake2_impl.h */
22 static inline uint32_t load32(const void *src)
26 memcpy(&w, src, sizeof(w));
29 const uint8_t *p = (const uint8_t *)src;
31 w |= (uint32_t)(*p++) << 8;
32 w |= (uint32_t)(*p++) << 16;
33 w |= (uint32_t)(*p++) << 24;
38 static inline uint64_t load64(const void *src)
42 memcpy(&w, src, sizeof(w));
45 const uint8_t *p = (const uint8_t *)src;
47 w |= (uint64_t)(*p++) << 8;
48 w |= (uint64_t)(*p++) << 16;
49 w |= (uint64_t)(*p++) << 24;
50 w |= (uint64_t)(*p++) << 32;
51 w |= (uint64_t)(*p++) << 40;
52 w |= (uint64_t)(*p++) << 48;
53 w |= (uint64_t)(*p++) << 56;
58 static inline void store32(void *dst, uint32_t w)
61 memcpy(dst, &w, sizeof(w));
63 uint8_t *p = (uint8_t *)dst;
74 static inline void store64(void *dst, uint64_t w)
77 memcpy(dst, &w, sizeof(w));
79 uint8_t *p = (uint8_t *)dst;
98 static inline uint64_t load48(const void *src)
100 const uint8_t *p = (const uint8_t *)src;
102 w |= (uint64_t)(*p++) << 8;
103 w |= (uint64_t)(*p++) << 16;
104 w |= (uint64_t)(*p++) << 24;
105 w |= (uint64_t)(*p++) << 32;
106 w |= (uint64_t)(*p++) << 40;
110 static inline void store48(void *dst, uint64_t w)
112 uint8_t *p = (uint8_t *)dst;
126 static inline uint32_t rotl32(const uint32_t w, const unsigned c)
128 return (w << c) | (w >> (32 - c));
131 static inline uint64_t rotl64(const uint64_t w, const unsigned c)
133 return (w << c) | (w >> (64 - c));
136 static inline uint32_t rotr32(const uint32_t w, const unsigned c)
138 return (w >> c) | (w << (32 - c));
141 static inline uint64_t rotr64(const uint64_t w, const unsigned c)
143 return (w >> c) | (w << (64 - c));