]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Use standard bit-rotation functions
authorMichael Brown <mcb30@ipxe.org>
Wed, 21 Mar 2012 14:13:15 +0000 (14:13 +0000)
committerMichael Brown <mcb30@ipxe.org>
Wed, 21 Mar 2012 16:27:12 +0000 (16:27 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/md5.c
src/crypto/sha1.c
src/crypto/sha256.c
src/include/ipxe/rotate.h

index e6c68821776e0ac0c79722bf91e1bec97840f6f4..2d0d03d130eceb40729d0a95c2f88b41a165fcb7 100644 (file)
@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <string.h>
 #include <byteswap.h>
 #include <assert.h>
+#include <ipxe/rotate.h>
 #include <ipxe/crypto.h>
 #include <ipxe/md5.h>
 
-/**
- * Rotate dword left
- *
- * @v dword            Dword
- * @v rotate           Amount of rotation
- */
-static inline __attribute__ (( always_inline )) uint32_t
-rol32 ( uint32_t dword, unsigned int rotate ) {
-       return ( ( dword << rotate ) | ( dword >> ( 32 - rotate ) ) );
-}
-
 /** MD5 variables */
 struct md5_variables {
        /* This layout matches that of struct md5_digest_data,
index 834d9a214686cfa643d4d7eb8552acd68300e29d..fd271a638af90160a27f86f7dd24c2587585a86d 100644 (file)
@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <string.h>
 #include <byteswap.h>
 #include <assert.h>
+#include <ipxe/rotate.h>
 #include <ipxe/crypto.h>
 #include <ipxe/sha1.h>
 
-/**
- * Rotate dword left
- *
- * @v dword            Dword
- * @v rotate           Amount of rotation
- */
-static inline __attribute__ (( always_inline )) uint32_t
-rol32 ( uint32_t dword, unsigned int rotate ) {
-       return ( ( dword << rotate ) | ( dword >> ( 32 - rotate ) ) );
-}
-
 /** SHA-1 variables */
 struct sha1_variables {
        /* This layout matches that of struct sha1_digest_data,
index 71683901be4a947c731c2459ac2e9590f8f5d9e7..6736a5773fe2fc36a5f3a9cba8a0e4076481bc14 100644 (file)
@@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <string.h>
 #include <byteswap.h>
 #include <assert.h>
+#include <ipxe/rotate.h>
 #include <ipxe/crypto.h>
 #include <ipxe/sha256.h>
 
-/**
- * Rotate dword right
- *
- * @v dword            Dword
- * @v rotate           Amount of rotation
- */
-static inline __attribute__ (( always_inline )) uint32_t
-ror32 ( uint32_t dword, unsigned int rotate ) {
-       return ( ( dword >> rotate ) | ( dword << ( 32 - rotate ) ) );
-}
-
 /** SHA-256 variables */
 struct sha256_variables {
        /* This layout matches that of struct sha256_digest_data,
index 745d84e6c25dd05d10d7f7fd52d2fb4ad2253259..ba271ca740d776b3a6c30634eb6236e65de795b4 100644 (file)
@@ -10,19 +10,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdint.h>
 
-static inline uint32_t rol32 ( uint32_t data, unsigned int rotation ) {
+static inline __attribute__ (( always_inline )) uint32_t
+rol32 ( uint32_t data, unsigned int rotation ) {
         return ( ( data << rotation ) | ( data >> ( 32 - rotation ) ) );
 }
 
-static inline uint32_t ror32 ( uint32_t data, unsigned int rotation ) {
+static inline __attribute__ (( always_inline )) uint32_t
+ror32 ( uint32_t data, unsigned int rotation ) {
         return ( ( data >> rotation ) | ( data << ( 32 - rotation ) ) );
 }
 
-static inline uint64_t rol64 ( uint64_t data, unsigned int rotation ) {
+static inline __attribute__ (( always_inline )) uint64_t
+rol64 ( uint64_t data, unsigned int rotation ) {
         return ( ( data << rotation ) | ( data >> ( 64 - rotation ) ) );
 }
 
-static inline uint64_t ror64 ( uint64_t data, unsigned int rotation ) {
+static inline __attribute__ (( always_inline )) uint64_t
+ror64 ( uint64_t data, unsigned int rotation ) {
         return ( ( data >> rotation ) | ( data << ( 64 - rotation ) ) );
 }