Browse Source

[crypto] Use standard bit-rotation functions

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
c76afb3605
4 changed files with 11 additions and 37 deletions
  1. 1
    11
      src/crypto/md5.c
  2. 1
    11
      src/crypto/sha1.c
  3. 1
    11
      src/crypto/sha256.c
  4. 8
    4
      src/include/ipxe/rotate.h

+ 1
- 11
src/crypto/md5.c View File

@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <string.h>
29 29
 #include <byteswap.h>
30 30
 #include <assert.h>
31
+#include <ipxe/rotate.h>
31 32
 #include <ipxe/crypto.h>
32 33
 #include <ipxe/md5.h>
33 34
 
34
-/**
35
- * Rotate dword left
36
- *
37
- * @v dword		Dword
38
- * @v rotate		Amount of rotation
39
- */
40
-static inline __attribute__ (( always_inline )) uint32_t
41
-rol32 ( uint32_t dword, unsigned int rotate ) {
42
-	return ( ( dword << rotate ) | ( dword >> ( 32 - rotate ) ) );
43
-}
44
-
45 35
 /** MD5 variables */
46 36
 struct md5_variables {
47 37
 	/* This layout matches that of struct md5_digest_data,

+ 1
- 11
src/crypto/sha1.c View File

@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <string.h>
29 29
 #include <byteswap.h>
30 30
 #include <assert.h>
31
+#include <ipxe/rotate.h>
31 32
 #include <ipxe/crypto.h>
32 33
 #include <ipxe/sha1.h>
33 34
 
34
-/**
35
- * Rotate dword left
36
- *
37
- * @v dword		Dword
38
- * @v rotate		Amount of rotation
39
- */
40
-static inline __attribute__ (( always_inline )) uint32_t
41
-rol32 ( uint32_t dword, unsigned int rotate ) {
42
-	return ( ( dword << rotate ) | ( dword >> ( 32 - rotate ) ) );
43
-}
44
-
45 35
 /** SHA-1 variables */
46 36
 struct sha1_variables {
47 37
 	/* This layout matches that of struct sha1_digest_data,

+ 1
- 11
src/crypto/sha256.c View File

@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <string.h>
29 29
 #include <byteswap.h>
30 30
 #include <assert.h>
31
+#include <ipxe/rotate.h>
31 32
 #include <ipxe/crypto.h>
32 33
 #include <ipxe/sha256.h>
33 34
 
34
-/**
35
- * Rotate dword right
36
- *
37
- * @v dword		Dword
38
- * @v rotate		Amount of rotation
39
- */
40
-static inline __attribute__ (( always_inline )) uint32_t
41
-ror32 ( uint32_t dword, unsigned int rotate ) {
42
-	return ( ( dword >> rotate ) | ( dword << ( 32 - rotate ) ) );
43
-}
44
-
45 35
 /** SHA-256 variables */
46 36
 struct sha256_variables {
47 37
 	/* This layout matches that of struct sha256_digest_data,

+ 8
- 4
src/include/ipxe/rotate.h View File

@@ -10,19 +10,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
10 10
 
11 11
 #include <stdint.h>
12 12
 
13
-static inline uint32_t rol32 ( uint32_t data, unsigned int rotation ) {
13
+static inline __attribute__ (( always_inline )) uint32_t
14
+rol32 ( uint32_t data, unsigned int rotation ) {
14 15
         return ( ( data << rotation ) | ( data >> ( 32 - rotation ) ) );
15 16
 }
16 17
 
17
-static inline uint32_t ror32 ( uint32_t data, unsigned int rotation ) {
18
+static inline __attribute__ (( always_inline )) uint32_t
19
+ror32 ( uint32_t data, unsigned int rotation ) {
18 20
         return ( ( data >> rotation ) | ( data << ( 32 - rotation ) ) );
19 21
 }
20 22
 
21
-static inline uint64_t rol64 ( uint64_t data, unsigned int rotation ) {
23
+static inline __attribute__ (( always_inline )) uint64_t
24
+rol64 ( uint64_t data, unsigned int rotation ) {
22 25
         return ( ( data << rotation ) | ( data >> ( 64 - rotation ) ) );
23 26
 }
24 27
 
25
-static inline uint64_t ror64 ( uint64_t data, unsigned int rotation ) {
28
+static inline __attribute__ (( always_inline )) uint64_t
29
+ror64 ( uint64_t data, unsigned int rotation ) {
26 30
         return ( ( data >> rotation ) | ( data << ( 64 - rotation ) ) );
27 31
 }
28 32
 

Loading…
Cancel
Save