Botan  1.11.15
src/lib/utils/rotate.h
Go to the documentation of this file.
00001 /*
00002 * Word Rotation Operations
00003 * (C) 1999-2008 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_WORD_ROTATE_H__
00009 #define BOTAN_WORD_ROTATE_H__
00010 
00011 #include <botan/types.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * Bit rotation left
00017 * @param input the input word
00018 * @param rot the number of bits to rotate
00019 * @return input rotated left by rot bits
00020 */
00021 template<typename T> inline T rotate_left(T input, size_t rot)
00022    {
00023    if(rot == 0)
00024       return input;
00025    return static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));;
00026    }
00027 
00028 /**
00029 * Bit rotation right
00030 * @param input the input word
00031 * @param rot the number of bits to rotate
00032 * @return input rotated right by rot bits
00033 */
00034 template<typename T> inline T rotate_right(T input, size_t rot)
00035    {
00036    if(rot == 0)
00037       return input;
00038    return static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot)));
00039    }
00040 
00041 }
00042 
00043 #endif