1From 608738ccad9ac3743ccd535bde1e84f401e6176f Mon Sep 17 00:00:00 2001 2From: Fabrice Fontaine <fontaine.fabrice@gmail.com> 3Date: Sat, 20 Jun 2020 12:50:40 +0200 4Subject: [PATCH] sha2/sha2.c: fix build on big endian 5 6Build is broken since 865ec9ba1d44e629c1107c299aebd20e901a19ff because 7tmp is undefined in put32be and put64be: 8 9sha2.c: In function 'put32be': 10sha2.c:177:34: error: 'tmp' undeclared (first use in this function) 11 MEMCPY_BCOPY(data, &val, sizeof(tmp)); 12 ^~~ 13 14Fix this error by replacing tmp by val 15 16Moreover, move MEMCPY_BCOPY before its usage or linking step will fail 17 18Fixes: 19 - http://autobuild.buildroot.org/results/e8704e02fdede7b63e22da552292977b23380b32 20 21Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 22[Upstream: https://github.com/eclipse/tinydtls/commit/78a2d32f47165eda10cbf8f5cf79f86fa1c4872b] 23--- 24 sha2/sha2.c | 58 ++++++++++++++++++++++++++--------------------------- 25 1 file changed, 29 insertions(+), 29 deletions(-) 26 27diff --git a/sha2/sha2.c b/sha2/sha2.c 28index cb6d90f..5c794c6 100644 29--- a/sha2/sha2.c 30+++ b/sha2/sha2.c 31@@ -114,6 +114,33 @@ 32 #error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN 33 #endif 34 35+/* 36+ * Macros for copying blocks of memory and for zeroing out ranges 37+ * of memory. Using these macros makes it easy to switch from 38+ * using memset()/memcpy() and using bzero()/bcopy(). 39+ * 40+ * Please define either SHA2_USE_MEMSET_MEMCPY or define 41+ * SHA2_USE_BZERO_BCOPY depending on which function set you 42+ * choose to use: 43+ */ 44+#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY) 45+/* Default to memset()/memcpy() if no option is specified */ 46+#define SHA2_USE_MEMSET_MEMCPY 1 47+#endif 48+#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY) 49+/* Abort with an error if BOTH options are defined */ 50+#error Define either SHA2_USE_MEMSET_MEMCPY or SHA2_USE_BZERO_BCOPY, not both! 51+#endif 52+ 53+#ifdef SHA2_USE_MEMSET_MEMCPY 54+#define MEMSET_BZERO(p,l) memset((p), 0, (l)) 55+#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l)) 56+#endif 57+#ifdef SHA2_USE_BZERO_BCOPY 58+#define MEMSET_BZERO(p,l) bzero((p), (l)) 59+#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l)) 60+#endif 61+ 62 /* 63 * Define the followingsha2_* types to types of the correct length on 64 * the native archtecture. Most BSD systems and Linux define u_intXX_t 65@@ -174,7 +201,7 @@ static inline void put32be(sha2_byte* data, sha2_word32 val) 66 data[1] = val; val >>= 8; 67 data[0] = val; 68 #else /* BYTE_ORDER != LITTLE_ENDIAN */ 69- MEMCPY_BCOPY(data, &val, sizeof(tmp)); 70+ MEMCPY_BCOPY(data, &val, sizeof(val)); 71 #endif /* BYTE_ORDER != LITTLE_ENDIAN */ 72 } 73 74@@ -209,7 +236,7 @@ static inline void put64be(sha2_byte* data, sha2_word64 val) 75 data[1] = val; val >>= 8; 76 data[0] = val; 77 #else /* BYTE_ORDER != LITTLE_ENDIAN */ 78- MEMCPY_BCOPY(data, &val, sizeof(tmp)); 79+ MEMCPY_BCOPY(data, &val, sizeof(val)); 80 #endif /* BYTE_ORDER != LITTLE_ENDIAN */ 81 } 82 83@@ -225,33 +252,6 @@ static inline void put64be(sha2_byte* data, sha2_word64 val) 84 } \ 85 } 86 87-/* 88- * Macros for copying blocks of memory and for zeroing out ranges 89- * of memory. Using these macros makes it easy to switch from 90- * using memset()/memcpy() and using bzero()/bcopy(). 91- * 92- * Please define either SHA2_USE_MEMSET_MEMCPY or define 93- * SHA2_USE_BZERO_BCOPY depending on which function set you 94- * choose to use: 95- */ 96-#if !defined(SHA2_USE_MEMSET_MEMCPY) && !defined(SHA2_USE_BZERO_BCOPY) 97-/* Default to memset()/memcpy() if no option is specified */ 98-#define SHA2_USE_MEMSET_MEMCPY 1 99-#endif 100-#if defined(SHA2_USE_MEMSET_MEMCPY) && defined(SHA2_USE_BZERO_BCOPY) 101-/* Abort with an error if BOTH options are defined */ 102-#error Define either SHA2_USE_MEMSET_MEMCPY or SHA2_USE_BZERO_BCOPY, not both! 103-#endif 104- 105-#ifdef SHA2_USE_MEMSET_MEMCPY 106-#define MEMSET_BZERO(p,l) memset((p), 0, (l)) 107-#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l)) 108-#endif 109-#ifdef SHA2_USE_BZERO_BCOPY 110-#define MEMSET_BZERO(p,l) bzero((p), (l)) 111-#define MEMCPY_BCOPY(d,s,l) bcopy((s), (d), (l)) 112-#endif 113- 114 115 /*** THE SIX LOGICAL FUNCTIONS ****************************************/ 116 /* 117-- 1182.26.2 119 120