Botan
1.11.15
|
00001 /** 00002 * (C) Copyright Projet SECRET, INRIA, Rocquencourt 00003 * (C) Bhaskar Biswas and Nicolas Sendrier 00004 * 00005 * (C) 2014 cryptosource GmbH 00006 * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de 00007 * 00008 * Botan is released under the Simplified BSD License (see license.txt) 00009 * 00010 */ 00011 00012 #ifndef BOTAN_CODE_BASED_UTIL_H__ 00013 #define BOTAN_CODE_BASED_UTIL_H__ 00014 00015 #include <botan/gf2m_small_m.h> 00016 00017 namespace Botan { 00018 00019 /** 00020 * Expand an input to a bit mask depending on it being being zero or non-zero 00021 * @ param tst the input 00022 * @return the mask 0xFFFF if tst is non-zero and 0 otherwise 00023 */ 00024 template<typename T> 00025 u16bit expand_mask_16bit(T tst) 00026 { 00027 const u16bit result = (tst != 0); 00028 return ~(result - 1); 00029 } 00030 00031 inline gf2m_small_m::gf2m gray_to_lex(gf2m_small_m::gf2m gray) 00032 { 00033 gf2m_small_m::gf2m result = gray ^ (gray>>8); 00034 result ^= (result >> 4); 00035 result ^= (result >> 2); 00036 result ^= (result >> 1); 00037 return result; 00038 } 00039 00040 inline gf2m_small_m::gf2m lex_to_gray(gf2m_small_m::gf2m lex) 00041 { 00042 return (lex>>1) ^ lex; 00043 } 00044 00045 inline u32bit bit_size_to_byte_size(u32bit bit_size) 00046 { 00047 return (bit_size - 1) / 8 + 1; 00048 } 00049 00050 inline u32bit bit_size_to_32bit_size(u32bit bit_size) 00051 { 00052 return (bit_size - 1) / 32 + 1; 00053 } 00054 00055 } 00056 00057 #endif