blob: 7ed9caf096ad70a8ba7c811c4132e84ee6ea91a2 [file] [log] [blame]
Brad Bishop8410d612019-11-25 09:40:59 -05001From 8f961521add49278b48c9721fc53e05ee3543b74 Mon Sep 17 00:00:00 2001
Brad Bishop23eaf032019-11-20 05:15:02 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 16 Nov 2019 23:03:51 -0800
4Subject: [PATCH] kcapi-kdf: Move code to fix
5
6Fixes clang build
7unused function '_bswap32' [-Werror,-Wunused-function]
8
Brad Bishop8410d612019-11-25 09:40:59 -05009Upstream-Status: Submitted [https://github.com/smuellerDD/libkcapi/pull/83]
Brad Bishop23eaf032019-11-20 05:15:02 -050010Signed-off-by: Khem Raj <raj.khem@gmail.com>
11---
Brad Bishop8410d612019-11-25 09:40:59 -050012 lib/kcapi-kdf.c | 37 +++++++++++++++++--------------------
13 1 file changed, 17 insertions(+), 20 deletions(-)
Brad Bishop23eaf032019-11-20 05:15:02 -050014
15diff --git a/lib/kcapi-kdf.c b/lib/kcapi-kdf.c
Brad Bishop8410d612019-11-25 09:40:59 -050016index ea39846..9e53a0b 100644
Brad Bishop23eaf032019-11-20 05:15:02 -050017--- a/lib/kcapi-kdf.c
18+++ b/lib/kcapi-kdf.c
19@@ -54,6 +54,20 @@
20 #include "kcapi.h"
21 #include "internal.h"
22
23+#define GCC_VERSION (__GNUC__ * 10000 \
24+ + __GNUC_MINOR__ * 100 \
25+ + __GNUC_PATCHLEVEL__)
26+#if GCC_VERSION >= 40400
27+# define __HAVE_BUILTIN_BSWAP32__
28+#endif
29+
Brad Bishop23eaf032019-11-20 05:15:02 -050030+/* Endian dependent byte swap operations. */
Brad Bishop8410d612019-11-25 09:40:59 -050031+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Brad Bishop23eaf032019-11-20 05:15:02 -050032+# define be_bswap32(x) ((uint32_t)(x))
33+#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
Brad Bishop8410d612019-11-25 09:40:59 -050034+# ifdef __HAVE_BUILTIN_BSWAP32__
35+# define be_bswap32(x) (uint32_t)__builtin_bswap32((uint32_t)(x))
36+# else
Brad Bishop23eaf032019-11-20 05:15:02 -050037 static inline uint32_t rol32(uint32_t x, int n)
38 {
39 return ( (x << (n&(32-1))) | (x >> ((32-n)&(32-1))) );
Brad Bishop8410d612019-11-25 09:40:59 -050040@@ -68,27 +82,10 @@ static inline uint32_t _bswap32(uint32_t x)
Brad Bishop23eaf032019-11-20 05:15:02 -050041 {
42 return ((rol32(x, 8) & 0x00ff00ffL) | (ror32(x, 8) & 0xff00ff00L));
43 }
44-
45-#define GCC_VERSION (__GNUC__ * 10000 \
46- + __GNUC_MINOR__ * 100 \
47- + __GNUC_PATCHLEVEL__)
48-#if GCC_VERSION >= 40400
49-# define __HAVE_BUILTIN_BSWAP32__
50-#endif
51-
52-#ifdef __HAVE_BUILTIN_BSWAP32__
53-# define _swap32(x) (uint32_t)__builtin_bswap32((uint32_t)(x))
54-#else
55-# define _swap32(x) _bswap32(x)
56-#endif
57-
58-/* Endian dependent byte swap operations. */
59-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
60-# define be_bswap32(x) ((uint32_t)(x))
61-#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
62-# define be_bswap32(x) _swap32(x)
Brad Bishop8410d612019-11-25 09:40:59 -050063+# define be_bswap32(x) _bswap32(x)
64+# endif
Brad Bishop23eaf032019-11-20 05:15:02 -050065 #else
66-#error "Endianess not defined"
Brad Bishop8410d612019-11-25 09:40:59 -050067+# error "endianess not defined"
Brad Bishop23eaf032019-11-20 05:15:02 -050068 #endif
69
70 DSO_PUBLIC
71--
722.24.0
73