/src/botan/build/include/internal/botan/internal/code_based_util.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * (C) Copyright Projet SECRET, INRIA, Rocquencourt |
3 | | * (C) Bhaskar Biswas and Nicolas Sendrier |
4 | | * |
5 | | * (C) 2014 cryptosource GmbH |
6 | | * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de |
7 | | * |
8 | | * Botan is released under the Simplified BSD License (see license.txt) |
9 | | * |
10 | | */ |
11 | | |
12 | | #ifndef BOTAN_CODE_BASED_UTIL_H_ |
13 | | #define BOTAN_CODE_BASED_UTIL_H_ |
14 | | |
15 | | #include <botan/internal/gf2m_small_m.h> |
16 | | |
17 | | namespace Botan { |
18 | | |
19 | | /** |
20 | | * Expand an input to a bit mask depending on it being being zero or non-zero |
21 | | * @param tst the input |
22 | | * @return the mask 0xFFFF if tst is non-zero and 0 otherwise |
23 | | */ |
24 | | template <typename T> |
25 | 0 | uint16_t expand_mask_16bit(T tst) { |
26 | 0 | const uint16_t result = (tst != 0); |
27 | 0 | return ~(result - 1); |
28 | 0 | } Unexecuted instantiation: unsigned short Botan::expand_mask_16bit<unsigned short>(unsigned short) Unexecuted instantiation: unsigned short Botan::expand_mask_16bit<unsigned int>(unsigned int) Unexecuted instantiation: unsigned short Botan::expand_mask_16bit<int>(int) |
29 | | |
30 | 0 | inline gf2m gray_to_lex(gf2m gray) { |
31 | 0 | gf2m result = gray ^ (gray >> 8); |
32 | 0 | result ^= (result >> 4); |
33 | 0 | result ^= (result >> 2); |
34 | 0 | result ^= (result >> 1); |
35 | 0 | return result; |
36 | 0 | } |
37 | | |
38 | 0 | inline gf2m lex_to_gray(gf2m lex) { |
39 | 0 | return (lex >> 1) ^ lex; |
40 | 0 | } |
41 | | |
42 | 0 | inline size_t bit_size_to_byte_size(size_t bit_size) { |
43 | 0 | return (bit_size - 1) / 8 + 1; |
44 | 0 | } |
45 | | |
46 | 0 | inline size_t bit_size_to_32bit_size(size_t bit_size) { |
47 | 0 | return (bit_size - 1) / 32 + 1; |
48 | 0 | } |
49 | | |
50 | | } // namespace Botan |
51 | | |
52 | | #endif |