From c76afb36054669759dd7a876e80b9779dbc79120 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 21 Mar 2012 14:13:15 +0000 Subject: [PATCH] [crypto] Use standard bit-rotation functions Signed-off-by: Michael Brown --- src/crypto/md5.c | 12 +----------- src/crypto/sha1.c | 12 +----------- src/crypto/sha256.c | 12 +----------- src/include/ipxe/rotate.h | 12 ++++++++---- 4 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/crypto/md5.c b/src/crypto/md5.c index e6c68821..2d0d03d1 100644 --- a/src/crypto/md5.c +++ b/src/crypto/md5.c @@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include #include #include -/** - * 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, diff --git a/src/crypto/sha1.c b/src/crypto/sha1.c index 834d9a21..fd271a63 100644 --- a/src/crypto/sha1.c +++ b/src/crypto/sha1.c @@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include #include #include -/** - * 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, diff --git a/src/crypto/sha256.c b/src/crypto/sha256.c index 71683901..6736a577 100644 --- a/src/crypto/sha256.c +++ b/src/crypto/sha256.c @@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include #include #include -/** - * 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, diff --git a/src/include/ipxe/rotate.h b/src/include/ipxe/rotate.h index 745d84e6..ba271ca7 100644 --- a/src/include/ipxe/rotate.h +++ b/src/include/ipxe/rotate.h @@ -10,19 +10,23 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include -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 ) ) ); }