From 775f5943c0aa8b9889aed057bf0057c62f06c253 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 25 Jul 2015 14:41:30 +0100 Subject: [PATCH] [crypto] Add bit-rotation functions for 8-bit and 16-bit values Signed-off-by: Michael Brown --- src/include/ipxe/rotate.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 +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 ) ) );