aboutsummaryrefslogtreecommitdiffstats
path: root/include/bit_ops.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-10-19 17:21:28 +0000
committerlloyd <[email protected]>2007-10-19 17:21:28 +0000
commit4c6fa9a9040a68150531da9327b7f40857ffa057 (patch)
tree68829ebc54ff276f464cf4696b496fc9ebdb4a1b /include/bit_ops.h
parentd527b430d6f82fef220ff0461e196183ce343fc9 (diff)
bit_ops.h no longer includes loadstor.h
Where loadstor.h was needed but only implicitly included via bit_ops.h, include it directly Add endian reversal functions to bit_ops.h Remove some unneeded includes in big_ops2.cpp and a few other files.
Diffstat (limited to 'include/bit_ops.h')
-rw-r--r--include/bit_ops.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/bit_ops.h b/include/bit_ops.h
index 5883d2163..c160d48e3 100644
--- a/include/bit_ops.h
+++ b/include/bit_ops.h
@@ -7,7 +7,6 @@
#define BOTAN_BIT_OPS_H__
#include <botan/types.h>
-#include <botan/loadstor.h>
namespace Botan {
@@ -25,13 +24,36 @@ template<typename T> inline T rotate_right(T input, u32bit rot)
}
/*************************************************
-* XOR Functions *
+* Byteswap *
+*************************************************/
+inline u16bit reverse_bytes(u16bit input)
+ {
+ return rotate_left(input, 8);
+ }
+
+inline u32bit reverse_bytes(u32bit input)
+ {
+ input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
+ return rotate_left(input, 16);
+ }
+
+inline u64bit reverse_bytes(u64bit input)
+ {
+ input = ((input & 0xFF00FF00FF00FF00) >> 8) |
+ ((input & 0x00FF00FF00FF00FF) << 8);
+ input = ((input & 0xFFFF0000FFFF0000) >> 16) |
+ ((input & 0x0000FFFF0000FFFF) << 16);
+ return rotate_left(input, 32);
+ }
+
+/*************************************************
+* Array XOR *
*************************************************/
void xor_buf(byte[], const byte[], u32bit);
void xor_buf(byte[], const byte[], const byte[], u32bit);
/*************************************************
-* Misc Utility Functions *
+* Simple Bit Manipulation *
*************************************************/
bool power_of_2(u64bit);
u32bit high_bit(u64bit);