Botan  1.11.15
src/lib/utils/ta_utils.h
Go to the documentation of this file.
00001 /*
00002 * Timing Attack Countermeasure Functions
00003 * (C) 2010 Falko Strenzke, Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_TIMING_ATTACK_CM_H__
00009 #define BOTAN_TIMING_ATTACK_CM_H__
00010 
00011 #include <botan/types.h>
00012 
00013 namespace Botan {
00014 
00015 namespace TA_CM {
00016 
00017 /**
00018 * Function used in timing attack countermeasures
00019 * See Wagner, Molnar, et al "The Program Counter Security Model"
00020 *
00021 * @param in an integer
00022 * @return 0 if in == 0 else 0xFFFFFFFF
00023 */
00024 u32bit expand_mask_u32bit(u32bit in);
00025 
00026 
00027 /**
00028  * Expand an input to a bit mask depending on it being being zero or
00029  * non-zero
00030  * @ param in the input
00031  * @return the mask 0xFFFF if tst is non-zero and 0 otherwise
00032  */
00033 u16bit expand_mask_u16bit(u16bit in);
00034 
00035 /**
00036 * Branch-free maximum
00037 * Note: assumes twos-complement signed representation
00038 * @param a an integer
00039 * @param b an integer
00040 * @return max(a,b)
00041 */
00042 u32bit max_32(u32bit a, u32bit b);
00043 
00044 /**
00045 * Branch-free minimum
00046 * Note: assumes twos-complement signed representation
00047 * @param a an integer
00048 * @param b an integer
00049 * @return min(a,b)
00050 */
00051 u32bit min_32(u32bit a, u32bit b);
00052 
00053 }
00054 
00055 }
00056 
00057 #endif