mirror of https://github.com/ipxe/ipxe.git
[crypto] Use standard bit-rotation functions
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/6/head
parent
cf78afa5c5
commit
c76afb3605
|
@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <byteswap.h>
|
#include <byteswap.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ipxe/rotate.h>
|
||||||
#include <ipxe/crypto.h>
|
#include <ipxe/crypto.h>
|
||||||
#include <ipxe/md5.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 */
|
/** MD5 variables */
|
||||||
struct md5_variables {
|
struct md5_variables {
|
||||||
/* This layout matches that of struct md5_digest_data,
|
/* This layout matches that of struct md5_digest_data,
|
||||||
|
|
|
@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <byteswap.h>
|
#include <byteswap.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ipxe/rotate.h>
|
||||||
#include <ipxe/crypto.h>
|
#include <ipxe/crypto.h>
|
||||||
#include <ipxe/sha1.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 */
|
/** SHA-1 variables */
|
||||||
struct sha1_variables {
|
struct sha1_variables {
|
||||||
/* This layout matches that of struct sha1_digest_data,
|
/* This layout matches that of struct sha1_digest_data,
|
||||||
|
|
|
@ -28,20 +28,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <byteswap.h>
|
#include <byteswap.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ipxe/rotate.h>
|
||||||
#include <ipxe/crypto.h>
|
#include <ipxe/crypto.h>
|
||||||
#include <ipxe/sha256.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 */
|
/** SHA-256 variables */
|
||||||
struct sha256_variables {
|
struct sha256_variables {
|
||||||
/* This layout matches that of struct sha256_digest_data,
|
/* This layout matches that of struct sha256_digest_data,
|
||||||
|
|
|
@ -10,19 +10,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stdint.h>
|
#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 ) ) );
|
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 ) ) );
|
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 ) ) );
|
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 ) ) );
|
return ( ( data >> rotation ) | ( data << ( 64 - rotation ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue