Botan  1.11.34
Crypto and TLS for C++11
rotate.h
Go to the documentation of this file.
1 /*
2 * Word Rotation Operations
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_WORD_ROTATE_H__
9 #define BOTAN_WORD_ROTATE_H__
10 
11 #include <botan/types.h>
12 
13 namespace Botan {
14 
15 /**
16 * Bit rotation left
17 * @param input the input word
18 * @param rot the number of bits to rotate
19 * @return input rotated left by rot bits
20 */
21 template<typename T> inline T rotate_left(T input, size_t rot)
22  {
23  return (rot == 0) ? input : static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));;
24  }
25 
26 /**
27 * Bit rotation right
28 * @param input the input word
29 * @param rot the number of bits to rotate
30 * @return input rotated right by rot bits
31 */
32 template<typename T> inline T rotate_right(T input, size_t rot)
33  {
34  return (rot == 0) ? input : static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot)));
35  }
36 
37 }
38 
39 #endif
T rotate_left(T input, size_t rot)
Definition: rotate.h:21
T rotate_right(T input, size_t rot)
Definition: rotate.h:32
Definition: alg_id.cpp:13