Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

code_based_util.h
Go to the documentation of this file.
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/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 uint16_t expand_mask_16bit(T tst)
26 {
27 const uint16_t result = (tst != 0);
28 return ~(result - 1);
29 }
30
31 inline gf2m gray_to_lex(gf2m gray)
32 {
33 gf2m result = gray ^ (gray >> 8);
34 result ^= (result >> 4);
35 result ^= (result >> 2);
36 result ^= (result >> 1);
37 return result;
38 }
39
40 inline gf2m lex_to_gray(gf2m lex)
41 {
42 return (lex >> 1) ^ lex;
43 }
44
45 inline uint32_t bit_size_to_byte_size(uint32_t bit_size)
46 {
47 return (bit_size - 1) / 8 + 1;
48 }
49
50 inline uint32_t bit_size_to_32bit_size(uint32_t bit_size)
51 {
52 return (bit_size - 1) / 32 + 1;
53 }
54
55 }
56
57 #endif
Botan::bit_size_to_32bit_size
uint32_t bit_size_to_32bit_size(uint32_t bit_size)
Definition: code_based_util.h:50
Botan::bit_size_to_byte_size
uint32_t bit_size_to_byte_size(uint32_t bit_size)
Definition: code_based_util.h:45
Botan::gray_to_lex
gf2m gray_to_lex(gf2m gray)
Definition: code_based_util.h:31
Botan::lex_to_gray
gf2m lex_to_gray(gf2m lex)
Definition: code_based_util.h:40
Botan::expand_mask_16bit
uint16_t expand_mask_16bit(T tst)
Definition: code_based_util.h:25
Botan::gf2m
uint16_t gf2m
Definition: gf2m_small_m.h:20
Botan
Definition: alg_id.cpp:13