Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kcapi-kdf: Move code to fix #83

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 21 additions & 20 deletions lib/kcapi-kdf.c
Expand Up @@ -54,6 +54,24 @@
#include "kcapi.h"
#include "internal.h"

#ifndef __has_builtin
# define __has_builtin(x) 0
#endif

#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION >= 40400 || (defined(__clang__) && __has_builtin(__builtin_bswap32))
# define __HAVE_BUILTIN_BSWAP32__
#endif

/* Endian dependent byte swap operations. */
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define be_bswap32(x) ((uint32_t)(x))
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# ifdef __HAVE_BUILTIN_BSWAP32__
# define be_bswap32(x) (uint32_t)__builtin_bswap32((uint32_t)(x))
# else
static inline uint32_t rol32(uint32_t x, int n)
{
return ( (x << (n&(32-1))) | (x >> ((32-n)&(32-1))) );
Expand All @@ -68,27 +86,10 @@ static inline uint32_t _bswap32(uint32_t x)
{
return ((rol32(x, 8) & 0x00ff00ffL) | (ror32(x, 8) & 0xff00ff00L));
}

#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION >= 40400
# define __HAVE_BUILTIN_BSWAP32__
#endif

#ifdef __HAVE_BUILTIN_BSWAP32__
# define _swap32(x) (uint32_t)__builtin_bswap32((uint32_t)(x))
#else
# define _swap32(x) _bswap32(x)
#endif

/* Endian dependent byte swap operations. */
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define be_bswap32(x) ((uint32_t)(x))
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define be_bswap32(x) _swap32(x)
# define be_bswap32(x) _bswap32(x)
# endif
#else
#error "Endianess not defined"
# error "Endianess not defined"
#endif

DSO_PUBLIC
Expand Down