Botan: src/utils/rotate.h Source File

Botan 1.10.16

rotate.h
Go to the documentation of this file.
1 /*
2 * Word Rotation Operations
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
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 if(rot == 0)
24 return input;
25 return static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));;
26 }
27
28 /**
29 * Bit rotation right
30 * @param input the input word
31 * @param rot the number of bits to rotate
32 * @return input rotated right by rot bits
33 */
34 template<typename T> inline T rotate_right(T input, size_t rot)
35 {
36 if(rot == 0)
37 return input;
38 return static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot)));
39 }
40
41 }
42
43 #endif
Botan::rotate_left
T rotate_left(T input, size_t rot)
Definition: rotate.h:21
Botan::rotate_right
T rotate_right(T input, size_t rot)
Definition: rotate.h:34
Botan
Definition: algo_base.h:14