aboutsummaryrefslogtreecommitdiffstats
path: root/include/bswap.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-02 06:03:04 +0000
committerlloyd <[email protected]>2008-09-02 06:03:04 +0000
commitae3b9535e41b884d5cc7f039504a66b6e7a25183 (patch)
tree5807c29e225f07a4b8f078626feae0ceed56969e /include/bswap.h
parent1bc7708bd51ea8bb56013b0f9aa4b2dbfe86cf9b (diff)
Split byte swap code and word rotation code off into bswap.h and rotate.h
Diffstat (limited to 'include/bswap.h')
-rw-r--r--include/bswap.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/bswap.h b/include/bswap.h
new file mode 100644
index 000000000..e38d3c6fa
--- /dev/null
+++ b/include/bswap.h
@@ -0,0 +1,39 @@
+/*************************************************
+* Byte Swapping Operations Header File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_BSWAP_H__
+#define BOTAN_BSWAP_H__
+
+#include <botan/types.h>
+#include <botan/rotate.h>
+
+namespace Botan {
+
+/*************************************************
+* Byte Swapping Functions *
+*************************************************/
+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)
+ {
+ u32bit hi = ((input >> 40) & 0x00FF00FF) | ((input >> 24) & 0xFF00FF00);
+ u32bit lo = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
+ hi = (hi << 16) | (hi >> 16);
+ lo = (lo << 16) | (lo >> 16);
+ return (static_cast<u64bit>(lo) << 32) | hi;
+ }
+
+}
+
+#endif