Skip to content

Commit

Permalink
[crypto] Use standard bit-rotation functions
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Mar 21, 2012
1 parent cf78afa commit c76afb3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 37 deletions.
12 changes: 1 addition & 11 deletions src/crypto/md5.c
Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions src/crypto/sha1.c
Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions src/crypto/sha256.c
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions src/include/ipxe/rotate.h
Expand Up @@ -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 ) ) );
}

Expand Down

0 comments on commit c76afb3

Please sign in to comment.