Browse Source

[crypto] Add bit-rotation functions for 8-bit and 16-bit values

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
775f5943c0
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      src/include/ipxe/rotate.h

+ 20
- 0
src/include/ipxe/rotate.h View File

@@ -10,6 +10,26 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10 10
 
11 11
 #include <stdint.h>
12 12
 
13
+static inline __attribute__ (( always_inline )) uint8_t
14
+rol8 ( uint8_t data, unsigned int rotation ) {
15
+        return ( ( data << rotation ) | ( data >> ( 8 - rotation ) ) );
16
+}
17
+
18
+static inline __attribute__ (( always_inline )) uint8_t
19
+ror8 ( uint8_t data, unsigned int rotation ) {
20
+        return ( ( data >> rotation ) | ( data << ( 8 - rotation ) ) );
21
+}
22
+
23
+static inline __attribute__ (( always_inline )) uint16_t
24
+rol16 ( uint16_t data, unsigned int rotation ) {
25
+        return ( ( data << rotation ) | ( data >> ( 16 - rotation ) ) );
26
+}
27
+
28
+static inline __attribute__ (( always_inline )) uint16_t
29
+ror16 ( uint16_t data, unsigned int rotation ) {
30
+        return ( ( data >> rotation ) | ( data << ( 16 - rotation ) ) );
31
+}
32
+
13 33
 static inline __attribute__ (( always_inline )) uint32_t
14 34
 rol32 ( uint32_t data, unsigned int rotation ) {
15 35
         return ( ( data << rotation ) | ( data >> ( 32 - rotation ) ) );

Loading…
Cancel
Save