2 * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
3 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
5 * Licensed under the OpenSSL licenses, (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * https://www.openssl.org/source/license.html
9 * or in the file LICENSE in the source distribution.
13 * Derived from the BLAKE2 reference implementation written by Samuel Neves.
14 * More information about the BLAKE2 hash function and its implementations
15 * can be found at https://blake2.net.
21 static ossl_inline uint32_t load32(const void *src)
28 if (is_endian.little) {
30 memcpy(&w, src, sizeof(w));
33 const uint8_t *p = (const uint8_t *)src;
35 w |= (uint32_t)(*p++) << 8;
36 w |= (uint32_t)(*p++) << 16;
37 w |= (uint32_t)(*p++) << 24;
42 static ossl_inline uint64_t load64(const void *src)
49 if (is_endian.little) {
51 memcpy(&w, src, sizeof(w));
54 const uint8_t *p = (const uint8_t *)src;
56 w |= (uint64_t)(*p++) << 8;
57 w |= (uint64_t)(*p++) << 16;
58 w |= (uint64_t)(*p++) << 24;
59 w |= (uint64_t)(*p++) << 32;
60 w |= (uint64_t)(*p++) << 40;
61 w |= (uint64_t)(*p++) << 48;
62 w |= (uint64_t)(*p++) << 56;
67 static ossl_inline void store32(void *dst, uint32_t w)
74 if (is_endian.little) {
75 memcpy(dst, &w, sizeof(w));
77 uint8_t *p = (uint8_t *)dst;
80 for (i = 0; i < 4; i++)
81 p[i] = (uint8_t)(w >> (8 * i));
85 static ossl_inline void store64(void *dst, uint64_t w)
92 if (is_endian.little) {
93 memcpy(dst, &w, sizeof(w));
95 uint8_t *p = (uint8_t *)dst;
98 for (i = 0; i < 8; i++)
99 p[i] = (uint8_t)(w >> (8 * i));
103 static ossl_inline uint64_t load48(const void *src)
105 const uint8_t *p = (const uint8_t *)src;
107 w |= (uint64_t)(*p++) << 8;
108 w |= (uint64_t)(*p++) << 16;
109 w |= (uint64_t)(*p++) << 24;
110 w |= (uint64_t)(*p++) << 32;
111 w |= (uint64_t)(*p++) << 40;
115 static ossl_inline void store48(void *dst, uint64_t w)
117 uint8_t *p = (uint8_t *)dst;
131 static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned c)
133 return (w >> c) | (w << (32 - c));
136 static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned c)
138 return (w >> c) | (w << (64 - c));