0003-fix-md5update.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. Fix build with -Wincompatible-pointer-types -Werror
  2. Upstream: https://people.nwtime.org/hart/ntp-stable-3928-29.tar.gz
  3. Ported fix from updated tarball provided by upstream:
  4. https://bugs.ntp.org/show_bug.cgi?id=3929#c9
  5. Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
  6. diff -uNr ntp-4.2.8p18.orig/include/ntp_md5.h ntp-4.2.8p18/include/ntp_md5.h
  7. --- ntp-4.2.8p18.orig/include/ntp_md5.h 2024-05-07 13:21:16.000000000 +0200
  8. +++ ntp-4.2.8p18/include/ntp_md5.h 2024-07-24 01:26:46.000000000 +0200
  9. @@ -1,56 +1,73 @@
  10. /*
  11. * ntp_md5.h: deal with md5.h headers
  12. *
  13. - * Use the system MD5 if available, otherwise libisc's.
  14. + * Use the system MD5 if available, otherwise use libisc's.
  15. + * Yes, MD5 has been deprecated. Nevertheless, ntpd IPv6 refid
  16. + * calculation uses MD5 to derive a 32-bit refid from a 128-bit
  17. + * IPv6 address. This use is retained to avoid breaking loop
  18. + * detection that would be triggered by such change, and because
  19. + * we are not depending on cryptographic strength for such use.
  20. */
  21. #ifndef NTP_MD5_H
  22. #define NTP_MD5_H
  23. /* Use the system MD5 or fall back on libisc's */
  24. -# if defined HAVE_MD5_H && defined HAVE_MD5INIT
  25. -# include <md5.h>
  26. -# else
  27. -# include "isc/md5.h"
  28. - typedef isc_md5_t MD5_CTX;
  29. -# define MD5_DIGEST_LENGTH ISC_MD5_DIGESTLENGTH
  30. -# define MD5Init(c) isc_md5_init(c)
  31. -# define MD5Update(c, p, s) isc_md5_update(c, (const void *)p, s)
  32. -# define MD5Final(d, c) isc_md5_final((c), (d)) /* swapped */
  33. -# endif
  34. -
  35. -# define KEY_TYPE_MD5 NID_md5
  36. +#if defined HAVE_MD5_H && defined HAVE_MD5INIT
  37. +# include <md5.h>
  38. +# define ntp_md5_init(c) MD5Init(c)
  39. +# define ntp_md5_update(c, p, s) MD5Update(c, (const void *)(p), s)
  40. +# define ntp_md5_final(d, c) MD5Final(d, c)
  41. +#else
  42. +# include "isc/md5.h"
  43. +typedef isc_md5_t MD5_CTX;
  44. +# define MD5_DIGEST_LENGTH ISC_MD5_DIGESTLENGTH
  45. +# define ntp_md5_init(c) isc_md5_init(c)
  46. +# define ntp_md5_update(c, p, s) isc_md5_update(c, (const void *)(p), s)
  47. +# define ntp_md5_final(d, c) isc_md5_final((c), (d)) /* swapped */
  48. +#endif
  49. #ifdef OPENSSL
  50. # include <openssl/evp.h>
  51. # include "libssl_compat.h"
  52. # ifdef HAVE_OPENSSL_CMAC_H
  53. # include <openssl/cmac.h>
  54. -# define CMAC "AES128CMAC"
  55. -# define AES_128_KEY_SIZE 16
  56. -# endif /*HAVE_OPENSSL_CMAC_H*/
  57. +# define CMAC "AES128CMAC"
  58. +# define AES_128_KEY_SIZE 16
  59. +# endif
  60. #else /* !OPENSSL follows */
  61. /*
  62. - * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
  63. + * Provide OpenSSL-alike MD5 API if we're not using OpenSSL. Most of this
  64. + * is used only by sntp when building it --without-crypto.
  65. */
  66. - typedef MD5_CTX EVP_MD_CTX;
  67. +typedef MD5_CTX EVP_MD_CTX;
  68. # define NID_md5 4 /* from openssl/objects.h */
  69. # define EVP_MAX_MD_SIZE MD5_DIGEST_LENGTH
  70. +
  71. +/*
  72. + * The following is used only by sntp configured --without-crypto as ntpd
  73. + * now uses explicit MD5 functions for MD5 uses which remain even where MD5
  74. + * is unavailable in OpenSSL, such as FIPS OpenSSL. Note that FIPS may be
  75. + * available in the build environment but not at runtime, as is the case
  76. + * with packaged NTP binaries.
  77. + * The remaining uses of MD5 are IPv6 refids and mode 6 nonces. ntpd does
  78. + * go through OpenSSL when using MD5 for symmetric authentication.
  79. + */
  80. # define EVP_MD_CTX_free(c) free(c)
  81. # define EVP_MD_CTX_new() calloc(1, sizeof(MD5_CTX))
  82. # define EVP_get_digestbynid(t) NULL
  83. # define EVP_md5() NULL
  84. # define EVP_MD_CTX_init(c)
  85. # define EVP_MD_CTX_set_flags(c, f)
  86. -# define EVP_DigestInit(c, dt) (MD5Init(c), 1)
  87. -# define EVP_DigestInit_ex(c, dt, i) (MD5Init(c), 1)
  88. -# define EVP_DigestUpdate(c, p, s) MD5Update(c, (const void *)(p), \
  89. - s)
  90. -# define EVP_DigestFinal(c, d, pdl) \
  91. - do { \
  92. - MD5Final((d), (c)); \
  93. - *(pdl) = MD5_LENGTH; \
  94. - } while (0)
  95. -# endif /* !OPENSSL */
  96. +# define EVP_DigestInit(c, dt) (ntp_md5_init(c), 1)
  97. +# define EVP_DigestUpdate(c, p, s) ntp_md5_update(c, p, s)
  98. +# define EVP_DigestFinal(c, d, pdl) \
  99. + do { \
  100. + ntp_md5_final((d), (c)); \
  101. + *(pdl) = MD5_LENGTH; \
  102. + } while (FALSE)
  103. +
  104. +#endif /* OPENSSL */
  105. +
  106. #endif /* NTP_MD5_H */
  107. diff -uNr ntp-4.2.8p18.orig/libntp/a_md5encrypt.c ntp-4.2.8p18/libntp/a_md5encrypt.c
  108. --- ntp-4.2.8p18.orig/libntp/a_md5encrypt.c 2024-05-07 13:21:31.000000000 +0200
  109. +++ ntp-4.2.8p18/libntp/a_md5encrypt.c 2024-07-24 01:26:46.000000000 +0200
  110. @@ -56,7 +56,7 @@
  111. static MD5_CTX md5_ctx;
  112. DEBUG_INSIST(NID_md5 == nid);
  113. - MD5Init(&md5_ctx);
  114. + ntp_md5_init(&md5_ctx);
  115. return &md5_ctx;
  116. #else
  117. @@ -171,10 +171,10 @@
  118. if (digest->len < MD5_LENGTH) {
  119. msyslog(LOG_ERR, "%s", "MAC encrypt: MAC md5 buf too small.");
  120. } else {
  121. - MD5Init(ctx);
  122. - MD5Update(ctx, (const void *)key->buf, key->len);
  123. - MD5Update(ctx, (const void *)msg->buf, msg->len);
  124. - MD5Final(digest->buf, ctx);
  125. + ntp_md5_init(ctx);
  126. + ntp_md5_update(ctx, key->buf, key->len);
  127. + ntp_md5_update(ctx, msg->buf, msg->len);
  128. + ntp_md5_final(digest->buf, ctx);
  129. retlen = MD5_LENGTH;
  130. }
  131. } else {
  132. @@ -279,9 +279,9 @@
  133. return (NSRCADR(addr));
  134. }
  135. /* MD5 is not used for authentication here. */
  136. - MD5Init(&md5_ctx);
  137. - MD5Update(&md5_ctx, (void *)&SOCK_ADDR6(addr), sizeof(SOCK_ADDR6(addr)));
  138. - MD5Final(u.digest, &md5_ctx);
  139. + ntp_md5_init(&md5_ctx);
  140. + ntp_md5_update(&md5_ctx, &SOCK_ADDR6(addr), sizeof(SOCK_ADDR6(addr)));
  141. + ntp_md5_final(u.digest, &md5_ctx);
  142. #ifdef WORDS_BIGENDIAN
  143. u.addr_refid = BYTESWAP32(u.addr_refid);
  144. #endif
  145. diff -uNr ntp-4.2.8p18.orig/libntp/authreadkeys.c ntp-4.2.8p18/libntp/authreadkeys.c
  146. --- ntp-4.2.8p18.orig/libntp/authreadkeys.c 2024-05-07 13:21:20.000000000 +0200
  147. +++ ntp-4.2.8p18/libntp/authreadkeys.c 2024-07-24 01:26:46.000000000 +0200
  148. @@ -240,7 +240,7 @@
  149. keyno);
  150. keytype = 0;
  151. } else {
  152. - keytype = KEY_TYPE_MD5;
  153. + keytype = NID_md5;
  154. }
  155. #endif /* !OPENSSL */
  156. diff -uNr ntp-4.2.8p18.orig/ntpd/ntp_control.c ntp-4.2.8p18/ntpd/ntp_control.c
  157. --- ntp-4.2.8p18.orig/ntpd/ntp_control.c 2024-05-07 13:21:15.000000000 +0200
  158. +++ ntp-4.2.8p18/ntpd/ntp_control.c 2024-07-24 01:26:46.000000000 +0200
  159. @@ -3663,18 +3663,18 @@
  160. last_salt_update = current_time;
  161. }
  162. - MD5Init(&ctx);
  163. - MD5Update(&ctx, salt, sizeof(salt));
  164. - MD5Update(&ctx, &ts_i, sizeof(ts_i));
  165. - MD5Update(&ctx, &ts_f, sizeof(ts_f));
  166. + ntp_md5_init(&ctx);
  167. + ntp_md5_update(&ctx, salt, sizeof(salt));
  168. + ntp_md5_update(&ctx, &ts_i, sizeof(ts_i));
  169. + ntp_md5_update(&ctx, &ts_f, sizeof(ts_f));
  170. if (IS_IPV4(addr)) {
  171. - MD5Update(&ctx, &SOCK_ADDR4(addr), sizeof(SOCK_ADDR4(addr)));
  172. + ntp_md5_update(&ctx, &SOCK_ADDR4(addr), sizeof(SOCK_ADDR4(addr)));
  173. } else {
  174. - MD5Update(&ctx, &SOCK_ADDR6(addr), sizeof(SOCK_ADDR6(addr)));
  175. + ntp_md5_update(&ctx, &SOCK_ADDR6(addr), sizeof(SOCK_ADDR6(addr)));
  176. }
  177. - MD5Update(&ctx, &NSRCPORT(addr), sizeof(NSRCPORT(addr)));
  178. - MD5Update(&ctx, salt, sizeof(salt));
  179. - MD5Final(d.digest, &ctx);
  180. + ntp_md5_update(&ctx, &NSRCPORT(addr), sizeof(NSRCPORT(addr)));
  181. + ntp_md5_update(&ctx, salt, sizeof(salt));
  182. + ntp_md5_final(d.digest, &ctx);
  183. return d.extract;
  184. }
  185. diff -uNr ntp-4.2.8p18.orig/ntpd/ntp_crypto.c ntp-4.2.8p18/ntpd/ntp_crypto.c
  186. --- ntp-4.2.8p18.orig/ntpd/ntp_crypto.c 2024-05-07 13:21:32.000000000 +0200
  187. +++ ntp-4.2.8p18/ntpd/ntp_crypto.c 2024-07-24 01:26:46.000000000 +0200
  188. @@ -150,7 +150,7 @@
  189. * Global cryptodata in host byte order
  190. */
  191. u_int32 crypto_flags = 0x0; /* status word */
  192. -int crypto_nid = KEY_TYPE_MD5; /* digest nid */
  193. +int crypto_nid = NID_md5; /* digest nid */
  194. char *sys_hostname = NULL;
  195. char *sys_groupname = NULL;
  196. static char *host_filename = NULL; /* host file name */