summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown2015-07-25 15:41:30 +0200
committerMichael Brown2015-07-27 16:21:17 +0200
commit775f5943c0aa8b9889aed057bf0057c62f06c253 (patch)
tree43239e83940640f8106550675447d99e8b4c42e6 /src/include
parent[build] Fix compiler warnings on some gcc versions (diff)
downloadipxe-775f5943c0aa8b9889aed057bf0057c62f06c253.tar.gz
ipxe-775f5943c0aa8b9889aed057bf0057c62f06c253.tar.xz
ipxe-775f5943c0aa8b9889aed057bf0057c62f06c253.zip
[crypto] Add bit-rotation functions for 8-bit and 16-bit values
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ipxe/rotate.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/include/ipxe/rotate.h b/src/include/ipxe/rotate.h
index 3495040bc..b5693e3ca 100644
--- a/src/include/ipxe/rotate.h
+++ b/src/include/ipxe/rotate.h
@@ -10,6 +10,26 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
+static inline __attribute__ (( always_inline )) uint8_t
+rol8 ( uint8_t data, unsigned int rotation ) {
+ return ( ( data << rotation ) | ( data >> ( 8 - rotation ) ) );
+}
+
+static inline __attribute__ (( always_inline )) uint8_t
+ror8 ( uint8_t data, unsigned int rotation ) {
+ return ( ( data >> rotation ) | ( data << ( 8 - rotation ) ) );
+}
+
+static inline __attribute__ (( always_inline )) uint16_t
+rol16 ( uint16_t data, unsigned int rotation ) {
+ return ( ( data << rotation ) | ( data >> ( 16 - rotation ) ) );
+}
+
+static inline __attribute__ (( always_inline )) uint16_t
+ror16 ( uint16_t data, unsigned int rotation ) {
+ return ( ( data >> rotation ) | ( data << ( 16 - rotation ) ) );
+}
+
static inline __attribute__ (( always_inline )) uint32_t
rol32 ( uint32_t data, unsigned int rotation ) {
return ( ( data << rotation ) | ( data >> ( 32 - rotation ) ) );