Coverage Report

Created: 2021-01-13 07:05

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