/src/openssl/providers/implementations/digests/blake2_impl.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | /* |
11 | | * Derived from the BLAKE2 reference implementation written by Samuel Neves. |
12 | | * Copyright 2012, Samuel Neves <sneves@dei.uc.pt> |
13 | | * More information about the BLAKE2 hash function and its implementations |
14 | | * can be found at https://blake2.net. |
15 | | */ |
16 | | |
17 | | #if !defined(OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H) |
18 | | #define OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H |
19 | | |
20 | | #include <string.h> |
21 | | |
22 | | #include <openssl/e_os2.h> |
23 | | |
24 | | #include "internal/endian.h" |
25 | | |
26 | | static ossl_inline uint32_t load32(const uint8_t *src) |
27 | 0 | { |
28 | 0 | DECLARE_IS_ENDIAN; |
29 | |
|
30 | 0 | if (IS_LITTLE_ENDIAN) { |
31 | 0 | uint32_t w; |
32 | 0 | memcpy(&w, src, sizeof(w)); |
33 | 0 | return w; |
34 | 0 | } else { |
35 | 0 | uint32_t w = ((uint32_t)src[0]) |
36 | 0 | | ((uint32_t)src[1] << 8) |
37 | 0 | | ((uint32_t)src[2] << 16) |
38 | 0 | | ((uint32_t)src[3] << 24); |
39 | 0 | return w; |
40 | 0 | } |
41 | 0 | } Unexecuted instantiation: blake2b_prov.c:load32 Unexecuted instantiation: blake2s_prov.c:load32 |
42 | | |
43 | | static ossl_inline uint64_t load64(const uint8_t *src) |
44 | 0 | { |
45 | 0 | DECLARE_IS_ENDIAN; |
46 | |
|
47 | 0 | if (IS_LITTLE_ENDIAN) { |
48 | 0 | uint64_t w; |
49 | 0 | memcpy(&w, src, sizeof(w)); |
50 | 0 | return w; |
51 | 0 | } else { |
52 | 0 | uint64_t w = ((uint64_t)src[0]) |
53 | 0 | | ((uint64_t)src[1] << 8) |
54 | 0 | | ((uint64_t)src[2] << 16) |
55 | 0 | | ((uint64_t)src[3] << 24) |
56 | 0 | | ((uint64_t)src[4] << 32) |
57 | 0 | | ((uint64_t)src[5] << 40) |
58 | 0 | | ((uint64_t)src[6] << 48) |
59 | 0 | | ((uint64_t)src[7] << 56); |
60 | 0 | return w; |
61 | 0 | } |
62 | 0 | } Unexecuted instantiation: blake2b_prov.c:load64 Unexecuted instantiation: blake2s_prov.c:load64 |
63 | | |
64 | | static ossl_inline void store32(uint8_t *dst, uint32_t w) |
65 | 0 | { |
66 | 0 | DECLARE_IS_ENDIAN; |
67 | |
|
68 | 0 | if (IS_LITTLE_ENDIAN) { |
69 | 0 | memcpy(dst, &w, sizeof(w)); |
70 | 0 | } else { |
71 | 0 | uint8_t *p = (uint8_t *)dst; |
72 | 0 | int i; |
73 | |
|
74 | 0 | for (i = 0; i < 4; i++) |
75 | 0 | p[i] = (uint8_t)(w >> (8 * i)); |
76 | 0 | } |
77 | 0 | } Unexecuted instantiation: blake2b_prov.c:store32 Unexecuted instantiation: blake2s_prov.c:store32 |
78 | | |
79 | | static ossl_inline void store64(uint8_t *dst, uint64_t w) |
80 | 0 | { |
81 | 0 | DECLARE_IS_ENDIAN; |
82 | |
|
83 | 0 | if (IS_LITTLE_ENDIAN) { |
84 | 0 | memcpy(dst, &w, sizeof(w)); |
85 | 0 | } else { |
86 | 0 | uint8_t *p = (uint8_t *)dst; |
87 | 0 | int i; |
88 | |
|
89 | 0 | for (i = 0; i < 8; i++) |
90 | 0 | p[i] = (uint8_t)(w >> (8 * i)); |
91 | 0 | } |
92 | 0 | } Unexecuted instantiation: blake2b_prov.c:store64 Unexecuted instantiation: blake2s_prov.c:store64 |
93 | | |
94 | | static ossl_inline uint64_t load48(const uint8_t *src) |
95 | 0 | { |
96 | 0 | uint64_t w = ((uint64_t)src[0]) |
97 | 0 | | ((uint64_t)src[1] << 8) |
98 | 0 | | ((uint64_t)src[2] << 16) |
99 | 0 | | ((uint64_t)src[3] << 24) |
100 | 0 | | ((uint64_t)src[4] << 32) |
101 | 0 | | ((uint64_t)src[5] << 40); |
102 | 0 | return w; |
103 | 0 | } Unexecuted instantiation: blake2b_prov.c:load48 Unexecuted instantiation: blake2s_prov.c:load48 |
104 | | |
105 | | static ossl_inline void store48(uint8_t *dst, uint64_t w) |
106 | 0 | { |
107 | 0 | uint8_t *p = (uint8_t *)dst; |
108 | 0 | p[0] = (uint8_t)w; |
109 | 0 | p[1] = (uint8_t)(w >> 8); |
110 | 0 | p[2] = (uint8_t)(w >> 16); |
111 | 0 | p[3] = (uint8_t)(w >> 24); |
112 | 0 | p[4] = (uint8_t)(w >> 32); |
113 | 0 | p[5] = (uint8_t)(w >> 40); |
114 | 0 | } Unexecuted instantiation: blake2b_prov.c:store48 Unexecuted instantiation: blake2s_prov.c:store48 |
115 | | |
116 | | static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c) |
117 | 0 | { |
118 | 0 | return (w >> c) | (w << (32 - c)); |
119 | 0 | } Unexecuted instantiation: blake2b_prov.c:rotr32 Unexecuted instantiation: blake2s_prov.c:rotr32 |
120 | | |
121 | | static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c) |
122 | 0 | { |
123 | 0 | return (w >> c) | (w << (64 - c)); |
124 | 0 | } Unexecuted instantiation: blake2b_prov.c:rotr64 Unexecuted instantiation: blake2s_prov.c:rotr64 |
125 | | |
126 | | #endif /* !defined(OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H) */ |