/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 | 23.5M | { |
28 | 23.5M | DECLARE_IS_ENDIAN; |
29 | | |
30 | 23.5M | if (IS_LITTLE_ENDIAN) { |
31 | 23.5M | uint32_t w; |
32 | 23.5M | memcpy(&w, src, sizeof(w)); |
33 | 23.5M | return w; |
34 | 23.5M | } 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 | 23.5M | } Unexecuted instantiation: blake2b_prov.c:load32 Line | Count | Source | 27 | 23.5M | { | 28 | 23.5M | DECLARE_IS_ENDIAN; | 29 | | | 30 | 23.5M | if (IS_LITTLE_ENDIAN) { | 31 | 23.5M | uint32_t w; | 32 | 23.5M | memcpy(&w, src, sizeof(w)); | 33 | 23.5M | return w; | 34 | 23.5M | } 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 | 23.5M | } |
|
42 | | |
43 | | static ossl_inline uint64_t load64(const uint8_t *src) |
44 | 15.9M | { |
45 | 15.9M | DECLARE_IS_ENDIAN; |
46 | | |
47 | 15.9M | if (IS_LITTLE_ENDIAN) { |
48 | 15.9M | uint64_t w; |
49 | 15.9M | memcpy(&w, src, sizeof(w)); |
50 | 15.9M | return w; |
51 | 15.9M | } 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 | 15.9M | } Line | Count | Source | 44 | 15.9M | { | 45 | 15.9M | DECLARE_IS_ENDIAN; | 46 | | | 47 | 15.9M | if (IS_LITTLE_ENDIAN) { | 48 | 15.9M | uint64_t w; | 49 | 15.9M | memcpy(&w, src, sizeof(w)); | 50 | 15.9M | return w; | 51 | 15.9M | } 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 | 15.9M | } |
Unexecuted instantiation: blake2s_prov.c:load64 |
63 | | |
64 | | static ossl_inline void store32(uint8_t *dst, uint32_t w) |
65 | 1.08k | { |
66 | 1.08k | DECLARE_IS_ENDIAN; |
67 | | |
68 | 1.08k | if (IS_LITTLE_ENDIAN) { |
69 | 1.08k | memcpy(dst, &w, sizeof(w)); |
70 | 1.08k | } 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 | 1.08k | } Line | Count | Source | 65 | 164 | { | 66 | 164 | DECLARE_IS_ENDIAN; | 67 | | | 68 | 164 | if (IS_LITTLE_ENDIAN) { | 69 | 164 | memcpy(dst, &w, sizeof(w)); | 70 | 164 | } 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 | 164 | } |
Line | Count | Source | 65 | 920 | { | 66 | 920 | DECLARE_IS_ENDIAN; | 67 | | | 68 | 920 | if (IS_LITTLE_ENDIAN) { | 69 | 920 | memcpy(dst, &w, sizeof(w)); | 70 | 920 | } 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 | 920 | } |
|
78 | | |
79 | | static ossl_inline void store64(uint8_t *dst, uint64_t w) |
80 | 820 | { |
81 | 820 | DECLARE_IS_ENDIAN; |
82 | | |
83 | 820 | if (IS_LITTLE_ENDIAN) { |
84 | 820 | memcpy(dst, &w, sizeof(w)); |
85 | 820 | } 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 | 820 | } Line | Count | Source | 80 | 820 | { | 81 | 820 | DECLARE_IS_ENDIAN; | 82 | | | 83 | 820 | if (IS_LITTLE_ENDIAN) { | 84 | 820 | memcpy(dst, &w, sizeof(w)); | 85 | 820 | } 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 | 820 | } |
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 | 184 | { |
107 | 184 | uint8_t *p = (uint8_t *)dst; |
108 | 184 | p[0] = (uint8_t)w; |
109 | 184 | p[1] = (uint8_t)(w >> 8); |
110 | 184 | p[2] = (uint8_t)(w >> 16); |
111 | 184 | p[3] = (uint8_t)(w >> 24); |
112 | 184 | p[4] = (uint8_t)(w >> 32); |
113 | 184 | p[5] = (uint8_t)(w >> 40); |
114 | 184 | } Unexecuted instantiation: blake2b_prov.c:store48 Line | Count | Source | 106 | 184 | { | 107 | 184 | uint8_t *p = (uint8_t *)dst; | 108 | 184 | p[0] = (uint8_t)w; | 109 | 184 | p[1] = (uint8_t)(w >> 8); | 110 | 184 | p[2] = (uint8_t)(w >> 16); | 111 | 184 | p[3] = (uint8_t)(w >> 24); | 112 | 184 | p[4] = (uint8_t)(w >> 32); | 113 | 184 | p[5] = (uint8_t)(w >> 40); | 114 | 184 | } |
|
115 | | |
116 | | static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c) |
117 | 471M | { |
118 | 471M | return (w >> c) | (w << (32 - c)); |
119 | 471M | } Unexecuted instantiation: blake2b_prov.c:rotr32 Line | Count | Source | 117 | 471M | { | 118 | 471M | return (w >> c) | (w << (32 - c)); | 119 | 471M | } |
|
120 | | |
121 | | static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c) |
122 | 382M | { |
123 | 382M | return (w >> c) | (w << (64 - c)); |
124 | 382M | } Line | Count | Source | 122 | 382M | { | 123 | 382M | return (w >> c) | (w << (64 - c)); | 124 | 382M | } |
Unexecuted instantiation: blake2s_prov.c:rotr64 |
125 | | |
126 | | #endif /* !defined(OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H) */ |