diff options
author | lloyd <[email protected]> | 2007-10-21 08:25:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2007-10-21 08:25:52 +0000 |
commit | 903c761d994599541dd1bc60d5196e6f926abd71 (patch) | |
tree | b32f60bc9301abf8809c911d43ef942c109c2b41 /src/bit_ops.cpp | |
parent | cfcfaf67d64abab036d3c4b66837b2a0116e1946 (diff) |
Move reverse_bytes from bit_ops.h to bit_ops.cpp
Diffstat (limited to 'src/bit_ops.cpp')
-rw-r--r-- | src/bit_ops.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/bit_ops.cpp b/src/bit_ops.cpp index 22a01c037..fa08c5a9f 100644 --- a/src/bit_ops.cpp +++ b/src/bit_ops.cpp @@ -3,6 +3,7 @@ * (C) 1999-2007 The Botan Project * *************************************************/ +#include <botan/bit_ops.h> #include <botan/loadstor.h> namespace Botan { @@ -42,6 +43,35 @@ void xor_buf(byte out[], const byte in[], const byte mask[], u32bit length) } /************************************************* +* Reverse bytes * +*************************************************/ +u16bit reverse_bytes(u16bit input) + { + return rotate_left(input, 8); + } + +/************************************************* +* Reverse bytes * +*************************************************/ +u32bit reverse_bytes(u32bit input) + { + input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8); + return rotate_left(input, 16); + } + +/************************************************* +* Reverse bytes * +*************************************************/ +u64bit reverse_bytes(u64bit input) + { + input = ((input & 0xFF00FF00FF00FF00) >> 8) | + ((input & 0x00FF00FF00FF00FF) << 8); + input = ((input & 0xFFFF0000FFFF0000) >> 16) | + ((input & 0x0000FFFF0000FFFF) << 16); + return rotate_left(input, 32); + } + +/************************************************* * Return true iff arg is 2**n for some n > 0 * *************************************************/ bool power_of_2(u64bit arg) |