/src/botan/build/include/botan/internal/loadstor.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Load/Store Operators |
3 | | * (C) 1999-2007,2015,2017 Jack Lloyd |
4 | | * 2007 Yves Jerschow |
5 | | * |
6 | | * Botan is released under the Simplified BSD License (see license.txt) |
7 | | */ |
8 | | |
9 | | #ifndef BOTAN_LOAD_STORE_H_ |
10 | | #define BOTAN_LOAD_STORE_H_ |
11 | | |
12 | | #include <botan/types.h> |
13 | | #include <botan/internal/bswap.h> |
14 | | #include <botan/mem_ops.h> |
15 | | #include <vector> |
16 | | |
17 | | #if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) |
18 | | #define BOTAN_ENDIAN_N2L(x) reverse_bytes(x) |
19 | | #define BOTAN_ENDIAN_L2N(x) reverse_bytes(x) |
20 | | #define BOTAN_ENDIAN_N2B(x) (x) |
21 | | #define BOTAN_ENDIAN_B2N(x) (x) |
22 | | |
23 | | #elif defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) |
24 | 6.88k | #define BOTAN_ENDIAN_N2L(x) (x) |
25 | 2.81k | #define BOTAN_ENDIAN_L2N(x) (x) |
26 | 18.4M | #define BOTAN_ENDIAN_N2B(x) reverse_bytes(x) |
27 | 3.90M | #define BOTAN_ENDIAN_B2N(x) reverse_bytes(x) |
28 | | |
29 | | #endif |
30 | | |
31 | | namespace Botan { |
32 | | |
33 | | /** |
34 | | * Byte extraction |
35 | | * @param byte_num which byte to extract, 0 == highest byte |
36 | | * @param input the value to extract from |
37 | | * @return byte byte_num of input |
38 | | */ |
39 | | template<typename T> inline constexpr uint8_t get_byte_var(size_t byte_num, T input) |
40 | 4.02M | { |
41 | 4.02M | return static_cast<uint8_t>( |
42 | 4.02M | input >> (((~byte_num)&(sizeof(T)-1)) << 3) |
43 | 4.02M | ); |
44 | 4.02M | } unsigned char Botan::get_byte_var<unsigned long>(unsigned long, unsigned long) Line | Count | Source | 40 | 504k | { | 41 | 504k | return static_cast<uint8_t>( | 42 | 504k | input >> (((~byte_num)&(sizeof(T)-1)) << 3) | 43 | 504k | ); | 44 | 504k | } |
unsigned char Botan::get_byte_var<unsigned int>(unsigned long, unsigned int) Line | Count | Source | 40 | 966 | { | 41 | 966 | return static_cast<uint8_t>( | 42 | 966 | input >> (((~byte_num)&(sizeof(T)-1)) << 3) | 43 | 966 | ); | 44 | 966 | } |
unsigned char Botan::get_byte_var<unsigned char>(unsigned long, unsigned char) Line | Count | Source | 40 | 3.52M | { | 41 | 3.52M | return static_cast<uint8_t>( | 42 | 3.52M | input >> (((~byte_num)&(sizeof(T)-1)) << 3) | 43 | 3.52M | ); | 44 | 3.52M | } |
Unexecuted instantiation: unsigned char Botan::get_byte_var<unsigned short>(unsigned long, unsigned short) |
45 | | |
46 | | /** |
47 | | * Byte extraction |
48 | | * @param byte_num which byte to extract, 0 == highest byte |
49 | | * @param input the value to extract from |
50 | | * @return byte byte_num of input |
51 | | */ |
52 | | template<size_t B, typename T> inline constexpr uint8_t get_byte(T input) |
53 | 2.06M | { |
54 | 2.06M | static_assert(B < sizeof(T), "Valid byte offset"); |
55 | | |
56 | 2.06M | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; |
57 | 2.06M | return static_cast<uint8_t>((input >> shift) & 0xFF); |
58 | 2.06M | } unsigned char Botan::get_byte<0ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 283k | { | 54 | 283k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 283k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 283k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 283k | } |
unsigned char Botan::get_byte<0ul, unsigned int>(unsigned int) Line | Count | Source | 53 | 82.7k | { | 54 | 82.7k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 82.7k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 82.7k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 82.7k | } |
unsigned char Botan::get_byte<1ul, unsigned int>(unsigned int) Line | Count | Source | 53 | 210k | { | 54 | 210k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 210k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 210k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 210k | } |
unsigned char Botan::get_byte<2ul, unsigned int>(unsigned int) Line | Count | Source | 53 | 210k | { | 54 | 210k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 210k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 210k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 210k | } |
unsigned char Botan::get_byte<3ul, unsigned int>(unsigned int) Line | Count | Source | 53 | 210k | { | 54 | 210k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 210k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 210k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 210k | } |
unsigned char Botan::get_byte<1ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<2ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<3ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<4ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<5ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<6ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<7ul, unsigned long>(unsigned long) Line | Count | Source | 53 | 54.2k | { | 54 | 54.2k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 54.2k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 54.2k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 54.2k | } |
unsigned char Botan::get_byte<0ul, unsigned short>(unsigned short) Line | Count | Source | 53 | 344k | { | 54 | 344k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 344k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 344k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 344k | } |
unsigned char Botan::get_byte<1ul, unsigned short>(unsigned short) Line | Count | Source | 53 | 344k | { | 54 | 344k | static_assert(B < sizeof(T), "Valid byte offset"); | 55 | | | 56 | 344k | const size_t shift = ((~B) & (sizeof(T) - 1)) << 3; | 57 | 344k | return static_cast<uint8_t>((input >> shift) & 0xFF); | 58 | 344k | } |
|
59 | | |
60 | | /** |
61 | | * Make a uint16_t from two bytes |
62 | | * @param i0 the first byte |
63 | | * @param i1 the second byte |
64 | | * @return i0 || i1 |
65 | | */ |
66 | | inline constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1) |
67 | 815k | { |
68 | 815k | return static_cast<uint16_t>((static_cast<uint16_t>(i0) << 8) | i1); |
69 | 815k | } |
70 | | |
71 | | /** |
72 | | * Make a uint32_t from four bytes |
73 | | * @param i0 the first byte |
74 | | * @param i1 the second byte |
75 | | * @param i2 the third byte |
76 | | * @param i3 the fourth byte |
77 | | * @return i0 || i1 || i2 || i3 |
78 | | */ |
79 | | inline constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3) |
80 | 87.3k | { |
81 | 87.3k | return ((static_cast<uint32_t>(i0) << 24) | |
82 | 87.3k | (static_cast<uint32_t>(i1) << 16) | |
83 | 87.3k | (static_cast<uint32_t>(i2) << 8) | |
84 | 87.3k | (static_cast<uint32_t>(i3))); |
85 | 87.3k | } |
86 | | |
87 | | /** |
88 | | * Make a uint64_t from eight bytes |
89 | | * @param i0 the first byte |
90 | | * @param i1 the second byte |
91 | | * @param i2 the third byte |
92 | | * @param i3 the fourth byte |
93 | | * @param i4 the fifth byte |
94 | | * @param i5 the sixth byte |
95 | | * @param i6 the seventh byte |
96 | | * @param i7 the eighth byte |
97 | | * @return i0 || i1 || i2 || i3 || i4 || i5 || i6 || i7 |
98 | | */ |
99 | | inline constexpr uint64_t make_uint64(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3, |
100 | | uint8_t i4, uint8_t i5, uint8_t i6, uint8_t i7) |
101 | 0 | { |
102 | 0 | return ((static_cast<uint64_t>(i0) << 56) | |
103 | 0 | (static_cast<uint64_t>(i1) << 48) | |
104 | 0 | (static_cast<uint64_t>(i2) << 40) | |
105 | 0 | (static_cast<uint64_t>(i3) << 32) | |
106 | 0 | (static_cast<uint64_t>(i4) << 24) | |
107 | 0 | (static_cast<uint64_t>(i5) << 16) | |
108 | 0 | (static_cast<uint64_t>(i6) << 8) | |
109 | 0 | (static_cast<uint64_t>(i7))); |
110 | 0 | } |
111 | | |
112 | | /** |
113 | | * Load a big-endian word |
114 | | * @param in a pointer to some bytes |
115 | | * @param off an offset into the array |
116 | | * @return off'th T of in, as a big-endian value |
117 | | */ |
118 | | template<typename T> |
119 | | inline constexpr T load_be(const uint8_t in[], size_t off) |
120 | 2.40M | { |
121 | 2.40M | in += off * sizeof(T); |
122 | 2.40M | T out = 0; |
123 | 4.80M | for(size_t i = 0; i != sizeof(T); ++i) |
124 | 2.40M | out = static_cast<T>((out << 8) | in[i]); |
125 | 2.40M | return out; |
126 | 2.40M | } |
127 | | |
128 | | /** |
129 | | * Load a little-endian word |
130 | | * @param in a pointer to some bytes |
131 | | * @param off an offset into the array |
132 | | * @return off'th T of in, as a litte-endian value |
133 | | */ |
134 | | template<typename T> |
135 | | inline constexpr T load_le(const uint8_t in[], size_t off) |
136 | | { |
137 | | in += off * sizeof(T); |
138 | | T out = 0; |
139 | | for(size_t i = 0; i != sizeof(T); ++i) |
140 | | out = (out << 8) | in[sizeof(T)-1-i]; |
141 | | return out; |
142 | | } |
143 | | |
144 | | /** |
145 | | * Load a big-endian uint16_t |
146 | | * @param in a pointer to some bytes |
147 | | * @param off an offset into the array |
148 | | * @return off'th uint16_t of in, as a big-endian value |
149 | | */ |
150 | | template<> |
151 | | inline constexpr uint16_t load_be<uint16_t>(const uint8_t in[], size_t off) |
152 | 117k | { |
153 | 117k | in += off * sizeof(uint16_t); |
154 | | |
155 | 117k | #if defined(BOTAN_ENDIAN_N2B) |
156 | 117k | uint16_t x = 0; |
157 | 117k | typecast_copy(x, in); |
158 | 117k | return BOTAN_ENDIAN_N2B(x); |
159 | | #else |
160 | | return make_uint16(in[0], in[1]); |
161 | | #endif |
162 | 117k | } |
163 | | |
164 | | /** |
165 | | * Load a little-endian uint16_t |
166 | | * @param in a pointer to some bytes |
167 | | * @param off an offset into the array |
168 | | * @return off'th uint16_t of in, as a little-endian value |
169 | | */ |
170 | | template<> |
171 | | inline constexpr uint16_t load_le<uint16_t>(const uint8_t in[], size_t off) |
172 | 0 | { |
173 | 0 | in += off * sizeof(uint16_t); |
174 | 0 |
|
175 | 0 | #if defined(BOTAN_ENDIAN_N2L) |
176 | 0 | uint16_t x = 0; |
177 | 0 | typecast_copy(x, in); |
178 | 0 | return BOTAN_ENDIAN_N2L(x); |
179 | 0 | #else |
180 | 0 | return make_uint16(in[1], in[0]); |
181 | 0 | #endif |
182 | 0 | } |
183 | | |
184 | | /** |
185 | | * Load a big-endian uint32_t |
186 | | * @param in a pointer to some bytes |
187 | | * @param off an offset into the array |
188 | | * @return off'th uint32_t of in, as a big-endian value |
189 | | */ |
190 | | template<> |
191 | | inline constexpr uint32_t load_be<uint32_t>(const uint8_t in[], size_t off) |
192 | 13.5M | { |
193 | 13.5M | in += off * sizeof(uint32_t); |
194 | 13.5M | #if defined(BOTAN_ENDIAN_N2B) |
195 | 13.5M | uint32_t x = 0; |
196 | 13.5M | typecast_copy(x, in); |
197 | 13.5M | return BOTAN_ENDIAN_N2B(x); |
198 | | #else |
199 | | return make_uint32(in[0], in[1], in[2], in[3]); |
200 | | #endif |
201 | 13.5M | } |
202 | | |
203 | | /** |
204 | | * Load a little-endian uint32_t |
205 | | * @param in a pointer to some bytes |
206 | | * @param off an offset into the array |
207 | | * @return off'th uint32_t of in, as a little-endian value |
208 | | */ |
209 | | template<> |
210 | | inline constexpr uint32_t load_le<uint32_t>(const uint8_t in[], size_t off) |
211 | 165 | { |
212 | 165 | in += off * sizeof(uint32_t); |
213 | 165 | #if defined(BOTAN_ENDIAN_N2L) |
214 | 165 | uint32_t x = 0; |
215 | 165 | typecast_copy(x, in); |
216 | 165 | return BOTAN_ENDIAN_N2L(x); |
217 | | #else |
218 | | return make_uint32(in[3], in[2], in[1], in[0]); |
219 | | #endif |
220 | 165 | } |
221 | | |
222 | | /** |
223 | | * Load a big-endian uint64_t |
224 | | * @param in a pointer to some bytes |
225 | | * @param off an offset into the array |
226 | | * @return off'th uint64_t of in, as a big-endian value |
227 | | */ |
228 | | template<> |
229 | | inline constexpr uint64_t load_be<uint64_t>(const uint8_t in[], size_t off) |
230 | 4.85M | { |
231 | 4.85M | in += off * sizeof(uint64_t); |
232 | 4.85M | #if defined(BOTAN_ENDIAN_N2B) |
233 | 4.85M | uint64_t x = 0; |
234 | 4.85M | typecast_copy(x, in); |
235 | 4.85M | return BOTAN_ENDIAN_N2B(x); |
236 | | #else |
237 | | return make_uint64(in[0], in[1], in[2], in[3], |
238 | | in[4], in[5], in[6], in[7]); |
239 | | #endif |
240 | 4.85M | } |
241 | | |
242 | | /** |
243 | | * Load a little-endian uint64_t |
244 | | * @param in a pointer to some bytes |
245 | | * @param off an offset into the array |
246 | | * @return off'th uint64_t of in, as a little-endian value |
247 | | */ |
248 | | template<> |
249 | | inline constexpr uint64_t load_le<uint64_t>(const uint8_t in[], size_t off) |
250 | 6.72k | { |
251 | 6.72k | in += off * sizeof(uint64_t); |
252 | 6.72k | #if defined(BOTAN_ENDIAN_N2L) |
253 | 6.72k | uint64_t x = 0; |
254 | 6.72k | typecast_copy(x, in); |
255 | 6.72k | return BOTAN_ENDIAN_N2L(x); |
256 | | #else |
257 | | return make_uint64(in[7], in[6], in[5], in[4], |
258 | | in[3], in[2], in[1], in[0]); |
259 | | #endif |
260 | 6.72k | } |
261 | | |
262 | | /** |
263 | | * Load two little-endian words |
264 | | * @param in a pointer to some bytes |
265 | | * @param x0 where the first word will be written |
266 | | * @param x1 where the second word will be written |
267 | | */ |
268 | | template<typename T> |
269 | | inline constexpr void load_le(const uint8_t in[], T& x0, T& x1) |
270 | | { |
271 | | x0 = load_le<T>(in, 0); |
272 | | x1 = load_le<T>(in, 1); |
273 | | } |
274 | | |
275 | | /** |
276 | | * Load four little-endian words |
277 | | * @param in a pointer to some bytes |
278 | | * @param x0 where the first word will be written |
279 | | * @param x1 where the second word will be written |
280 | | * @param x2 where the third word will be written |
281 | | * @param x3 where the fourth word will be written |
282 | | */ |
283 | | template<typename T> |
284 | | inline constexpr void load_le(const uint8_t in[], |
285 | | T& x0, T& x1, T& x2, T& x3) |
286 | 0 | { |
287 | 0 | x0 = load_le<T>(in, 0); |
288 | 0 | x1 = load_le<T>(in, 1); |
289 | 0 | x2 = load_le<T>(in, 2); |
290 | 0 | x3 = load_le<T>(in, 3); |
291 | 0 | } |
292 | | |
293 | | /** |
294 | | * Load eight little-endian words |
295 | | * @param in a pointer to some bytes |
296 | | * @param x0 where the first word will be written |
297 | | * @param x1 where the second word will be written |
298 | | * @param x2 where the third word will be written |
299 | | * @param x3 where the fourth word will be written |
300 | | * @param x4 where the fifth word will be written |
301 | | * @param x5 where the sixth word will be written |
302 | | * @param x6 where the seventh word will be written |
303 | | * @param x7 where the eighth word will be written |
304 | | */ |
305 | | template<typename T> |
306 | | inline constexpr void load_le(const uint8_t in[], |
307 | | T& x0, T& x1, T& x2, T& x3, |
308 | | T& x4, T& x5, T& x6, T& x7) |
309 | 0 | { |
310 | 0 | x0 = load_le<T>(in, 0); |
311 | 0 | x1 = load_le<T>(in, 1); |
312 | 0 | x2 = load_le<T>(in, 2); |
313 | 0 | x3 = load_le<T>(in, 3); |
314 | 0 | x4 = load_le<T>(in, 4); |
315 | 0 | x5 = load_le<T>(in, 5); |
316 | 0 | x6 = load_le<T>(in, 6); |
317 | 0 | x7 = load_le<T>(in, 7); |
318 | 0 | } Unexecuted instantiation: void Botan::load_le<unsigned long>(unsigned char const*, unsigned long&, unsigned long&, unsigned long&, unsigned long&, unsigned long&, unsigned long&, unsigned long&, unsigned long&) Unexecuted instantiation: void Botan::load_le<unsigned int>(unsigned char const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&, unsigned int&) |
319 | | |
320 | | /** |
321 | | * Load a variable number of little-endian words |
322 | | * @param out the output array of words |
323 | | * @param in the input array of bytes |
324 | | * @param count how many words are in in |
325 | | */ |
326 | | template<typename T> |
327 | | inline constexpr void load_le(T out[], |
328 | | const uint8_t in[], |
329 | | size_t count) |
330 | 545 | { |
331 | 545 | if(count > 0) |
332 | 545 | { |
333 | 545 | #if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) |
334 | 545 | typecast_copy(out, in, count); |
335 | | |
336 | | #elif defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) |
337 | | typecast_copy(out, in, count); |
338 | | |
339 | | const size_t blocks = count - (count % 4); |
340 | | const size_t left = count - blocks; |
341 | | |
342 | | for(size_t i = 0; i != blocks; i += 4) |
343 | | bswap_4(out + i); |
344 | | |
345 | | for(size_t i = 0; i != left; ++i) |
346 | | out[blocks+i] = reverse_bytes(out[blocks+i]); |
347 | | #else |
348 | | for(size_t i = 0; i != count; ++i) |
349 | | out[i] = load_le<T>(in, i); |
350 | | #endif |
351 | 545 | } |
352 | 545 | } void Botan::load_le<unsigned int>(unsigned int*, unsigned char const*, unsigned long) Line | Count | Source | 330 | 545 | { | 331 | 545 | if(count > 0) | 332 | 545 | { | 333 | 545 | #if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) | 334 | 545 | typecast_copy(out, in, count); | 335 | | | 336 | | #elif defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) | 337 | | typecast_copy(out, in, count); | 338 | | | 339 | | const size_t blocks = count - (count % 4); | 340 | | const size_t left = count - blocks; | 341 | | | 342 | | for(size_t i = 0; i != blocks; i += 4) | 343 | | bswap_4(out + i); | 344 | | | 345 | | for(size_t i = 0; i != left; ++i) | 346 | | out[blocks+i] = reverse_bytes(out[blocks+i]); | 347 | | #else | 348 | | for(size_t i = 0; i != count; ++i) | 349 | | out[i] = load_le<T>(in, i); | 350 | | #endif | 351 | 545 | } | 352 | 545 | } |
Unexecuted instantiation: void Botan::load_le<unsigned long>(unsigned long*, unsigned char const*, unsigned long) |
353 | | |
354 | | /** |
355 | | * Load two big-endian words |
356 | | * @param in a pointer to some bytes |
357 | | * @param x0 where the first word will be written |
358 | | * @param x1 where the second word will be written |
359 | | */ |
360 | | template<typename T> |
361 | | inline constexpr void load_be(const uint8_t in[], T& x0, T& x1) |
362 | 2.58k | { |
363 | 2.58k | x0 = load_be<T>(in, 0); |
364 | 2.58k | x1 = load_be<T>(in, 1); |
365 | 2.58k | } Unexecuted instantiation: void Botan::load_be<unsigned int>(unsigned char const*, unsigned int&, unsigned int&) void Botan::load_be<unsigned long>(unsigned char const*, unsigned long&, unsigned long&) Line | Count | Source | 362 | 2.58k | { | 363 | 2.58k | x0 = load_be<T>(in, 0); | 364 | 2.58k | x1 = load_be<T>(in, 1); | 365 | 2.58k | } |
|
366 | | |
367 | | /** |
368 | | * Load four big-endian words |
369 | | * @param in a pointer to some bytes |
370 | | * @param x0 where the first word will be written |
371 | | * @param x1 where the second word will be written |
372 | | * @param x2 where the third word will be written |
373 | | * @param x3 where the fourth word will be written |
374 | | */ |
375 | | template<typename T> |
376 | | inline constexpr void load_be(const uint8_t in[], |
377 | | T& x0, T& x1, T& x2, T& x3) |
378 | 1.35k | { |
379 | 1.35k | x0 = load_be<T>(in, 0); |
380 | 1.35k | x1 = load_be<T>(in, 1); |
381 | 1.35k | x2 = load_be<T>(in, 2); |
382 | 1.35k | x3 = load_be<T>(in, 3); |
383 | 1.35k | } void Botan::load_be<unsigned int>(unsigned char const*, unsigned int&, unsigned int&, unsigned int&, unsigned int&) Line | Count | Source | 378 | 1.35k | { | 379 | 1.35k | x0 = load_be<T>(in, 0); | 380 | 1.35k | x1 = load_be<T>(in, 1); | 381 | 1.35k | x2 = load_be<T>(in, 2); | 382 | 1.35k | x3 = load_be<T>(in, 3); | 383 | 1.35k | } |
Unexecuted instantiation: void Botan::load_be<unsigned short>(unsigned char const*, unsigned short&, unsigned short&, unsigned short&, unsigned short&) |
384 | | |
385 | | /** |
386 | | * Load eight big-endian words |
387 | | * @param in a pointer to some bytes |
388 | | * @param x0 where the first word will be written |
389 | | * @param x1 where the second word will be written |
390 | | * @param x2 where the third word will be written |
391 | | * @param x3 where the fourth word will be written |
392 | | * @param x4 where the fifth word will be written |
393 | | * @param x5 where the sixth word will be written |
394 | | * @param x6 where the seventh word will be written |
395 | | * @param x7 where the eighth word will be written |
396 | | */ |
397 | | template<typename T> |
398 | | inline constexpr void load_be(const uint8_t in[], |
399 | | T& x0, T& x1, T& x2, T& x3, |
400 | | T& x4, T& x5, T& x6, T& x7) |
401 | 0 | { |
402 | 0 | x0 = load_be<T>(in, 0); |
403 | 0 | x1 = load_be<T>(in, 1); |
404 | 0 | x2 = load_be<T>(in, 2); |
405 | 0 | x3 = load_be<T>(in, 3); |
406 | 0 | x4 = load_be<T>(in, 4); |
407 | 0 | x5 = load_be<T>(in, 5); |
408 | 0 | x6 = load_be<T>(in, 6); |
409 | 0 | x7 = load_be<T>(in, 7); |
410 | 0 | } |
411 | | |
412 | | /** |
413 | | * Load a variable number of big-endian words |
414 | | * @param out the output array of words |
415 | | * @param in the input array of bytes |
416 | | * @param count how many words are in in |
417 | | */ |
418 | | template<typename T> |
419 | | inline constexpr void load_be(T out[], |
420 | | const uint8_t in[], |
421 | | size_t count) |
422 | 2.07k | { |
423 | 2.07k | if(count > 0) |
424 | 2.07k | { |
425 | | #if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) |
426 | | typecast_copy(out, in, count); |
427 | | |
428 | | #elif defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) |
429 | 2.07k | typecast_copy(out, in, count); |
430 | 2.07k | const size_t blocks = count - (count % 4); |
431 | 2.07k | const size_t left = count - blocks; |
432 | | |
433 | 2.07k | for(size_t i = 0; i != blocks; i += 4) |
434 | 0 | bswap_4(out + i); |
435 | | |
436 | 6.21k | for(size_t i = 0; i != left; ++i) |
437 | 4.14k | out[blocks+i] = reverse_bytes(out[blocks+i]); |
438 | | #else |
439 | | for(size_t i = 0; i != count; ++i) |
440 | | out[i] = load_be<T>(in, i); |
441 | | #endif |
442 | 2.07k | } |
443 | 2.07k | } Unexecuted instantiation: void Botan::load_be<unsigned int>(unsigned int*, unsigned char const*, unsigned long) void Botan::load_be<unsigned long>(unsigned long*, unsigned char const*, unsigned long) Line | Count | Source | 422 | 2.07k | { | 423 | 2.07k | if(count > 0) | 424 | 2.07k | { | 425 | | #if defined(BOTAN_TARGET_CPU_IS_BIG_ENDIAN) | 426 | | typecast_copy(out, in, count); | 427 | | | 428 | | #elif defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) | 429 | 2.07k | typecast_copy(out, in, count); | 430 | 2.07k | const size_t blocks = count - (count % 4); | 431 | 2.07k | const size_t left = count - blocks; | 432 | | | 433 | 2.07k | for(size_t i = 0; i != blocks; i += 4) | 434 | 0 | bswap_4(out + i); | 435 | | | 436 | 6.21k | for(size_t i = 0; i != left; ++i) | 437 | 4.14k | out[blocks+i] = reverse_bytes(out[blocks+i]); | 438 | | #else | 439 | | for(size_t i = 0; i != count; ++i) | 440 | | out[i] = load_be<T>(in, i); | 441 | | #endif | 442 | 2.07k | } | 443 | 2.07k | } |
|
444 | | |
445 | | /** |
446 | | * Store a big-endian uint16_t |
447 | | * @param in the input uint16_t |
448 | | * @param out the byte array to write to |
449 | | */ |
450 | | inline constexpr void store_be(uint16_t in, uint8_t out[2]) |
451 | 13 | { |
452 | 13 | #if defined(BOTAN_ENDIAN_N2B) |
453 | 13 | uint16_t o = BOTAN_ENDIAN_N2B(in); |
454 | 13 | typecast_copy(out, o); |
455 | | #else |
456 | | out[0] = get_byte<0>(in); |
457 | | out[1] = get_byte<1>(in); |
458 | | #endif |
459 | 13 | } |
460 | | |
461 | | /** |
462 | | * Store a little-endian uint16_t |
463 | | * @param in the input uint16_t |
464 | | * @param out the byte array to write to |
465 | | */ |
466 | | inline constexpr void store_le(uint16_t in, uint8_t out[2]) |
467 | 0 | { |
468 | 0 | #if defined(BOTAN_ENDIAN_N2L) |
469 | 0 | uint16_t o = BOTAN_ENDIAN_N2L(in); |
470 | 0 | typecast_copy(out, o); |
471 | | #else |
472 | | out[0] = get_byte<1>(in); |
473 | | out[1] = get_byte<0>(in); |
474 | | #endif |
475 | 0 | } Unexecuted instantiation: Botan::store_le(unsigned short, unsigned char*) Unexecuted instantiation: Botan::store_le(unsigned short, unsigned char*) |
476 | | |
477 | | /** |
478 | | * Store a big-endian uint32_t |
479 | | * @param in the input uint32_t |
480 | | * @param out the byte array to write to |
481 | | */ |
482 | | inline constexpr void store_be(uint32_t in, uint8_t out[4]) |
483 | 2.68M | { |
484 | 2.68M | #if defined(BOTAN_ENDIAN_B2N) |
485 | 2.68M | uint32_t o = BOTAN_ENDIAN_B2N(in); |
486 | 2.68M | typecast_copy(out, o); |
487 | | #else |
488 | | out[0] = get_byte<0>(in); |
489 | | out[1] = get_byte<1>(in); |
490 | | out[2] = get_byte<2>(in); |
491 | | out[3] = get_byte<3>(in); |
492 | | #endif |
493 | 2.68M | } |
494 | | |
495 | | /** |
496 | | * Store a little-endian uint32_t |
497 | | * @param in the input uint32_t |
498 | | * @param out the byte array to write to |
499 | | */ |
500 | | inline constexpr void store_le(uint32_t in, uint8_t out[4]) |
501 | 388 | { |
502 | 388 | #if defined(BOTAN_ENDIAN_L2N) |
503 | 388 | uint32_t o = BOTAN_ENDIAN_L2N(in); |
504 | 388 | typecast_copy(out, o); |
505 | | #else |
506 | | out[0] = get_byte<3>(in); |
507 | | out[1] = get_byte<2>(in); |
508 | | out[2] = get_byte<1>(in); |
509 | | out[3] = get_byte<0>(in); |
510 | | #endif |
511 | 388 | } |
512 | | |
513 | | /** |
514 | | * Store a big-endian uint64_t |
515 | | * @param in the input uint64_t |
516 | | * @param out the byte array to write to |
517 | | */ |
518 | | inline constexpr void store_be(uint64_t in, uint8_t out[8]) |
519 | 1.21M | { |
520 | 1.21M | #if defined(BOTAN_ENDIAN_B2N) |
521 | 1.21M | uint64_t o = BOTAN_ENDIAN_B2N(in); |
522 | 1.21M | typecast_copy(out, o); |
523 | | #else |
524 | | out[0] = get_byte<0>(in); |
525 | | out[1] = get_byte<1>(in); |
526 | | out[2] = get_byte<2>(in); |
527 | | out[3] = get_byte<3>(in); |
528 | | out[4] = get_byte<4>(in); |
529 | | out[5] = get_byte<5>(in); |
530 | | out[6] = get_byte<6>(in); |
531 | | out[7] = get_byte<7>(in); |
532 | | #endif |
533 | 1.21M | } |
534 | | |
535 | | /** |
536 | | * Store a little-endian uint64_t |
537 | | * @param in the input uint64_t |
538 | | * @param out the byte array to write to |
539 | | */ |
540 | | inline constexpr void store_le(uint64_t in, uint8_t out[8]) |
541 | 2.42k | { |
542 | 2.42k | #if defined(BOTAN_ENDIAN_L2N) |
543 | 2.42k | uint64_t o = BOTAN_ENDIAN_L2N(in); |
544 | 2.42k | typecast_copy(out, o); |
545 | | #else |
546 | | out[0] = get_byte<7>(in); |
547 | | out[1] = get_byte<6>(in); |
548 | | out[2] = get_byte<5>(in); |
549 | | out[3] = get_byte<4>(in); |
550 | | out[4] = get_byte<3>(in); |
551 | | out[5] = get_byte<2>(in); |
552 | | out[6] = get_byte<1>(in); |
553 | | out[7] = get_byte<0>(in); |
554 | | #endif |
555 | 2.42k | } |
556 | | |
557 | | /** |
558 | | * Store two little-endian words |
559 | | * @param out the output byte array |
560 | | * @param x0 the first word |
561 | | * @param x1 the second word |
562 | | */ |
563 | | template<typename T> |
564 | | inline constexpr void store_le(uint8_t out[], T x0, T x1) |
565 | 55 | { |
566 | 55 | store_le(x0, out + (0 * sizeof(T))); |
567 | 55 | store_le(x1, out + (1 * sizeof(T))); |
568 | 55 | } Unexecuted instantiation: void Botan::store_le<unsigned int>(unsigned char*, unsigned int, unsigned int) void Botan::store_le<unsigned long>(unsigned char*, unsigned long, unsigned long) Line | Count | Source | 565 | 55 | { | 566 | 55 | store_le(x0, out + (0 * sizeof(T))); | 567 | 55 | store_le(x1, out + (1 * sizeof(T))); | 568 | 55 | } |
|
569 | | |
570 | | /** |
571 | | * Store two big-endian words |
572 | | * @param out the output byte array |
573 | | * @param x0 the first word |
574 | | * @param x1 the second word |
575 | | */ |
576 | | template<typename T> |
577 | | inline constexpr void store_be(uint8_t out[], T x0, T x1) |
578 | 3.47k | { |
579 | 3.47k | store_be(x0, out + (0 * sizeof(T))); |
580 | 3.47k | store_be(x1, out + (1 * sizeof(T))); |
581 | 3.47k | } void Botan::store_be<unsigned int>(unsigned char*, unsigned int, unsigned int) Line | Count | Source | 578 | 383 | { | 579 | 383 | store_be(x0, out + (0 * sizeof(T))); | 580 | 383 | store_be(x1, out + (1 * sizeof(T))); | 581 | 383 | } |
void Botan::store_be<unsigned long>(unsigned char*, unsigned long, unsigned long) Line | Count | Source | 578 | 3.09k | { | 579 | 3.09k | store_be(x0, out + (0 * sizeof(T))); | 580 | 3.09k | store_be(x1, out + (1 * sizeof(T))); | 581 | 3.09k | } |
Unexecuted instantiation: void Botan::store_be<unsigned short>(unsigned char*, unsigned short, unsigned short) |
582 | | |
583 | | /** |
584 | | * Store four little-endian words |
585 | | * @param out the output byte array |
586 | | * @param x0 the first word |
587 | | * @param x1 the second word |
588 | | * @param x2 the third word |
589 | | * @param x3 the fourth word |
590 | | */ |
591 | | template<typename T> |
592 | | inline constexpr void store_le(uint8_t out[], T x0, T x1, T x2, T x3) |
593 | 527 | { |
594 | 527 | store_le(x0, out + (0 * sizeof(T))); |
595 | 527 | store_le(x1, out + (1 * sizeof(T))); |
596 | 527 | store_le(x2, out + (2 * sizeof(T))); |
597 | 527 | store_le(x3, out + (3 * sizeof(T))); |
598 | 527 | } Unexecuted instantiation: void Botan::store_le<unsigned int>(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned int) void Botan::store_le<unsigned long>(unsigned char*, unsigned long, unsigned long, unsigned long, unsigned long) Line | Count | Source | 593 | 527 | { | 594 | 527 | store_le(x0, out + (0 * sizeof(T))); | 595 | 527 | store_le(x1, out + (1 * sizeof(T))); | 596 | 527 | store_le(x2, out + (2 * sizeof(T))); | 597 | 527 | store_le(x3, out + (3 * sizeof(T))); | 598 | 527 | } |
|
599 | | |
600 | | /** |
601 | | * Store four big-endian words |
602 | | * @param out the output byte array |
603 | | * @param x0 the first word |
604 | | * @param x1 the second word |
605 | | * @param x2 the third word |
606 | | * @param x3 the fourth word |
607 | | */ |
608 | | template<typename T> |
609 | | inline constexpr void store_be(uint8_t out[], T x0, T x1, T x2, T x3) |
610 | 1.84k | { |
611 | 1.84k | store_be(x0, out + (0 * sizeof(T))); |
612 | 1.84k | store_be(x1, out + (1 * sizeof(T))); |
613 | 1.84k | store_be(x2, out + (2 * sizeof(T))); |
614 | 1.84k | store_be(x3, out + (3 * sizeof(T))); |
615 | 1.84k | } void Botan::store_be<unsigned int>(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned int) Line | Count | Source | 610 | 1.84k | { | 611 | 1.84k | store_be(x0, out + (0 * sizeof(T))); | 612 | 1.84k | store_be(x1, out + (1 * sizeof(T))); | 613 | 1.84k | store_be(x2, out + (2 * sizeof(T))); | 614 | 1.84k | store_be(x3, out + (3 * sizeof(T))); | 615 | 1.84k | } |
Unexecuted instantiation: void Botan::store_be<unsigned short>(unsigned char*, unsigned short, unsigned short, unsigned short, unsigned short) |
616 | | |
617 | | /** |
618 | | * Store eight little-endian words |
619 | | * @param out the output byte array |
620 | | * @param x0 the first word |
621 | | * @param x1 the second word |
622 | | * @param x2 the third word |
623 | | * @param x3 the fourth word |
624 | | * @param x4 the fifth word |
625 | | * @param x5 the sixth word |
626 | | * @param x6 the seventh word |
627 | | * @param x7 the eighth word |
628 | | */ |
629 | | template<typename T> |
630 | | inline constexpr void store_le(uint8_t out[], T x0, T x1, T x2, T x3, |
631 | | T x4, T x5, T x6, T x7) |
632 | 0 | { |
633 | 0 | store_le(x0, out + (0 * sizeof(T))); |
634 | 0 | store_le(x1, out + (1 * sizeof(T))); |
635 | 0 | store_le(x2, out + (2 * sizeof(T))); |
636 | 0 | store_le(x3, out + (3 * sizeof(T))); |
637 | 0 | store_le(x4, out + (4 * sizeof(T))); |
638 | 0 | store_le(x5, out + (5 * sizeof(T))); |
639 | 0 | store_le(x6, out + (6 * sizeof(T))); |
640 | 0 | store_le(x7, out + (7 * sizeof(T))); |
641 | 0 | } Unexecuted instantiation: void Botan::store_le<unsigned long>(unsigned char*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) Unexecuted instantiation: void Botan::store_le<unsigned int>(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) |
642 | | |
643 | | /** |
644 | | * Store eight big-endian words |
645 | | * @param out the output byte array |
646 | | * @param x0 the first word |
647 | | * @param x1 the second word |
648 | | * @param x2 the third word |
649 | | * @param x3 the fourth word |
650 | | * @param x4 the fifth word |
651 | | * @param x5 the sixth word |
652 | | * @param x6 the seventh word |
653 | | * @param x7 the eighth word |
654 | | */ |
655 | | template<typename T> |
656 | | inline constexpr void store_be(uint8_t out[], T x0, T x1, T x2, T x3, |
657 | | T x4, T x5, T x6, T x7) |
658 | 0 | { |
659 | 0 | store_be(x0, out + (0 * sizeof(T))); |
660 | 0 | store_be(x1, out + (1 * sizeof(T))); |
661 | 0 | store_be(x2, out + (2 * sizeof(T))); |
662 | 0 | store_be(x3, out + (3 * sizeof(T))); |
663 | 0 | store_be(x4, out + (4 * sizeof(T))); |
664 | 0 | store_be(x5, out + (5 * sizeof(T))); |
665 | 0 | store_be(x6, out + (6 * sizeof(T))); |
666 | 0 | store_be(x7, out + (7 * sizeof(T))); |
667 | 0 | } |
668 | | |
669 | | template<typename T> |
670 | | void copy_out_be(uint8_t out[], size_t out_bytes, const T in[]) |
671 | 374k | { |
672 | 3.22M | while(out_bytes >= sizeof(T)) |
673 | 2.84M | { |
674 | 2.84M | store_be(in[0], out); |
675 | 2.84M | out += sizeof(T); |
676 | 2.84M | out_bytes -= sizeof(T); |
677 | 2.84M | in += 1; |
678 | 2.84M | } |
679 | | |
680 | 374k | for(size_t i = 0; i != out_bytes; ++i) |
681 | 0 | out[i] = get_byte_var(i % 8, in[0]); |
682 | 374k | } void Botan::copy_out_be<unsigned int>(unsigned char*, unsigned long, unsigned int const*) Line | Count | Source | 671 | 332k | { | 672 | 2.93M | while(out_bytes >= sizeof(T)) | 673 | 2.60M | { | 674 | 2.60M | store_be(in[0], out); | 675 | 2.60M | out += sizeof(T); | 676 | 2.60M | out_bytes -= sizeof(T); | 677 | 2.60M | in += 1; | 678 | 2.60M | } | 679 | | | 680 | 332k | for(size_t i = 0; i != out_bytes; ++i) | 681 | 0 | out[i] = get_byte_var(i % 8, in[0]); | 682 | 332k | } |
void Botan::copy_out_be<unsigned long>(unsigned char*, unsigned long, unsigned long const*) Line | Count | Source | 671 | 42.3k | { | 672 | 285k | while(out_bytes >= sizeof(T)) | 673 | 243k | { | 674 | 243k | store_be(in[0], out); | 675 | 243k | out += sizeof(T); | 676 | 243k | out_bytes -= sizeof(T); | 677 | 243k | in += 1; | 678 | 243k | } | 679 | | | 680 | 42.3k | for(size_t i = 0; i != out_bytes; ++i) | 681 | 0 | out[i] = get_byte_var(i % 8, in[0]); | 682 | 42.3k | } |
|
683 | | |
684 | | template<typename T, typename Alloc> |
685 | | void copy_out_vec_be(uint8_t out[], size_t out_bytes, const std::vector<T, Alloc>& in) |
686 | 372k | { |
687 | 372k | copy_out_be(out, out_bytes, in.data()); |
688 | 372k | } void Botan::copy_out_vec_be<unsigned int, Botan::secure_allocator<unsigned int> >(unsigned char*, unsigned long, std::__1::vector<unsigned int, Botan::secure_allocator<unsigned int> > const&) Line | Count | Source | 686 | 332k | { | 687 | 332k | copy_out_be(out, out_bytes, in.data()); | 688 | 332k | } |
void Botan::copy_out_vec_be<unsigned long, Botan::secure_allocator<unsigned long> >(unsigned char*, unsigned long, std::__1::vector<unsigned long, Botan::secure_allocator<unsigned long> > const&) Line | Count | Source | 686 | 40.3k | { | 687 | 40.3k | copy_out_be(out, out_bytes, in.data()); | 688 | 40.3k | } |
|
689 | | |
690 | | template<typename T> |
691 | | void copy_out_le(uint8_t out[], size_t out_bytes, const T in[]) |
692 | 97 | { |
693 | 485 | while(out_bytes >= sizeof(T)) |
694 | 388 | { |
695 | 388 | store_le(in[0], out); |
696 | 388 | out += sizeof(T); |
697 | 388 | out_bytes -= sizeof(T); |
698 | 388 | in += 1; |
699 | 388 | } |
700 | | |
701 | 97 | for(size_t i = 0; i != out_bytes; ++i) |
702 | 0 | out[i] = get_byte_var(sizeof(T) - 1 - (i % 8), in[0]); |
703 | 97 | } Unexecuted instantiation: void Botan::copy_out_le<unsigned long>(unsigned char*, unsigned long, unsigned long const*) void Botan::copy_out_le<unsigned int>(unsigned char*, unsigned long, unsigned int const*) Line | Count | Source | 692 | 97 | { | 693 | 485 | while(out_bytes >= sizeof(T)) | 694 | 388 | { | 695 | 388 | store_le(in[0], out); | 696 | 388 | out += sizeof(T); | 697 | 388 | out_bytes -= sizeof(T); | 698 | 388 | in += 1; | 699 | 388 | } | 700 | | | 701 | 97 | for(size_t i = 0; i != out_bytes; ++i) | 702 | 0 | out[i] = get_byte_var(sizeof(T) - 1 - (i % 8), in[0]); | 703 | 97 | } |
|
704 | | |
705 | | template<typename T, typename Alloc> |
706 | | void copy_out_vec_le(uint8_t out[], size_t out_bytes, const std::vector<T, Alloc>& in) |
707 | 97 | { |
708 | 97 | copy_out_le(out, out_bytes, in.data()); |
709 | 97 | } Unexecuted instantiation: void Botan::copy_out_vec_le<unsigned long, Botan::secure_allocator<unsigned long> >(unsigned char*, unsigned long, std::__1::vector<unsigned long, Botan::secure_allocator<unsigned long> > const&) void Botan::copy_out_vec_le<unsigned int, Botan::secure_allocator<unsigned int> >(unsigned char*, unsigned long, std::__1::vector<unsigned int, Botan::secure_allocator<unsigned int> > const&) Line | Count | Source | 707 | 97 | { | 708 | 97 | copy_out_le(out, out_bytes, in.data()); | 709 | 97 | } |
|
710 | | |
711 | | } |
712 | | |
713 | | #endif |