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