aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h7
-rw-r--r--mailutils/popmaildir.c2
-rw-r--r--networking/ntpd.c37
-rw-r--r--networking/tls.c2
4 files changed, 41 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6be934994..8c7978456 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2063,6 +2063,13 @@ unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
2063typedef struct md5_ctx_t md5sha_ctx_t; 2063typedef struct md5_ctx_t md5sha_ctx_t;
2064#define md5sha_hash md5_hash 2064#define md5sha_hash md5_hash
2065#define sha_end sha1_end 2065#define sha_end sha1_end
2066enum {
2067 MD5_OUTSIZE = 16,
2068 SHA1_OUTSIZE = 20,
2069 SHA256_OUTSIZE = 32,
2070 SHA512_OUTSIZE = 64,
2071 SHA3_OUTSIZE = 28,
2072};
2066 2073
2067extern uint32_t *global_crc32_table; 2074extern uint32_t *global_crc32_table;
2068uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 2075uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
diff --git a/mailutils/popmaildir.c b/mailutils/popmaildir.c
index 6927e3a58..c5522f1b7 100644
--- a/mailutils/popmaildir.c
+++ b/mailutils/popmaildir.c
@@ -156,7 +156,7 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv)
156 md5_ctx_t ctx; 156 md5_ctx_t ctx;
157 char hex[16 * 2 + 1]; 157 char hex[16 * 2 + 1];
158 } md5; 158 } md5;
159 uint32_t res[16 / 4]; 159 uint32_t res[MD5_OUTSIZE / 4];
160 160
161 char *s = strchr(buf, '>'); 161 char *s = strchr(buf, '>');
162 if (s) 162 if (s)
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 0f12409f9..b08de504e 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -337,6 +337,9 @@ typedef struct {
337#endif 337#endif
338 int p_fd; 338 int p_fd;
339 int datapoint_idx; 339 int datapoint_idx;
340#if ENABLE_FEATURE_NTPD_SERVER
341 uint32_t p_refid;
342#endif
340 uint32_t lastpkt_refid; 343 uint32_t lastpkt_refid;
341 uint8_t lastpkt_status; 344 uint8_t lastpkt_status;
342 uint8_t lastpkt_stratum; 345 uint8_t lastpkt_stratum;
@@ -413,7 +416,9 @@ struct globals {
413 * in stratum 2+ packets, it's IPv4 address or 4 first bytes 416 * in stratum 2+ packets, it's IPv4 address or 4 first bytes
414 * of MD5 hash of IPv6 417 * of MD5 hash of IPv6
415 */ 418 */
419#if ENABLE_FEATURE_NTPD_SERVER
416 uint32_t refid; 420 uint32_t refid;
421#endif
417 uint8_t ntp_status; 422 uint8_t ntp_status;
418 /* precision is defined as the larger of the resolution and time to 423 /* precision is defined as the larger of the resolution and time to
419 * read the clock, in log2 units. For instance, the precision of a 424 * read the clock, in log2 units. For instance, the precision of a
@@ -836,6 +841,24 @@ reset_peer_stats(peer_t *p, double offset)
836 VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); 841 VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time);
837} 842}
838 843
844#if ENABLE_FEATURE_NTPD_SERVER
845static uint32_t calculate_refid(len_and_sockaddr *lsa)
846{
847# if ENABLE_FEATURE_IPV6
848 if (lsa->u.sa.sa_family == AF_INET6) {
849 md5_ctx_t md5;
850 uint32_t res[MD5_OUTSIZE / 4];
851
852 md5_begin(&md5);
853 md5_hash(&md5, &lsa->u.sin6.sin6_addr, sizeof(lsa->u.sin6.sin6_addr));
854 md5_end(&md5, res);
855 return res[0];
856 }
857# endif
858 return lsa->u.sin.sin_addr.s_addr;
859}
860#endif
861
839static len_and_sockaddr* 862static len_and_sockaddr*
840resolve_peer_hostname(peer_t *p) 863resolve_peer_hostname(peer_t *p)
841{ 864{
@@ -847,6 +870,9 @@ resolve_peer_hostname(peer_t *p)
847 p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); 870 p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
848 VERB1 if (strcmp(p->p_hostname, p->p_dotted) != 0) 871 VERB1 if (strcmp(p->p_hostname, p->p_dotted) != 0)
849 bb_error_msg("'%s' is %s", p->p_hostname, p->p_dotted); 872 bb_error_msg("'%s' is %s", p->p_hostname, p->p_dotted);
873#if ENABLE_FEATURE_NTPD_SERVER
874 p->p_refid = calculate_refid(p->p_lsa);
875#endif
850 p->dns_errors = 0; 876 p->dns_errors = 0;
851 return lsa; 877 return lsa;
852 } 878 }
@@ -1764,7 +1790,10 @@ update_local_clock(peer_t *p)
1764 1790
1765 G.reftime = G.cur_time; 1791 G.reftime = G.cur_time;
1766 G.ntp_status = p->lastpkt_status; 1792 G.ntp_status = p->lastpkt_status;
1767 G.refid = p->lastpkt_refid; 1793#if ENABLE_FEATURE_NTPD_SERVER
1794 /* Our current refid is the IPv4 (or md5-hashed IPv6) address of the peer we took time from: */
1795 G.refid = p->p_refid;
1796#endif
1768 G.rootdelay = p->lastpkt_rootdelay + p->lastpkt_delay; 1797 G.rootdelay = p->lastpkt_rootdelay + p->lastpkt_delay;
1769 dtemp = p->filter_jitter; // SQRT(SQUARE(p->filter_jitter) + SQUARE(G.cluster_jitter)); 1798 dtemp = p->filter_jitter; // SQRT(SQUARE(p->filter_jitter) + SQUARE(G.cluster_jitter));
1770 dtemp += MAXD(p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + abs_offset, MINDISP); 1799 dtemp += MAXD(p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + abs_offset, MINDISP);
@@ -2249,11 +2278,11 @@ recv_and_process_client_pkt(void /*int fd*/)
2249 * We don't support this. 2278 * We don't support this.
2250 */ 2279 */
2251 2280
2252#if ENABLE_FEATURE_NTP_AUTH 2281# if ENABLE_FEATURE_NTP_AUTH
2253 if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) 2282 if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH)
2254#else 2283# else
2255 if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH) 2284 if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH)
2256#endif 2285# endif
2257 { 2286 {
2258 char *addr; 2287 char *addr;
2259 if (size < 0) { 2288 if (size < 0) {
diff --git a/networking/tls.c b/networking/tls.c
index 854937302..341225207 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -212,8 +212,6 @@
212 212
213enum { 213enum {
214 SHA_INSIZE = 64, 214 SHA_INSIZE = 64,
215 SHA1_OUTSIZE = 20,
216 SHA256_OUTSIZE = 32,
217 215
218 AES128_KEYSIZE = 16, 216 AES128_KEYSIZE = 16,
219 AES256_KEYSIZE = 32, 217 AES256_KEYSIZE = 32,