0001-sha2-sha2.c-fix-build-on-big-endian.patch 4.0 KB

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