aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/mce/code_based_util.h
blob: 9b5395f41104841ed2d85a29994021b16365b0ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * (C) Copyright Projet SECRET, INRIA, Rocquencourt
 * (C) Bhaskar Biswas and  Nicolas Sendrier
 *
 * (C) 2014 cryptosource GmbH
 * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de
 *
 * Botan is released under the Simplified BSD License (see license.txt)
 *
 */

#ifndef BOTAN_CODE_BASED_UTIL_H__
#define BOTAN_CODE_BASED_UTIL_H__

#include <botan/gf2m_small_m.h>

namespace Botan {

/**
* Expand an input to a bit mask depending on it being being zero or non-zero
* @param tst the input
* @return the mask 0xFFFF if tst is non-zero and 0 otherwise
*/
template<typename T>
u16bit expand_mask_16bit(T tst)
   {
   const u16bit result = (tst != 0);
   return ~(result - 1);
   }

inline gf2m gray_to_lex(gf2m gray)
   {
   gf2m result = gray ^ (gray >> 8);
   result ^= (result >> 4);
   result ^= (result >> 2);
   result ^= (result >> 1);
   return result;
   }

inline gf2m lex_to_gray(gf2m lex)
   {
   return (lex >> 1) ^ lex;
   }

inline u32bit bit_size_to_byte_size(u32bit bit_size)
   {
   return (bit_size - 1) / 8 + 1;
   }

inline u32bit bit_size_to_32bit_size(u32bit bit_size)
   {
   return (bit_size - 1) / 32 + 1;
   }

}

#endif